@speedkit/cli 4.30.0 → 4.32.0
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.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/services/deploy/checks/activation/customer-approval-check.js +5 -2
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -7
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +7 -6
- package/dist/services/integration-api/file-list.d.ts +2 -1
- package/dist/services/integration-api/file-list.js +7 -1
- package/dist/services/integration-api/handler/install-resource-handler.js +10 -2
- package/dist/services/integration-api/integration-api-model.d.ts +8 -0
- package/dist/services/integration-api/integration-api-model.js +3 -0
- package/dist/services/integration-api/spec/config-plugin.spec.js +188 -0
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.d.ts +1 -0
- package/dist/{helpers/evaluate-speed-kit-config.spec.js → services/integration-api/spec/speed-kit-config-file.spec.js} +43 -12
- package/dist/services/integration-api/spec/speed-kit-config.spec.d.ts +1 -0
- package/dist/services/integration-api/spec/speed-kit-config.spec.js +108 -0
- package/dist/services/integration-api/struct/config-plugin.d.ts +41 -0
- package/dist/services/integration-api/struct/config-plugin.js +241 -0
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +46 -0
- package/dist/services/integration-api/struct/speed-kit-config-file.js +223 -0
- package/dist/services/integration-api/struct/speed-kit-config.d.ts +84 -0
- package/dist/services/integration-api/struct/speed-kit-config.js +114 -0
- package/dist/services/integration-api/virtual/static-recipe.d.ts +1 -1
- package/dist/services/onboarding/empty-service-worker.d.ts +8 -0
- package/dist/services/onboarding/empty-service-worker.js +17 -0
- package/dist/services/onboarding/empty-service-worker.spec.d.ts +1 -0
- package/dist/services/onboarding/empty-service-worker.spec.js +22 -0
- package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +3 -2
- package/dist/services/onboarding/onboarding-service.js +2 -1
- package/dist/services/query-builder/queries/spec/golden-configs.d.ts +2 -0
- package/dist/services/query-builder/queries/spec/golden-configs.js +37 -0
- package/dist/services/query-builder/queries/spec/golden.spec.js +5 -4
- package/dist/services/query-builder/queries/spec/queries.spec.js +2 -1
- package/dist/services/query-builder/queries/spec/reported-bugs.spec.js +2 -1
- package/dist/services/query-builder/query-builder-factory.js +4 -8
- package/dist/services/query-builder/query-builder-service.js +4 -0
- package/dist/services/query-builder/query-builder-service.spec.js +2 -1
- package/dist/services/query-builder/rules/rule-model.d.ts +6 -2
- package/dist/services/query-builder/rules/rule-model.js +0 -2
- package/dist/services/query-builder/rules/rule-parser.d.ts +7 -8
- package/dist/services/query-builder/rules/rule-parser.js +41 -47
- package/dist/services/query-builder/rules/spec/rule-parser.spec.js +30 -32
- package/dist/services/query-builder/rules/spec/rule-reducer.spec.js +2 -1
- package/dist/services/query-builder/rules/spec/rule-relevance.spec.js +7 -3
- package/dist/services/query-builder/rules/spec/rule-to-sql.spec.js +3 -2
- package/dist/services/query-builder/rules/spec/strip-parameters.spec.js +5 -2
- package/oclif.manifest.json +112 -112
- package/package.json +1 -1
- package/dist/helpers/evaluate-speed-kit-config.d.ts +0 -16
- package/dist/helpers/evaluate-speed-kit-config.js +0 -157
- /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.d.ts +0 -0
- /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.js +0 -0
- /package/dist/{helpers/evaluate-speed-kit-config.spec.d.ts → services/integration-api/spec/config-plugin.spec.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [4.32.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.31.0...v4.32.0) (2026-09-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **onboarding:** recognize r=empty as the empty service worker ([d37d0c7](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/d37d0c74ae536aa8697101ddc053073164d40547))
|
|
7
|
+
|
|
8
|
+
# [4.31.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.30.0...v4.31.0) (2026-09-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **config-plugins:** apply configPlugins to config before evaluation ([78984ff](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/78984ff145c6cacc3280652e5975f3ef1676b550))
|
|
14
|
+
|
|
1
15
|
# [4.30.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.29.0...v4.30.0) (2026-09-18)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
2
2
|
import { safe } from "../../../../helpers/safe.js";
|
|
3
3
|
/** The install resource key config_SpeedKit.js is stored under. */
|
|
4
4
|
const SPEED_KIT_CONFIG_KEY = "config";
|
|
@@ -40,9 +40,12 @@ export class CustomerApprovalCheck {
|
|
|
40
40
|
if (!speedKitConfig) {
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
43
|
+
// The config to be activated, read the same way the local file is — one
|
|
44
|
+
// file, evaluated once per origin.
|
|
45
|
+
const configFile = await VirtualSpeedKitConfigFile.createRemote(speedKitConfig);
|
|
43
46
|
const splits = [];
|
|
44
47
|
for (const origin of this.customer.origins) {
|
|
45
|
-
const result = await safe(
|
|
48
|
+
const result = await safe(configFile.evaluate(this.customer.app, origin));
|
|
46
49
|
if (result.success === false) {
|
|
47
50
|
// An unreadable config is not proof that the split is 0, so keep the
|
|
48
51
|
// approval question rather than skipping it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
1
2
|
import { INTEGRATION_FILES } from "../../../../models/files.js";
|
|
2
3
|
import { safe } from "../../../../helpers/safe.js";
|
|
3
|
-
import { evaluateLocalAndRemoteSpeedKit } from "../../../../helpers/evaluate-speed-kit-config.js";
|
|
4
4
|
export class DeviceDetectionChangedCheck {
|
|
5
5
|
cli;
|
|
6
6
|
fileList;
|
|
@@ -22,9 +22,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
22
22
|
!this.isProduction ||
|
|
23
23
|
// do not check if speedKitConfigFile is not to be deployed
|
|
24
24
|
!this.fileList.hasFile(INTEGRATION_FILES.CONFIG.SPEED_KIT) ||
|
|
25
|
-
this.fileList
|
|
26
|
-
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
27
|
-
.shouldSkipFile()) {
|
|
25
|
+
this.fileList.getSpeedKitConfig().shouldSkipFile()) {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
28
|
const activeInstallResource = await this.getActiveInstallResource();
|
|
@@ -33,7 +31,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
33
|
this.cli.startAction("PRE:CHECK:DEVICE_DETECTION", "Checking for customDeviceDetection");
|
|
36
|
-
const speedKitConfigFile = this.fileList.
|
|
34
|
+
const speedKitConfigFile = this.fileList.getSpeedKitConfig();
|
|
37
35
|
const activeSpeedKitConfig = activeInstallResource[speedKitConfigFile.remoteKey];
|
|
38
36
|
const changesResponse = await safe(this.checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig));
|
|
39
37
|
if (changesResponse.success === false) {
|
|
@@ -42,7 +40,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
42
40
|
return;
|
|
43
41
|
}
|
|
44
42
|
const changes = changesResponse.data.map((value) => {
|
|
45
|
-
return
|
|
43
|
+
return `${INTEGRATION_FILES.CONFIG.SPEED_KIT}.${value}`;
|
|
46
44
|
});
|
|
47
45
|
this.cli.successAction("PRE:CHECK:DEVICE_DETECTION");
|
|
48
46
|
if (changes.length === 0) {
|
|
@@ -55,8 +53,12 @@ export class DeviceDetectionChangedCheck {
|
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
async checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig) {
|
|
56
|
+
const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig);
|
|
57
|
+
const app = this.customerConfig.app;
|
|
58
|
+
const origin = this.customerConfig.origins[0];
|
|
58
59
|
const changes = [];
|
|
59
|
-
const
|
|
60
|
+
const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
|
|
61
|
+
const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
|
|
60
62
|
if ((localSpeedKit.detectDevice && !remoteSpeedKit.detectDevice) ||
|
|
61
63
|
(!localSpeedKit.detectDevice && remoteSpeedKit.detectDevice)) {
|
|
62
64
|
changes.push("detectDevice");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
1
2
|
import { INTEGRATION_FILES } from "../../../../models/files.js";
|
|
2
3
|
import { safe } from "../../../../helpers/safe.js";
|
|
3
|
-
import { evaluateLocalAndRemoteSpeedKit } from "../../../../helpers/evaluate-speed-kit-config.js";
|
|
4
4
|
import ApplicationError from "../../../error-handling/error/application-error.js";
|
|
5
5
|
export class SplitChangeCheck {
|
|
6
6
|
cli;
|
|
@@ -23,9 +23,7 @@ export class SplitChangeCheck {
|
|
|
23
23
|
!this.isProduction ||
|
|
24
24
|
// do not check if speedKitConfigFile is not to be deployed
|
|
25
25
|
!this.fileList.hasFile(INTEGRATION_FILES.CONFIG.SPEED_KIT) ||
|
|
26
|
-
this.fileList
|
|
27
|
-
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
28
|
-
.shouldSkipFile()) {
|
|
26
|
+
this.fileList.getSpeedKitConfig().shouldSkipFile()) {
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
const activeInstallResource = await this.getActiveInstallResource();
|
|
@@ -34,7 +32,7 @@ export class SplitChangeCheck {
|
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
this.cli.startAction("PRE:CHECK:SPLIT_CHANGE", "Checking Split Test ID");
|
|
37
|
-
const speedKitConfigFile = this.fileList.
|
|
35
|
+
const speedKitConfigFile = this.fileList.getSpeedKitConfig();
|
|
38
36
|
const activeSpeedKitConfig = activeInstallResource[speedKitConfigFile.remoteKey];
|
|
39
37
|
if (!activeSpeedKitConfig) {
|
|
40
38
|
throw new ApplicationError("RemoteSpeedKitConfig is empty");
|
|
@@ -58,9 +56,12 @@ export class SplitChangeCheck {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
async checkSplitsForEachOrigin(speedKitConfigFile, activeSpeedKitConfig) {
|
|
59
|
+
const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig);
|
|
60
|
+
const app = this.customerConfig.app;
|
|
61
61
|
const changes = [];
|
|
62
62
|
for (const origin of this.customerConfig.origins) {
|
|
63
|
-
const
|
|
63
|
+
const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
|
|
64
|
+
const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
|
|
64
65
|
// check for split change
|
|
65
66
|
if (localSpeedKit.split !== remoteSpeedKit.split) {
|
|
66
67
|
changes.push({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomerConfigInterface, FILE_TYPE, FileInterface, FileListInterface, InstallResourceInterface, ModuleInterface, ServerConfigInterface, RoFile, VirtualFile } from "./integration-api-model.js";
|
|
1
|
+
import { CustomerConfigInterface, FILE_TYPE, FileInterface, FileListInterface, InstallResourceInterface, ModuleInterface, ServerConfigInterface, RoFile, VirtualFile, SpeedKitConfigInterface } from "./integration-api-model.js";
|
|
2
2
|
export default class FileList implements FileListInterface {
|
|
3
3
|
files: FileInterface[];
|
|
4
4
|
addFile(file: FileInterface): void;
|
|
@@ -7,6 +7,7 @@ export default class FileList implements FileListInterface {
|
|
|
7
7
|
getModules(): ModuleInterface[];
|
|
8
8
|
getServerConfig(): ServerConfigInterface;
|
|
9
9
|
getCustomerConfig(): CustomerConfigInterface;
|
|
10
|
+
getSpeedKitConfig(): SpeedKitConfigInterface;
|
|
10
11
|
getTypes(): FILE_TYPE[];
|
|
11
12
|
getByType<T>(type: FILE_TYPE): FileInterface[] | T[];
|
|
12
13
|
getByName<T>(name: string): T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomerConfigFile, InstallResourceFile, ServerConfigFile, ModuleFile, } from "./integration-api-model.js";
|
|
1
|
+
import { CustomerConfigFile, InstallResourceFile, ServerConfigFile, ModuleFile, SpeedKitConfigFile, } from "./integration-api-model.js";
|
|
2
2
|
export default class FileList {
|
|
3
3
|
files = [];
|
|
4
4
|
addFile(file) {
|
|
@@ -35,6 +35,12 @@ export default class FileList {
|
|
|
35
35
|
});
|
|
36
36
|
return configFiles.shift();
|
|
37
37
|
}
|
|
38
|
+
getSpeedKitConfig() {
|
|
39
|
+
const configFiles = this.files.filter((file) => {
|
|
40
|
+
return file instanceof SpeedKitConfigFile;
|
|
41
|
+
});
|
|
42
|
+
return configFiles.shift();
|
|
43
|
+
}
|
|
38
44
|
getTypes() {
|
|
39
45
|
const types = this.files
|
|
40
46
|
.map((file) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import FileHandler from "./file-handler.js";
|
|
2
|
-
import { InstallResourceFile, } from "../integration-api-model.js";
|
|
2
|
+
import { InstallResourceFile, SpeedKitConfigFile, } from "../integration-api-model.js";
|
|
3
3
|
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
4
|
+
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
4
5
|
export default class InstallResourceHandler extends FileHandler {
|
|
5
6
|
allowedFiles = [
|
|
6
7
|
"config_SpeedKit",
|
|
@@ -29,7 +30,14 @@ export default class InstallResourceHandler extends FileHandler {
|
|
|
29
30
|
}
|
|
30
31
|
async handle(filePath) {
|
|
31
32
|
const fileName = this.getFileName(filePath);
|
|
32
|
-
|
|
33
|
+
const content = await this.getFileContent(fileName, filePath);
|
|
34
|
+
const remoteKey = this.getRemoteKey(fileName);
|
|
35
|
+
// config_SpeedKit is more than a file to upload: it is the config itself,
|
|
36
|
+
// and everything downstream reads it through its own struct.
|
|
37
|
+
if (fileName === INTEGRATION_FILES.CONFIG.SPEED_KIT) {
|
|
38
|
+
return new SpeedKitConfigFile(fileName, filePath, content, remoteKey);
|
|
39
|
+
}
|
|
40
|
+
return new InstallResourceFile(fileName, filePath, content, remoteKey);
|
|
33
41
|
}
|
|
34
42
|
getRemoteKey(fileName) {
|
|
35
43
|
if (!this.remoteKeyMapping[fileName]) {
|
|
@@ -3,12 +3,16 @@ export * from "./struct/file.js";
|
|
|
3
3
|
export * from "./struct/customer-config-file.js";
|
|
4
4
|
export * from "./struct/module-file.js";
|
|
5
5
|
export * from "./struct/install-resource-file.js";
|
|
6
|
+
export * from "./struct/speed-kit-config.js";
|
|
7
|
+
export * from "./struct/speed-kit-config-file.js";
|
|
6
8
|
export * from "./struct/server-config-file.js";
|
|
7
9
|
export * from "./struct/ro-file.js";
|
|
8
10
|
export * from "./struct/virtual-file.js";
|
|
9
11
|
export * from "./virtual/virtual-file-handler.js";
|
|
10
12
|
export * from "./virtual/external-recipe.js";
|
|
13
|
+
export * from "./virtual/static-recipe.js";
|
|
11
14
|
export * from "./external/external-file-reader.js";
|
|
15
|
+
import type { SpeedKitConfig } from "./struct/speed-kit-config.js";
|
|
12
16
|
import { CustomerConfig } from "./struct/customer-config.js";
|
|
13
17
|
import { RoFile } from "./struct/ro-file.js";
|
|
14
18
|
import { VirtualFile } from "./struct/virtual-file.js";
|
|
@@ -29,6 +33,7 @@ export interface FileListInterface {
|
|
|
29
33
|
getModules(): ModuleInterface[];
|
|
30
34
|
getServerConfig(): ServerConfigInterface;
|
|
31
35
|
getCustomerConfig(): CustomerConfigInterface;
|
|
36
|
+
getSpeedKitConfig(): SpeedKitConfigInterface;
|
|
32
37
|
getByType<T>(type: FILE_TYPE): FileInterface[] | T[];
|
|
33
38
|
getTypes(): FILE_TYPE[];
|
|
34
39
|
filter(callback: (file: FileInterface) => boolean): void;
|
|
@@ -83,6 +88,9 @@ export interface ServerConfigInterface extends ConfigFileInterface, FileInterfac
|
|
|
83
88
|
export interface InstallResourceInterface extends ConfigFileInterface, FileInterface {
|
|
84
89
|
readonly remoteKey: string;
|
|
85
90
|
}
|
|
91
|
+
export interface SpeedKitConfigInterface extends InstallResourceInterface {
|
|
92
|
+
evaluate(app: string, origin: string): Promise<SpeedKitConfig>;
|
|
93
|
+
}
|
|
86
94
|
export interface CustomerConfigInterface extends ConfigFileInterface {
|
|
87
95
|
config: CustomerConfig;
|
|
88
96
|
updateOrigins(origins: string[]): void;
|
|
@@ -3,11 +3,14 @@ export * from "./struct/file.js";
|
|
|
3
3
|
export * from "./struct/customer-config-file.js";
|
|
4
4
|
export * from "./struct/module-file.js";
|
|
5
5
|
export * from "./struct/install-resource-file.js";
|
|
6
|
+
export * from "./struct/speed-kit-config.js";
|
|
7
|
+
export * from "./struct/speed-kit-config-file.js";
|
|
6
8
|
export * from "./struct/server-config-file.js";
|
|
7
9
|
export * from "./struct/ro-file.js";
|
|
8
10
|
export * from "./struct/virtual-file.js";
|
|
9
11
|
export * from "./virtual/virtual-file-handler.js";
|
|
10
12
|
export * from "./virtual/external-recipe.js";
|
|
13
|
+
export * from "./virtual/static-recipe.js";
|
|
11
14
|
export * from "./external/external-file-reader.js";
|
|
12
15
|
export var FILE_TYPE;
|
|
13
16
|
(function (FILE_TYPE) {
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as vm from "node:vm";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { describe, it } from "mocha";
|
|
4
|
+
import { SpeedKitConfig } from "../struct/speed-kit-config.js";
|
|
5
|
+
/**
|
|
6
|
+
* The plugin shapes here mirror the published bundles at
|
|
7
|
+
* `https://www.baqend.com/speed-kit-config/latest/`: a `name`, an `options`,
|
|
8
|
+
* and every hook as an own instance field — which is what
|
|
9
|
+
* `ConfigController` reads with `Object.keys`.
|
|
10
|
+
*/
|
|
11
|
+
function blacklistPlugin(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
name: "BlacklistPlugin",
|
|
14
|
+
options,
|
|
15
|
+
addBlacklist: () => [
|
|
16
|
+
{ pathname: [/cart/i], tags: ["cart"] },
|
|
17
|
+
{ pathname: [/checkout/i], tags: ["checkout"] },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function config(evaluated, ...plugins) {
|
|
22
|
+
return SpeedKitConfig.createFrom(evaluated, plugins);
|
|
23
|
+
}
|
|
24
|
+
describe("config plugins", () => {
|
|
25
|
+
it("should add the rules a plugin contributes to the rule set", () => {
|
|
26
|
+
const parsed = config({ blacklist: [{ pathname: [/\/wishlist/i] }] }, blacklistPlugin());
|
|
27
|
+
expect(parsed.blacklist).to.have.lengthOf(3);
|
|
28
|
+
expect(parsed.plugins).to.deep.equal(["BlacklistPlugin"]);
|
|
29
|
+
});
|
|
30
|
+
it("should start a rule set a plugin is the only contributor to", () => {
|
|
31
|
+
const parsed = config({}, blacklistPlugin());
|
|
32
|
+
expect(parsed.blacklist).to.have.lengthOf(2);
|
|
33
|
+
});
|
|
34
|
+
it("should leave the config the file wrote untouched", () => {
|
|
35
|
+
const evaluated = { blacklist: [{ pathname: [/\/wishlist/i] }] };
|
|
36
|
+
const parsed = config(evaluated, blacklistPlugin());
|
|
37
|
+
expect(parsed.raw).to.equal(evaluated);
|
|
38
|
+
expect(evaluated.blacklist).to.have.lengthOf(1);
|
|
39
|
+
});
|
|
40
|
+
it("should prefix a plugin's tags with its name", () => {
|
|
41
|
+
const parsed = config({}, blacklistPlugin());
|
|
42
|
+
expect(parsed.blacklist[0].tags).to.deep.equal(["BlacklistPlugin-cart"]);
|
|
43
|
+
});
|
|
44
|
+
it("should drop the rules an exclude option names", () => {
|
|
45
|
+
const parsed = config({}, blacklistPlugin({ exclude: ["cart"] }));
|
|
46
|
+
expect(parsed.blacklist).to.have.lengthOf(1);
|
|
47
|
+
expect(parsed.blacklist[0].tags).to.deep.equal([
|
|
48
|
+
"BlacklistPlugin-checkout",
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
it("should accept an exclude option that carries the plugin name", () => {
|
|
52
|
+
const parsed = config({}, blacklistPlugin({ exclude: ["BlacklistPlugin-cart"] }));
|
|
53
|
+
expect(parsed.blacklist).to.have.lengthOf(1);
|
|
54
|
+
});
|
|
55
|
+
it("should refuse a blacklist rule with a key that is no condition", () => {
|
|
56
|
+
// The snippet drops the whole contribution rather than feed the service
|
|
57
|
+
// worker a rule it cannot read.
|
|
58
|
+
const parsed = config({ blacklist: [{ host: "a.de" }] }, {
|
|
59
|
+
name: "BrokenPlugin",
|
|
60
|
+
addBlacklist: () => [{ pathname: [/cart/i], sometimes: true }],
|
|
61
|
+
});
|
|
62
|
+
expect(parsed.blacklist).to.have.lengthOf(1);
|
|
63
|
+
});
|
|
64
|
+
it("should add the scopes a plugin disables", () => {
|
|
65
|
+
const parsed = config({ disabledScopes: ["/admin"] }, {
|
|
66
|
+
name: "ShopifyPlugin",
|
|
67
|
+
addDisabledScopes: () => ["/cart", "/checkout"],
|
|
68
|
+
});
|
|
69
|
+
expect(parsed.disabledScopes).to.deep.equal([
|
|
70
|
+
"/admin",
|
|
71
|
+
"/cart",
|
|
72
|
+
"/checkout",
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
it("should take a single disabled scope as a list of one", () => {
|
|
76
|
+
const parsed = config({}, {
|
|
77
|
+
name: "P",
|
|
78
|
+
addDisabledScopes: () => "/checkout",
|
|
79
|
+
});
|
|
80
|
+
expect(parsed.disabledScopes).to.deep.equal(["/checkout"]);
|
|
81
|
+
});
|
|
82
|
+
describe("stripQueryParams", () => {
|
|
83
|
+
const paramPlugin = {
|
|
84
|
+
name: "StripQueryParamPlugin",
|
|
85
|
+
addStripQueryParams: () => [{ params: ["gclid"], tags: ["ads"] }],
|
|
86
|
+
};
|
|
87
|
+
it("should merge two bare conditions into one", () => {
|
|
88
|
+
const parsed = config({ stripQueryParams: ["size"] }, {
|
|
89
|
+
name: "P",
|
|
90
|
+
addStripQueryParams: () => ["gclid", "fbclid"],
|
|
91
|
+
});
|
|
92
|
+
expect(parsed.stripQueryParams).to.deep.equal([
|
|
93
|
+
"size",
|
|
94
|
+
"gclid",
|
|
95
|
+
"fbclid",
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
it("should turn a bare condition into rules when the plugin brings rules", () => {
|
|
99
|
+
// Conditions and rules must not be mixed — the service worker converts
|
|
100
|
+
// the property as a whole.
|
|
101
|
+
const parsed = config({ stripQueryParams: ["size"] }, paramPlugin);
|
|
102
|
+
expect(parsed.stripQueryParams).to.deep.equal([
|
|
103
|
+
{ params: ["size"] },
|
|
104
|
+
{ params: ["gclid"], tags: ["StripQueryParamPlugin-ads"] },
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
it("should append to the rules a config already has", () => {
|
|
108
|
+
const parsed = config({ stripQueryParams: [{ params: ["size"] }] }, paramPlugin);
|
|
109
|
+
expect(parsed.stripQueryParams).to.have.lengthOf(2);
|
|
110
|
+
});
|
|
111
|
+
it("should recognise a pattern from the config's own realm", () => {
|
|
112
|
+
// The config is evaluated in a vm, so its regular expressions are not
|
|
113
|
+
// `instanceof RegExp` here. Read as rules, a bare list of them carries
|
|
114
|
+
// no `params` and every parameter would silently stop being stripped.
|
|
115
|
+
const foreign = vm.runInNewContext("[/^utm[_-]/]");
|
|
116
|
+
const parsed = config({ stripQueryParams: foreign }, {
|
|
117
|
+
name: "P",
|
|
118
|
+
addStripQueryParams: () => ["gclid"],
|
|
119
|
+
});
|
|
120
|
+
expect(parsed.stripQueryParams).to.have.lengthOf(2);
|
|
121
|
+
expect(parsed.stripQueryParams[1]).to.equal("gclid");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it("should let applyToConfig change the config directly", () => {
|
|
125
|
+
const parsed = config({}, {
|
|
126
|
+
name: "SSRPlugin",
|
|
127
|
+
applyToConfig: (speedKit) => {
|
|
128
|
+
speedKit.disabledSites = [{ pathname: [/\/print/i] }];
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
expect(parsed.disabledSites).to.have.lengthOf(1);
|
|
132
|
+
expect(parsed.plugins).to.deep.equal(["SSRPlugin"]);
|
|
133
|
+
});
|
|
134
|
+
it("should run applyToConfig after every other hook", () => {
|
|
135
|
+
// `BlacklistPlugin.applyToConfig` reads back what its own `addBlacklist`
|
|
136
|
+
// contributed, so the order is not an implementation detail.
|
|
137
|
+
const seen = [];
|
|
138
|
+
config({}, {
|
|
139
|
+
name: "P",
|
|
140
|
+
applyToConfig: (speedKit) => seen.push(speedKit.blacklist.length),
|
|
141
|
+
addBlacklist: () => [{ pathname: [/cart/i] }],
|
|
142
|
+
});
|
|
143
|
+
expect(seen).to.deep.equal([1]);
|
|
144
|
+
});
|
|
145
|
+
it("should show a hook the config as it was before any plugin ran", () => {
|
|
146
|
+
const seen = [];
|
|
147
|
+
const record = (speedKit) => {
|
|
148
|
+
seen.push(speedKit.blacklist?.length ?? 0);
|
|
149
|
+
return [{ pathname: [/cart/i] }];
|
|
150
|
+
};
|
|
151
|
+
config({}, { name: "First", addBlacklist: record }, { name: "Second", addBlacklist: record });
|
|
152
|
+
// The second plugin must not see the first one's rule.
|
|
153
|
+
expect(seen).to.deep.equal([0, 0]);
|
|
154
|
+
});
|
|
155
|
+
it("should keep the other plugins when one of them throws", () => {
|
|
156
|
+
const parsed = config({}, {
|
|
157
|
+
name: "BrokenPlugin",
|
|
158
|
+
addBlacklist: () => {
|
|
159
|
+
throw new Error("no");
|
|
160
|
+
},
|
|
161
|
+
}, blacklistPlugin());
|
|
162
|
+
expect(parsed.blacklist).to.have.lengthOf(2);
|
|
163
|
+
expect(parsed.plugins).to.deep.equal(["BlacklistPlugin"]);
|
|
164
|
+
});
|
|
165
|
+
it("should ignore a hook it knows nothing about", () => {
|
|
166
|
+
const parsed = config({}, {
|
|
167
|
+
name: "ShopifyPlugin",
|
|
168
|
+
onShopifyAnalyticsReady: () => "never called here",
|
|
169
|
+
});
|
|
170
|
+
expect(parsed.plugins).to.deep.equal([]);
|
|
171
|
+
});
|
|
172
|
+
it("should read the fields a pre-deploy check compares from the file", () => {
|
|
173
|
+
// `SSRPlugin` replaces `detectDevice` with a wrapper of its own. A check
|
|
174
|
+
// asking whether a human changed the device detection has to see the
|
|
175
|
+
// function in the file, not the wrapper around it.
|
|
176
|
+
const detectDevice = () => "mobile";
|
|
177
|
+
const parsed = config({ detectDevice, split: 0.5 }, {
|
|
178
|
+
name: "SSRPlugin",
|
|
179
|
+
applyToConfig: (speedKit) => {
|
|
180
|
+
speedKit.detectDevice = () => "wrapped";
|
|
181
|
+
speedKit.split = 1;
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
expect(parsed.detectDevice).to.equal(detectDevice);
|
|
185
|
+
expect(parsed.split).to.equal(0.5);
|
|
186
|
+
expect(parsed.effective.split).to.equal(1);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { describe, it } from "mocha";
|
|
3
|
-
import {
|
|
3
|
+
import { SpeedKitConfigFile, VirtualSpeedKitConfigFile, } from "../index.js";
|
|
4
|
+
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
4
5
|
function configFile(source) {
|
|
5
|
-
return
|
|
6
|
-
getContent: () => source,
|
|
7
|
-
path: "config_SpeedKit.js",
|
|
8
|
-
};
|
|
6
|
+
return new SpeedKitConfigFile(INTEGRATION_FILES.CONFIG.SPEED_KIT, "config_SpeedKit.js", source, "config");
|
|
9
7
|
}
|
|
10
8
|
function evaluate(source) {
|
|
11
|
-
return
|
|
9
|
+
return configFile(source).evaluate("shop-de", "https://www.shop.de");
|
|
12
10
|
}
|
|
13
|
-
|
|
11
|
+
/** What the config assigned, for the tests about the browser mock itself. */
|
|
12
|
+
async function evaluateRaw(source) {
|
|
13
|
+
return (await evaluate(source)).raw;
|
|
14
|
+
}
|
|
15
|
+
describe("SpeedKitConfigFile", () => {
|
|
14
16
|
it("should read the app and the origin the config is evaluated for", async () => {
|
|
15
|
-
const speedKit = await
|
|
17
|
+
const speedKit = await evaluateRaw(`
|
|
16
18
|
window.speedKit = { appName: APP, host: window.location.host };
|
|
17
19
|
`);
|
|
18
20
|
expect(speedKit.appName).to.equal("shop-de");
|
|
@@ -22,7 +24,7 @@ describe("evaluateLocalSpeedKitConfig", () => {
|
|
|
22
24
|
// A real shape: `precache` is collected from the document's own script and
|
|
23
25
|
// link tags. A `querySelectorAll` returning undefined would throw here,
|
|
24
26
|
// and the whole config — every rule in it — would be unreadable.
|
|
25
|
-
const speedKit = await
|
|
27
|
+
const speedKit = await evaluateRaw(`
|
|
26
28
|
window.speedKit = {
|
|
27
29
|
appName: APP,
|
|
28
30
|
precache: Array.from(
|
|
@@ -41,7 +43,7 @@ describe("evaluateLocalSpeedKitConfig", () => {
|
|
|
41
43
|
// `document.referrer` to tell a new visitor from a returning one. When
|
|
42
44
|
// `window.location` was undefined this failed with
|
|
43
45
|
// "Cannot read properties of undefined (reading 'hostname')".
|
|
44
|
-
const speedKit = await
|
|
46
|
+
const speedKit = await evaluateRaw(`
|
|
45
47
|
var hostname = window.location.hostname;
|
|
46
48
|
var isNewUser = !document.referrer;
|
|
47
49
|
window.speedKit = {
|
|
@@ -56,7 +58,7 @@ describe("evaluateLocalSpeedKitConfig", () => {
|
|
|
56
58
|
expect(speedKit.isNewUser).to.equal(true);
|
|
57
59
|
});
|
|
58
60
|
it("should answer a missing element with null, the way the dom does", async () => {
|
|
59
|
-
const speedKit = await
|
|
61
|
+
const speedKit = await evaluateRaw(`
|
|
60
62
|
window.speedKit = {
|
|
61
63
|
appName: APP,
|
|
62
64
|
hasMarker: document.querySelector('.marker') !== null,
|
|
@@ -72,7 +74,36 @@ describe("evaluateLocalSpeedKitConfig", () => {
|
|
|
72
74
|
expect.fail("should have thrown");
|
|
73
75
|
}
|
|
74
76
|
catch (error) {
|
|
75
|
-
expect(String(error)).to.contain("
|
|
77
|
+
expect(String(error)).to.contain("config_SpeedKit.js");
|
|
76
78
|
}
|
|
77
79
|
});
|
|
80
|
+
it("should read a config once per app and origin", async () => {
|
|
81
|
+
// Two callers asking for the same reading get the same one — the query
|
|
82
|
+
// builder and the pre-deploy checks both go through here.
|
|
83
|
+
const file = configFile(`window.speedKit = { host: window.location.host };`);
|
|
84
|
+
const [first, second] = await Promise.all([
|
|
85
|
+
file.evaluate("shop-de", "https://www.shop.de"),
|
|
86
|
+
file.evaluate("shop-de", "https://www.shop.de"),
|
|
87
|
+
]);
|
|
88
|
+
const otherOrigin = await file.evaluate("shop-de", "https://m.shop.de");
|
|
89
|
+
expect(first).to.equal(second);
|
|
90
|
+
expect(otherOrigin).to.not.equal(first);
|
|
91
|
+
expect(otherOrigin.raw.host).to.equal("m.shop.de");
|
|
92
|
+
});
|
|
93
|
+
it("should forget what it read when the file changes", async () => {
|
|
94
|
+
const file = configFile(`window.speedKit = { split: 0.1 };`);
|
|
95
|
+
const before = await file.evaluate("shop-de", "https://www.shop.de");
|
|
96
|
+
file.setContent(`window.speedKit = { split: 0.5 };`);
|
|
97
|
+
const after = await file.evaluate("shop-de", "https://www.shop.de");
|
|
98
|
+
expect(before.split).to.equal(0.1);
|
|
99
|
+
expect(after.split).to.equal(0.5);
|
|
100
|
+
});
|
|
101
|
+
it("should read the deployed config the same way as the local file", async () => {
|
|
102
|
+
const source = `window.speedKit = { split: 0.5, appName: APP };`;
|
|
103
|
+
const remote = await VirtualSpeedKitConfigFile.createRemote(source);
|
|
104
|
+
const local = await evaluate(source);
|
|
105
|
+
const deployed = await remote.evaluate("shop-de", "https://www.shop.de");
|
|
106
|
+
expect(deployed).to.deep.equal(local);
|
|
107
|
+
expect(remote.getContent()).to.equal(source);
|
|
108
|
+
});
|
|
78
109
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { SpeedKitConfig } from "../struct/speed-kit-config.js";
|
|
4
|
+
describe("SpeedKitConfig", () => {
|
|
5
|
+
describe("ruleSetVersion", () => {
|
|
6
|
+
it("should default to version 1", () => {
|
|
7
|
+
expect(SpeedKitConfig.createFrom({}).ruleSetVersion).to.equal(1);
|
|
8
|
+
});
|
|
9
|
+
it("should read the declared version", () => {
|
|
10
|
+
const config = SpeedKitConfig.createFrom({
|
|
11
|
+
ruleSetConfig: { version: 2 },
|
|
12
|
+
});
|
|
13
|
+
expect(config.ruleSetVersion).to.equal(2);
|
|
14
|
+
});
|
|
15
|
+
it("should read a version given as a string", () => {
|
|
16
|
+
const config = SpeedKitConfig.createFrom({
|
|
17
|
+
ruleSetConfig: { version: "2" },
|
|
18
|
+
});
|
|
19
|
+
expect(config.ruleSetVersion).to.equal(2);
|
|
20
|
+
});
|
|
21
|
+
it("should fall back for an unusable version", () => {
|
|
22
|
+
const config = SpeedKitConfig.createFrom({
|
|
23
|
+
ruleSetConfig: { version: "x" },
|
|
24
|
+
});
|
|
25
|
+
expect(config.ruleSetVersion).to.equal(1);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("rule sets", () => {
|
|
29
|
+
it("should give every rule set for a config that declares none", () => {
|
|
30
|
+
const config = SpeedKitConfig.createFrom({});
|
|
31
|
+
expect(config.blacklist).to.deep.equal([]);
|
|
32
|
+
expect(config.disabledScopes).to.deep.equal([]);
|
|
33
|
+
expect(config.disabledSites).to.deep.equal([]);
|
|
34
|
+
expect(config.enabledSites).to.deep.equal([]);
|
|
35
|
+
expect(config.stripQueryParams).to.deep.equal([]);
|
|
36
|
+
expect(config.whitelist).to.deep.equal([]);
|
|
37
|
+
});
|
|
38
|
+
it("should ignore a rule set that is not an array", () => {
|
|
39
|
+
const config = SpeedKitConfig.createFrom({ blacklist: "everything" });
|
|
40
|
+
expect(config.blacklist).to.deep.equal([]);
|
|
41
|
+
});
|
|
42
|
+
it("should drop an entry of a rule set that is not a rule", () => {
|
|
43
|
+
const config = SpeedKitConfig.createFrom({
|
|
44
|
+
whitelist: [{ host: "a.de" }, "b.de", undefined, [{ host: "c.de" }]],
|
|
45
|
+
});
|
|
46
|
+
expect(config.whitelist).to.deep.equal([{ host: "a.de" }]);
|
|
47
|
+
});
|
|
48
|
+
it("should keep the rules of a rule set as they were written", () => {
|
|
49
|
+
const rule = { host: ["www.shop.de"], pathname: [/^\/p\//i] };
|
|
50
|
+
const config = SpeedKitConfig.createFrom({ enabledSites: [rule] });
|
|
51
|
+
expect(config.enabledSites[0]).to.deep.equal(rule);
|
|
52
|
+
// A plugin may only ever add to a copy, so the evaluated config a
|
|
53
|
+
// caller holds is never changed under it.
|
|
54
|
+
expect(config.raw.enabledSites[0]).to.equal(rule);
|
|
55
|
+
expect(config.enabledSites[0]).to.not.equal(rule);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("stripQueryParams", () => {
|
|
59
|
+
it("should wrap a bare condition in a list", () => {
|
|
60
|
+
const config = SpeedKitConfig.createFrom({ stripQueryParams: "gclid" });
|
|
61
|
+
expect(config.stripQueryParams).to.deep.equal(["gclid"]);
|
|
62
|
+
});
|
|
63
|
+
it("should keep a list as it is", () => {
|
|
64
|
+
const config = SpeedKitConfig.createFrom({
|
|
65
|
+
stripQueryParams: [{ params: ["size"] }],
|
|
66
|
+
});
|
|
67
|
+
expect(config.stripQueryParams).to.deep.equal([{ params: ["size"] }]);
|
|
68
|
+
});
|
|
69
|
+
it("should read a missing property as nothing to strip", () => {
|
|
70
|
+
expect(SpeedKitConfig.createFrom({}).stripQueryParams).to.deep.equal([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("the fields the pre-deploy checks read", () => {
|
|
74
|
+
it("should carry the split, its id, and the device detection", () => {
|
|
75
|
+
const detectDevice = () => "mobile";
|
|
76
|
+
const variationFunction = () => "b";
|
|
77
|
+
const config = SpeedKitConfig.createFrom({
|
|
78
|
+
customVariation: [{ variationFunction }],
|
|
79
|
+
detectDevice,
|
|
80
|
+
split: 0.5,
|
|
81
|
+
splitTestId: "2026-09-jeans",
|
|
82
|
+
});
|
|
83
|
+
expect(config.split).to.equal(0.5);
|
|
84
|
+
expect(config.splitTestId).to.equal("2026-09-jeans");
|
|
85
|
+
expect(config.detectDevice).to.equal(detectDevice);
|
|
86
|
+
expect(config.customVariation[0].variationFunction).to.equal(variationFunction);
|
|
87
|
+
});
|
|
88
|
+
it("should leave customVariation undefined when there is none", () => {
|
|
89
|
+
expect(SpeedKitConfig.createFrom({}).customVariation).to.equal(undefined);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it("should apply no plugin when a config registers none", () => {
|
|
93
|
+
const config = SpeedKitConfig.createFrom({ blacklist: [{ host: "a.de" }] });
|
|
94
|
+
expect(config.plugins).to.deep.equal([]);
|
|
95
|
+
expect(config.effective).to.deep.equal(config.raw);
|
|
96
|
+
});
|
|
97
|
+
it("should keep everything the config assigned", () => {
|
|
98
|
+
// A config carries far more than the CLI reads — appName, precache,
|
|
99
|
+
// loadHandler — and nothing may be lost on the way through here.
|
|
100
|
+
const evaluated = { appName: "shop-de", precache: ["/app.js"] };
|
|
101
|
+
expect(SpeedKitConfig.createFrom(evaluated).raw).to.equal(evaluated);
|
|
102
|
+
});
|
|
103
|
+
it("should survive a config that assigned no object at all", () => {
|
|
104
|
+
const config = SpeedKitConfig.createFrom(undefined);
|
|
105
|
+
expect(config.raw).to.deep.equal({});
|
|
106
|
+
expect(config.whitelist).to.deep.equal([]);
|
|
107
|
+
});
|
|
108
|
+
});
|