@speedkit/cli 4.44.0-beta.4 → 4.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/CHANGELOG.md +35 -13
  2. package/README.md +68 -42
  3. package/dist/base/sk-command.d.ts +7 -0
  4. package/dist/base/sk-command.js +19 -0
  5. package/dist/commands/deploy.d.ts +1 -0
  6. package/dist/commands/deploy.js +5 -1
  7. package/dist/commands/diff.d.ts +47 -0
  8. package/dist/commands/diff.js +67 -0
  9. package/dist/commands/generate-pop-config.js +3 -7
  10. package/dist/helpers/race.js +4 -2
  11. package/dist/helpers/spec/race.spec.js +31 -0
  12. package/dist/models/files.d.ts +0 -1
  13. package/dist/models/files.js +0 -1
  14. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  15. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
  16. package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
  17. package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
  18. package/dist/services/bundler/bundle-service-factory.js +1 -5
  19. package/dist/services/bundler/bundle-service.d.ts +1 -10
  20. package/dist/services/bundler/bundle-service.js +1 -16
  21. package/dist/services/bundler/index.d.ts +0 -1
  22. package/dist/services/bundler/index.js +0 -1
  23. package/dist/services/cli/cli-environment.d.ts +11 -0
  24. package/dist/services/cli/cli-environment.js +37 -0
  25. package/dist/services/cli/cli-service-model.d.ts +3 -1
  26. package/dist/services/cli/cli-service.d.ts +1 -1
  27. package/dist/services/cli/cli-service.js +4 -1
  28. package/dist/services/cli/spec/cli-environment.spec.js +30 -1
  29. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  30. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  31. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  32. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  33. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  34. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  35. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  36. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  37. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  38. package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
  39. package/dist/services/deploy/deploy-service-build-context.js +13 -2
  40. package/dist/services/deploy/deploy-service-factory.js +2 -9
  41. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  42. package/dist/services/deploy/deploy-service.d.ts +2 -0
  43. package/dist/services/deploy/deploy-service.js +26 -1
  44. package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
  45. package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
  46. package/dist/services/deploy/handler/install-resource-handler.js +6 -3
  47. package/dist/services/deploy/handler/module-handler.d.ts +2 -2
  48. package/dist/services/deploy/handler/module-handler.js +2 -2
  49. package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
  50. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  51. package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
  52. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
  53. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  54. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  55. package/dist/services/deploy/policy/index.d.ts +1 -0
  56. package/dist/services/deploy/policy/index.js +1 -0
  57. package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
  58. package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
  59. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  60. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  61. package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
  62. package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
  63. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  64. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
  65. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
  66. package/dist/services/diff/create-diff-engine.d.ts +14 -0
  67. package/dist/services/diff/create-diff-engine.js +42 -0
  68. package/dist/services/diff/customer-origin.d.ts +9 -0
  69. package/dist/services/diff/customer-origin.js +19 -0
  70. package/dist/services/diff/diff-engine.d.ts +30 -0
  71. package/dist/services/diff/diff-engine.js +49 -0
  72. package/dist/services/diff/diff-log.d.ts +9 -0
  73. package/dist/services/diff/diff-log.js +18 -0
  74. package/dist/services/diff/diff-model.d.ts +68 -0
  75. package/dist/services/diff/diff-model.js +1 -0
  76. package/dist/services/diff/diff-service-build-context.d.ts +99 -9
  77. package/dist/services/diff/diff-service-build-context.js +299 -1
  78. package/dist/services/diff/diff-service-factory.d.ts +24 -2
  79. package/dist/services/diff/diff-service-factory.js +165 -3
  80. package/dist/services/diff/diff-service.d.ts +93 -33
  81. package/dist/services/diff/diff-service.js +274 -140
  82. package/dist/services/diff/index.d.ts +12 -1
  83. package/dist/services/diff/index.js +12 -1
  84. package/dist/services/diff/noise-baseline.d.ts +28 -0
  85. package/dist/services/diff/noise-baseline.js +105 -0
  86. package/dist/services/diff/page-source.d.ts +42 -0
  87. package/dist/services/diff/page-source.js +93 -0
  88. package/dist/services/diff/side-failure.d.ts +28 -0
  89. package/dist/services/diff/side-failure.js +100 -0
  90. package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
  91. package/dist/services/diff/sinks/json-diff-sink.js +44 -0
  92. package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
  93. package/dist/services/diff/sinks/no-diff-sink.js +6 -0
  94. package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
  95. package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
  96. package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
  97. package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
  98. package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
  99. package/dist/services/diff/sinks/unified-patch.js +12 -0
  100. package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
  101. package/dist/services/diff/spec/customer-origin.spec.js +27 -0
  102. package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
  103. package/dist/services/diff/spec/diff-engine.spec.js +47 -0
  104. package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
  105. package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
  106. package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
  107. package/dist/services/diff/spec/diff-service.spec.js +393 -0
  108. package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
  109. package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
  110. package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
  111. package/dist/services/diff/spec/page-source.spec.js +140 -0
  112. package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
  113. package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
  114. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
  115. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
  116. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
  117. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
  118. package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
  119. package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
  120. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  121. package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
  122. package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
  123. package/dist/services/document-handler-runtime/runtime-files.js +17 -0
  124. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  125. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
  126. package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
  127. package/dist/services/integration-api/struct/customer-config.js +3 -33
  128. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  129. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
  130. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -25
  131. package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
  132. package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
  133. package/dist/services/onboarding/dashboard/index.js +13 -6
  134. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
  135. package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
  136. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  137. package/dist/services/onboarding/onboarding-model.js +0 -1
  138. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  139. package/dist/services/onboarding/onboarding-service-factory.js +24 -30
  140. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
  141. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
  142. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  143. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
  144. package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
  145. package/dist/services/origin-request/index.d.ts +3 -0
  146. package/dist/services/origin-request/index.js +3 -0
  147. package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
  148. package/dist/services/origin-request/origin-fetcher.js +93 -0
  149. package/dist/services/origin-request/origin-request-service-factory.js +19 -1
  150. package/dist/services/origin-request/origin-request-service.d.ts +6 -10
  151. package/dist/services/origin-request/origin-request-service.js +28 -70
  152. package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
  153. package/dist/services/origin-request/runtime-config-source.js +59 -0
  154. package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
  155. package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
  156. package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
  157. package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
  158. package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
  159. package/dist/services/prewarm/assets/asset-api-client.js +6 -1
  160. package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
  161. package/dist/services/prewarm/pre-warm-service.js +17 -0
  162. package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
  163. package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
  164. package/dist/services/query-builder/query-builder-factory.js +3 -3
  165. package/dist/services/setup/os/tool-registry.d.ts +1 -1
  166. package/oclif.manifest.json +151 -19
  167. package/package.json +1 -2
  168. package/dist/commands/diff-url-parameters.d.ts +0 -19
  169. package/dist/commands/diff-url-parameters.js +0 -121
  170. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  171. package/dist/services/bundler/error/packjockel-error.js +0 -3
  172. package/dist/services/bundler/packjockel-service.d.ts +0 -72
  173. package/dist/services/bundler/packjockel-service.js +0 -156
  174. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
  175. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  176. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  177. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  178. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  179. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  180. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  181. package/dist/services/onboarding/server-config/index.d.ts +0 -10
  182. package/dist/services/onboarding/server-config/index.js +0 -27
  183. package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
  184. package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
  185. /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
  186. /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
  187. /package/dist/services/{onboarding/spec/virtual-orestes-app/origin-error-cause.spec.d.ts → deploy/spec/handler/install-resource-handler.spec.d.ts} +0 -0
  188. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
  189. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
@@ -0,0 +1,185 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { DiffServiceBuildContext, withAskingFlags, } from "../diff-service-build-context.js";
4
+ const environment = { nonInteractive: true };
5
+ function create(flags) {
6
+ return DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/" }, {
7
+ configName: "production",
8
+ baseline: false,
9
+ raw: false,
10
+ params: false,
11
+ hideDiff: false,
12
+ ...flags,
13
+ }, environment);
14
+ }
15
+ describe("DiffServiceBuildContext", () => {
16
+ it("compares the page against another page in one variation", () => {
17
+ const context = create({
18
+ against: "https://shop.test/?color=blue",
19
+ variation: "Desktop",
20
+ });
21
+ expect(context.against).to.equal("https://shop.test/?color=blue");
22
+ expect(context.variation).to.equal("default");
23
+ });
24
+ it("requests the pages in desktop without --variation", () => {
25
+ expect(create({}).variation).to.equal("default");
26
+ });
27
+ it("refuses --against with the flags of the checks it replaces", () => {
28
+ expect(() => create({
29
+ against: "https://shop.test/?color=blue",
30
+ params: true,
31
+ variations: ["mobile"],
32
+ })).to.throw("does not take --params, --variations");
33
+ });
34
+ it("refuses --against with something that is not a url", () => {
35
+ expect(() => create({ against: "color=blue" })).to.throw("page url");
36
+ });
37
+ it("refuses --against the page itself", () => {
38
+ expect(() => create({ against: "https://shop.test/" })).to.throw("with itself");
39
+ });
40
+ it("refuses --variation next to --variations", () => {
41
+ expect(() => create({ variation: "mobile", variations: ["tablet"] })).to.throw("pass one of them");
42
+ });
43
+ it("compares one variation against desktop", () => {
44
+ expect(create({ variations: ["mobile"] }).variations).to.deep.equal([
45
+ "default",
46
+ "mobile",
47
+ ]);
48
+ });
49
+ it("compares two variations with each other, in their order", () => {
50
+ expect(create({ variations: ["tablet", "mobile"] }).variations).to.deep.equal(["tablet", "mobile"]);
51
+ });
52
+ it("calls the desktop variation by Speed Kit's name for it", () => {
53
+ expect(create({ variations: ["mobile", "Desktop"] }).variations).to.deep.equal(["mobile", "default"]);
54
+ });
55
+ it("selects every parameter --param names, across flags and commas, once", () => {
56
+ const context = DiffServiceBuildContext.create({
57
+ customerPath: "customers/shop",
58
+ pageUrl: "https://shop.test/?a=1&b=2&c=3",
59
+ }, { configName: "production", param: ["c", "a, b,a"] }, environment);
60
+ expect(context.parameters).to.deep.equal(["c", "a", "b"]);
61
+ });
62
+ it("checks the parameters --param names also with --variations", () => {
63
+ const context = DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/?a=1" }, {
64
+ configName: "production",
65
+ variations: ["mobile"],
66
+ param: ["a"],
67
+ }, environment);
68
+ expect(context.params).to.equal(true);
69
+ });
70
+ it("refuses a parameter the url does not carry", () => {
71
+ expect(() => DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/?a=1" }, { configName: "production", param: ["a,sort"] }, environment)).to.throw(/no parameter "sort"/);
72
+ });
73
+ it("asks which parameters to check for an empty --param", () => {
74
+ const context = DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/?a=1&b=2" }, { configName: "production", param: ["", "a"] }, { nonInteractive: false });
75
+ expect(context.chooseParameters).to.equal(true);
76
+ expect(context.params).to.equal(true);
77
+ expect(context.parameters).to.deep.equal(["a"]);
78
+ });
79
+ it("takes a url's only parameter for an empty --param, without asking", () => {
80
+ const context = DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/?a=1&a=2" }, { configName: "production", param: [""] }, environment);
81
+ expect(context.chooseParameters).to.equal(false);
82
+ expect(context.parameters).to.deep.equal(["a"]);
83
+ });
84
+ it("refuses an empty --param when the run cannot ask", () => {
85
+ expect(() => DiffServiceBuildContext.create({
86
+ customerPath: "customers/shop",
87
+ pageUrl: "https://shop.test/?a=1&b=2",
88
+ }, { configName: "production", param: [" "] }, environment)).to.throw(/cannot ask/);
89
+ });
90
+ it("refuses an empty --param for a url without parameters", () => {
91
+ expect(() => DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/" }, { configName: "production", param: [""] }, { nonInteractive: false })).to.throw(/no query parameters to choose from/);
92
+ });
93
+ it("checks every parameter without --param", () => {
94
+ expect(create({}).parameters).to.equal(undefined);
95
+ });
96
+ it("asks which variations to compare for an empty --variations", () => {
97
+ const context = DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/" }, { configName: "production", variations: [""] }, { nonInteractive: false });
98
+ expect(context.chooseVariations).to.equal(true);
99
+ expect(context.variations).to.equal(undefined);
100
+ });
101
+ it("refuses an empty --variations when the run cannot ask", () => {
102
+ expect(() => create({ variations: [""] })).to.throw(/cannot ask/);
103
+ });
104
+ it("asks which variation to request the pages in for an empty --variation", () => {
105
+ const context = DiffServiceBuildContext.create({ customerPath: "customers/shop", pageUrl: "https://shop.test/?a=1" }, { configName: "production", variation: "" }, { nonInteractive: false });
106
+ expect(context.chooseVariation).to.equal(true);
107
+ });
108
+ it("refuses an empty --variation when the run cannot ask", () => {
109
+ expect(() => create({ variation: " " })).to.throw(/cannot ask/);
110
+ });
111
+ it("compares no variations without --variations", () => {
112
+ expect(create({}).variations).to.equal(undefined);
113
+ });
114
+ it("refuses more than two variations", () => {
115
+ expect(() => create({ variations: ["desktop", "tablet", "mobile"] })).to.throw(/two variations, not 3/);
116
+ });
117
+ it("refuses a variation compared with itself", () => {
118
+ expect(() => create({ variations: ["desktop"] })).to.throw(/with itself/);
119
+ expect(() => create({ variations: ["desktop", "default"] })).to.throw(/with itself/);
120
+ });
121
+ it("prints a patch when nobody is at the terminal", () => {
122
+ expect(create({}).output).to.equal("patch");
123
+ });
124
+ it("shows no diff for the deprecated --hideDiff", () => {
125
+ expect(create({ hideDiff: true, output: "patch" }).output).to.equal("none");
126
+ });
127
+ });
128
+ describe("DiffServiceBuildContext without a customer", () => {
129
+ function createWith(args, raw) {
130
+ return DiffServiceBuildContext.create(args, {
131
+ configName: "production",
132
+ baseline: false,
133
+ raw,
134
+ params: false,
135
+ hideDiff: false,
136
+ }, environment);
137
+ }
138
+ it("takes a lone url as the page with --raw", () => {
139
+ const context = createWith({ customerPath: "https://shop.test/?a=1" }, true);
140
+ expect(context.customerPath).to.equal(undefined);
141
+ expect(context.pageUrl).to.equal("https://shop.test/?a=1");
142
+ });
143
+ it("refuses a lone url without --raw, which needs the documentHandler", () => {
144
+ expect(() => createWith({ customerPath: "https://shop.test/?a=1" }, false)).to.throw(/no documentHandler/);
145
+ });
146
+ it("refuses --browserFetch without a customer", () => {
147
+ expect(() => DiffServiceBuildContext.create({ customerPath: "https://shop.test/?a=1" }, {
148
+ configName: "production",
149
+ baseline: false,
150
+ raw: true,
151
+ params: false,
152
+ hideDiff: false,
153
+ browserFetch: true,
154
+ }, environment)).to.throw(/--browserFetch needs the customer path/);
155
+ });
156
+ it("refuses a customer path without a page", () => {
157
+ expect(() => createWith({ customerPath: "customers/shop" }, true)).to.throw(/needs the page/);
158
+ });
159
+ });
160
+ describe("withAskingFlags", () => {
161
+ it("gives a bare --param or --variations an empty value", () => {
162
+ expect(withAskingFlags(["customers/shop", "https://shop.test/?a=1", "--param"])).to.deep.equal([
163
+ "customers/shop",
164
+ "https://shop.test/?a=1",
165
+ "--param",
166
+ "",
167
+ ]);
168
+ expect(withAskingFlags(["--variations", "--param", "a"])).to.deep.equal([
169
+ "--variations",
170
+ "",
171
+ "--param",
172
+ "a",
173
+ ]);
174
+ });
175
+ it("gives a bare --variation an empty value", () => {
176
+ expect(withAskingFlags(["--variation", "--raw"])).to.deep.equal([
177
+ "--variation",
178
+ "",
179
+ "--raw",
180
+ ]);
181
+ });
182
+ it("leaves a flag with a value alone", () => {
183
+ expect(withAskingFlags(["--param", "a", "--variations=mobile"])).to.deep.equal(["--param", "a", "--variations=mobile"]);
184
+ });
185
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,393 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { DiffEngine } from "../diff-engine.js";
4
+ import { DiffService } from "../diff-service.js";
5
+ import { documentHandlerFailure, originFailure, PageSideFailure, } from "../side-failure.js";
6
+ import { DocumentHandlerTransformError } from "../../onboarding/error/document-handler-transform-error.js";
7
+ import { DocumentHandlerAbort } from "../../document-handler-runtime/document-handler-abort.js";
8
+ function notFound(url) {
9
+ return new PageSideFailure({
10
+ url,
11
+ variation: "default",
12
+ failure: originFailure(404, "Not Found"),
13
+ });
14
+ }
15
+ function aborted(url, variation = "default") {
16
+ return new PageSideFailure({
17
+ url,
18
+ variation,
19
+ failure: documentHandlerFailure(new DocumentHandlerTransformError(new DocumentHandlerAbort("old-engine PLP"))),
20
+ });
21
+ }
22
+ /** A page source that answers each url with its entry in `pages`. */
23
+ function pageSource(pages) {
24
+ const fetched = [];
25
+ const source = {
26
+ fetched,
27
+ async fetch(url, variation, label, options) {
28
+ fetched.push(`${variation} ${url}${options?.baseline ? " +baseline" : ""}`);
29
+ const content = pages[`${variation} ${url}`] ?? pages[url];
30
+ if (content === undefined)
31
+ throw new Error(`unexpected fetch ${url}`);
32
+ if (content instanceof PageSideFailure)
33
+ throw content;
34
+ return { label, content };
35
+ },
36
+ };
37
+ return source;
38
+ }
39
+ function recordingLog() {
40
+ const lines = [];
41
+ const record = (message) => lines.push(message);
42
+ return {
43
+ lines,
44
+ write: record,
45
+ writeError: record,
46
+ writeSuccess: record,
47
+ writeWarning: record,
48
+ comment: record,
49
+ spacer: () => undefined,
50
+ startAction: () => undefined,
51
+ successAction: () => undefined,
52
+ failAction: () => undefined,
53
+ };
54
+ }
55
+ function service(pageUrl, pages, options = {}) {
56
+ const shown = [];
57
+ const failed = [];
58
+ const sink = {
59
+ async show(result) {
60
+ shown.push(result);
61
+ return undefined;
62
+ },
63
+ fail(comparison) {
64
+ failed.push(comparison);
65
+ },
66
+ };
67
+ const log = recordingLog();
68
+ const source = pageSource(pages);
69
+ const diffOptions = {
70
+ pageUrl,
71
+ variation: "default",
72
+ variations: undefined,
73
+ params: false,
74
+ baseline: false,
75
+ ...options,
76
+ };
77
+ return {
78
+ shown,
79
+ failed,
80
+ log,
81
+ source,
82
+ diff: new DiffService({
83
+ options: diffOptions,
84
+ log,
85
+ engine: new DiffEngine({ sink }),
86
+ pages: source,
87
+ }),
88
+ };
89
+ }
90
+ describe("DiffService parameters", () => {
91
+ it("refuses a url without parameters when there is nothing else to compare", async () => {
92
+ const { diff, shown } = service("https://shop.test/", {});
93
+ const error = await diff.run().catch((error_) => error_);
94
+ expect(error.message).to.contain("no query parameters");
95
+ expect(shown).to.have.length(0);
96
+ });
97
+ it("only warns about a url without parameters next to a variation diff", async () => {
98
+ const { diff, shown, log } = service("https://shop.test/", { "https://shop.test/": "<p>same</p>" }, { variations: ["default", "mobile"], params: true });
99
+ expect(await diff.run()).to.equal("equal");
100
+ expect(shown).to.have.length(1);
101
+ expect(log.lines.join(" ")).to.contain("no query parameters");
102
+ });
103
+ it("stops after the first check when removing every parameter changes nothing", async () => {
104
+ const { diff, shown } = service("https://shop.test/?a=1&b=2", {
105
+ "https://shop.test/?a=1&b=2": "<p>same</p>",
106
+ "https://shop.test/": "<p>same</p>",
107
+ });
108
+ expect(await diff.run()).to.equal("equal");
109
+ expect(shown).to.have.length(1);
110
+ });
111
+ it("checks each parameter on its own once removing all of them differs", async () => {
112
+ const { diff, shown, log } = service("https://shop.test/?a=1&b=2", {
113
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
114
+ "https://shop.test/": "<p>none</p>",
115
+ "https://shop.test/?b=2": "<p>none</p>",
116
+ "https://shop.test/?a=1": "<p>a b</p>",
117
+ });
118
+ expect(await diff.run()).to.equal("differs");
119
+ expect(shown.map((result) => result.right.label)).to.deep.equal([
120
+ "default-without-any-params.html",
121
+ "default-without-a-param.html",
122
+ "default-without-b-param.html",
123
+ ]);
124
+ expect(log.lines).to.include("⚠️ Found diff, the same one removing every parameter makes");
125
+ expect(log.lines.at(-1)).to.equal("✅ No diff found: this parameter does not make the difference");
126
+ expect(shown.map((result) => result.right.details)).to.deep.equal([
127
+ undefined,
128
+ { sameAsWithoutAnyParam: true },
129
+ { sameAsWithoutAnyParam: false },
130
+ ]);
131
+ });
132
+ it("says when a parameter's difference is not the one removing all of them makes", async () => {
133
+ const { diff, log } = service("https://shop.test/?a=1&b=2", {
134
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
135
+ "https://shop.test/": "<p>none</p>",
136
+ "https://shop.test/?b=2": "<p>b</p>",
137
+ "https://shop.test/?a=1": "<p>a b</p>",
138
+ });
139
+ expect(await diff.run()).to.equal("differs");
140
+ expect(log.lines).to.include("⚠️ Found diff, not the one removing every parameter makes");
141
+ });
142
+ it("says when no parameter makes the difference on its own", async () => {
143
+ const { diff, log } = service("https://shop.test/?a=1&b=2", {
144
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
145
+ "https://shop.test/": "<p>none</p>",
146
+ "https://shop.test/?b=2": "<p>a b</p>",
147
+ "https://shop.test/?a=1": "<p>a b</p>",
148
+ });
149
+ expect(await diff.run()).to.equal("differs");
150
+ expect(log.lines.at(-1)).to.equal("⚠️ No parameter makes the difference on its own: only removing them together does");
151
+ });
152
+ it("does not check a single parameter twice", async () => {
153
+ const { diff, shown } = service("https://shop.test/?a=1", {
154
+ "https://shop.test/?a=1": "<p>a</p>",
155
+ "https://shop.test/": "<p>none</p>",
156
+ });
157
+ expect(await diff.run()).to.equal("differs");
158
+ expect(shown).to.have.length(1);
159
+ });
160
+ it("checks only the selected parameter, without removing all of them first", async () => {
161
+ const { diff, shown, source } = service("https://shop.test/?a=1&b=2", {
162
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
163
+ "https://shop.test/?a=1": "<p>a</p>",
164
+ }, { parameters: ["b"] });
165
+ expect(await diff.run()).to.equal("differs");
166
+ expect(shown.map((result) => result.right.label)).to.deep.equal([
167
+ "default-without-b-param.html",
168
+ ]);
169
+ expect(source.fetched).to.deep.equal([
170
+ "default https://shop.test/?a=1&b=2",
171
+ "default https://shop.test/?a=1",
172
+ ]);
173
+ });
174
+ it("removes the selected parameters together, in one check", async () => {
175
+ const { diff, shown, source } = service("https://shop.test/?a=1&b=2&c=3", {
176
+ "https://shop.test/?a=1&b=2&c=3": "<p>a b c</p>",
177
+ "https://shop.test/?b=2": "<p>b</p>",
178
+ }, { parameters: ["a", "c"] });
179
+ expect(await diff.run()).to.equal("differs");
180
+ expect(shown.map((result) => result.right.label)).to.deep.equal([
181
+ "default-without-a+c-params.html",
182
+ ]);
183
+ expect(source.fetched).to.deep.equal([
184
+ "default https://shop.test/?a=1&b=2&c=3",
185
+ "default https://shop.test/?b=2",
186
+ ]);
187
+ });
188
+ it("lets a collecting sink write once the comparisons are done, even after an error", async () => {
189
+ let finished = 0;
190
+ const options = {
191
+ pageUrl: "https://shop.test/",
192
+ variations: undefined,
193
+ };
194
+ const diff = new DiffService({
195
+ options: options,
196
+ log: recordingLog(),
197
+ engine: new DiffEngine({
198
+ sink: {
199
+ show: async () => undefined,
200
+ finish: () => {
201
+ finished++;
202
+ },
203
+ },
204
+ }),
205
+ pages: pageSource({}),
206
+ });
207
+ await diff.run().catch(() => undefined);
208
+ expect(finished).to.equal(1);
209
+ });
210
+ });
211
+ describe("DiffService variations", () => {
212
+ it("compares the two variations with each other", async () => {
213
+ const { diff, shown, source } = service("https://shop.test/", {
214
+ "tablet https://shop.test/": "<p>tablet</p>",
215
+ "mobile https://shop.test/": "<p>mobile</p>",
216
+ }, { variations: ["tablet", "mobile"] });
217
+ expect(await diff.run()).to.equal("differs");
218
+ expect(shown).to.have.length(1);
219
+ expect(shown[0].left.label).to.equal("tablet.html");
220
+ expect(shown[0].right.label).to.equal("mobile.html");
221
+ expect(source.fetched).to.deep.equal([
222
+ "tablet https://shop.test/",
223
+ "mobile https://shop.test/",
224
+ ]);
225
+ });
226
+ it("checks the parameters for each of the two variations with --params", async () => {
227
+ const { diff, source } = service("https://shop.test/?a=1", {
228
+ "https://shop.test/?a=1": "<p>same</p>",
229
+ "https://shop.test/": "<p>same</p>",
230
+ }, { variations: ["default", "mobile"], params: true });
231
+ expect(await diff.run()).to.equal("equal");
232
+ // Each side is fetched once, though the original of each variation
233
+ // takes part in two comparisons.
234
+ expect(source.fetched).to.deep.equal([
235
+ "default https://shop.test/?a=1",
236
+ "mobile https://shop.test/?a=1",
237
+ "default https://shop.test/",
238
+ "mobile https://shop.test/",
239
+ ]);
240
+ });
241
+ it("leaves the parameters alone without --params", async () => {
242
+ const { diff, source } = service("https://shop.test/?a=1", { "https://shop.test/?a=1": "<p>same</p>" }, { variations: ["default", "mobile"] });
243
+ await diff.run();
244
+ expect(source.fetched).to.have.length(2);
245
+ });
246
+ });
247
+ describe("DiffService baseline", () => {
248
+ it("asks for a baseline of every side with --baseline", async () => {
249
+ const { diff, source } = service("https://shop.test/?a=1", {
250
+ "https://shop.test/?a=1": "<p>same</p>",
251
+ "https://shop.test/": "<p>same</p>",
252
+ }, { baseline: true });
253
+ await diff.run();
254
+ expect(source.fetched).to.deep.equal([
255
+ "default https://shop.test/?a=1 +baseline",
256
+ "default https://shop.test/ +baseline",
257
+ ]);
258
+ });
259
+ });
260
+ describe("DiffService browser fetch", () => {
261
+ it("closes the browser when the run ends, also after an error", async () => {
262
+ let closed = 0;
263
+ const diff = new DiffService({
264
+ options: { pageUrl: "https://shop.test/" },
265
+ log: recordingLog(),
266
+ engine: new DiffEngine({ sink: { show: async () => undefined } }),
267
+ pages: pageSource({}),
268
+ browserFetch: {
269
+ fetcher: undefined,
270
+ close: async () => {
271
+ closed++;
272
+ },
273
+ },
274
+ });
275
+ await diff.run().catch(() => undefined);
276
+ expect(closed).to.equal(1);
277
+ });
278
+ });
279
+ describe("DiffService failed sides", () => {
280
+ it("goes on with the other parameters when one reduced url is not found", async () => {
281
+ const { diff, shown, failed, log } = service("https://shop.test/?a=1&b=2", {
282
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
283
+ "https://shop.test/": "<p>none</p>",
284
+ "https://shop.test/?b=2": notFound("https://shop.test/?b=2"),
285
+ "https://shop.test/?a=1": "<p>a</p>",
286
+ });
287
+ expect(await diff.run()).to.equal("failed");
288
+ expect(shown).to.have.length(2);
289
+ expect(failed).to.have.length(1);
290
+ expect(failed[0].outcome).to.equal("failed");
291
+ expect(failed[0].right).to.deep.include({
292
+ label: "default-without-a-param.html",
293
+ failure: {
294
+ kind: "origin",
295
+ code: "105",
296
+ cause: "OriginStatusNotFound",
297
+ status: 404,
298
+ reason: "Not Found",
299
+ },
300
+ });
301
+ expect(log.lines.join("\n"))
302
+ .to.contain("does not exist")
303
+ .and.not.contain("bot protection");
304
+ });
305
+ it("stops the parameter check when the page itself fails", async () => {
306
+ const { diff, failed, source } = service("https://shop.test/?a=1&b=2", {
307
+ "https://shop.test/?a=1&b=2": notFound("https://shop.test/?a=1&b=2"),
308
+ "https://shop.test/": "<p>none</p>",
309
+ });
310
+ expect(await diff.run()).to.equal("failed");
311
+ expect(failed).to.have.length(1);
312
+ expect(source.fetched).to.have.length(2);
313
+ });
314
+ it("ends as not cacheable when the documentHandler aborts a side", async () => {
315
+ const { diff, shown, failed, log } = service("https://shop.test/?a=1", {
316
+ "https://shop.test/?a=1": aborted("https://shop.test/?a=1"),
317
+ "https://shop.test/": "<p>none</p>",
318
+ });
319
+ expect(await diff.run()).to.equal("uncacheable");
320
+ expect(shown).to.have.length(0);
321
+ expect(failed[0].outcome).to.equal("uncacheable");
322
+ expect(failed[0].left).to.deep.include({
323
+ failure: {
324
+ kind: "documentHandlerAbort",
325
+ code: "303",
326
+ cause: "ServerDocumentHandlerAbort",
327
+ reason: "old-engine PLP",
328
+ },
329
+ });
330
+ expect(log.lines.join("\n")).to.contain("ServerDocumentHandlerAbort (303): old-engine PLP");
331
+ });
332
+ it("ranks a diff above a page that is not cacheable", async () => {
333
+ const { diff, failed } = service("https://shop.test/?a=1&b=2", {
334
+ "https://shop.test/?a=1&b=2": "<p>a b</p>",
335
+ "https://shop.test/": "<p>none</p>",
336
+ "https://shop.test/?b=2": aborted("https://shop.test/?b=2"),
337
+ "https://shop.test/?a=1": "<p>a</p>",
338
+ });
339
+ expect(await diff.run()).to.equal("differs");
340
+ expect(failed.map((comparison) => comparison.outcome)).to.deep.equal([
341
+ "uncacheable",
342
+ ]);
343
+ });
344
+ it("writes a hint once, however many comparisons it fails", async () => {
345
+ const { diff, log } = service("https://shop.test/?a=1", {
346
+ "default https://shop.test/?a=1": "<p>a</p>",
347
+ "mobile https://shop.test/?a=1": aborted("https://shop.test/?a=1", "mobile"),
348
+ "default https://shop.test/": "<p>a</p>",
349
+ "mobile https://shop.test/": "<p>a</p>",
350
+ }, { variations: ["default", "mobile"], params: true });
351
+ expect(await diff.run()).to.equal("uncacheable");
352
+ const hints = log.lines.filter((line) => line.startsWith("Speed Kit never caches"));
353
+ expect(hints).to.have.length(1);
354
+ });
355
+ });
356
+ describe("DiffService against", () => {
357
+ it("compares the page with the other page, in the variation named", async () => {
358
+ const { diff, shown, source, log } = service("https://shop.test/?color=red", {
359
+ "https://shop.test/?color=red": "<p>red</p>",
360
+ "https://shop.test/?color=blue": "<p>blue</p>",
361
+ }, { against: "https://shop.test/?color=blue", variation: "mobile" });
362
+ expect(await diff.run()).to.equal("differs");
363
+ expect(shown.map((result) => result.right.label)).to.deep.equal([
364
+ "mobile-against.html",
365
+ ]);
366
+ expect(source.fetched).to.deep.equal([
367
+ "mobile https://shop.test/?color=red",
368
+ "mobile https://shop.test/?color=blue",
369
+ ]);
370
+ expect(log.lines).to.include("- against: https://shop.test/?color=blue");
371
+ });
372
+ it("does not check the parameters next to it", async () => {
373
+ const { diff, source } = service("https://shop.test/?color=red", {
374
+ "https://shop.test/?color=red": "<p>grid</p>",
375
+ "https://shop.test/?color=blue": "<p>grid</p>",
376
+ }, { against: "https://shop.test/?color=blue" });
377
+ expect(await diff.run()).to.equal("equal");
378
+ expect(source.fetched).to.have.length(2);
379
+ });
380
+ });
381
+ describe("DiffService variation", () => {
382
+ it("checks the parameters in the one variation named", async () => {
383
+ const { diff, source } = service("https://shop.test/?a=1", {
384
+ "https://shop.test/?a=1": "<p>same</p>",
385
+ "https://shop.test/": "<p>same</p>",
386
+ }, { variation: "tablet" });
387
+ await diff.run();
388
+ expect(source.fetched).to.deep.equal([
389
+ "tablet https://shop.test/?a=1",
390
+ "tablet https://shop.test/",
391
+ ]);
392
+ });
393
+ });
@@ -0,0 +1 @@
1
+ export {};