@eventvisor/core 0.0.2
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/LICENSE +21 -0
- package/README.md +9 -0
- package/jest.config.js +4 -0
- package/lib/builder/buildProject.d.ts +21 -0
- package/lib/builder/buildProject.js +153 -0
- package/lib/builder/buildProject.js.map +1 -0
- package/lib/builder/hashes.d.ts +2 -0
- package/lib/builder/hashes.js +59 -0
- package/lib/builder/hashes.js.map +1 -0
- package/lib/builder/index.d.ts +1 -0
- package/lib/builder/index.js +18 -0
- package/lib/builder/index.js.map +1 -0
- package/lib/cli/cli.d.ts +26 -0
- package/lib/cli/cli.js +69 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/index.d.ts +1 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/plugins.d.ts +4 -0
- package/lib/cli/plugins.js +12 -0
- package/lib/cli/plugins.js.map +1 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +19 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/parsers.d.ts +15 -0
- package/lib/config/parsers.js +65 -0
- package/lib/config/parsers.js.map +1 -0
- package/lib/config/projectConfig.d.ts +42 -0
- package/lib/config/projectConfig.js +137 -0
- package/lib/config/projectConfig.js.map +1 -0
- package/lib/datasource/adapter.d.ts +16 -0
- package/lib/datasource/adapter.js +7 -0
- package/lib/datasource/adapter.js.map +1 -0
- package/lib/datasource/datasource.d.ts +48 -0
- package/lib/datasource/datasource.js +117 -0
- package/lib/datasource/datasource.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +29 -0
- package/lib/datasource/filesystemAdapter.js +192 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +3 -0
- package/lib/datasource/index.js +20 -0
- package/lib/datasource/index.js.map +1 -0
- package/lib/dependencies.d.ts +11 -0
- package/lib/dependencies.js +3 -0
- package/lib/dependencies.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/index.spec.d.ts +0 -0
- package/lib/index.spec.js +6 -0
- package/lib/index.spec.js.map +1 -0
- package/lib/init/index.d.ts +8 -0
- package/lib/init/index.js +90 -0
- package/lib/init/index.js.map +1 -0
- package/lib/linter/attributeSchema.d.ts +5 -0
- package/lib/linter/attributeSchema.js +55 -0
- package/lib/linter/attributeSchema.js.map +1 -0
- package/lib/linter/conditionsSchema.d.ts +303 -0
- package/lib/linter/conditionsSchema.js +106 -0
- package/lib/linter/conditionsSchema.js.map +1 -0
- package/lib/linter/destinationSchema.d.ts +5 -0
- package/lib/linter/destinationSchema.js +57 -0
- package/lib/linter/destinationSchema.js.map +1 -0
- package/lib/linter/effectSchema.d.ts +1257 -0
- package/lib/linter/effectSchema.js +77 -0
- package/lib/linter/effectSchema.js.map +1 -0
- package/lib/linter/eventSchema.d.ts +5 -0
- package/lib/linter/eventSchema.js +70 -0
- package/lib/linter/eventSchema.js.map +1 -0
- package/lib/linter/index.d.ts +1 -0
- package/lib/linter/index.js +18 -0
- package/lib/linter/index.js.map +1 -0
- package/lib/linter/jsonSchema.d.ts +25 -0
- package/lib/linter/jsonSchema.js +487 -0
- package/lib/linter/jsonSchema.js.map +1 -0
- package/lib/linter/jsonSchema.spec.d.ts +1 -0
- package/lib/linter/jsonSchema.spec.js +875 -0
- package/lib/linter/jsonSchema.spec.js.map +1 -0
- package/lib/linter/lintProject.d.ts +2 -0
- package/lib/linter/lintProject.js +141 -0
- package/lib/linter/lintProject.js.map +1 -0
- package/lib/linter/persistSchema.d.ts +609 -0
- package/lib/linter/persistSchema.js +52 -0
- package/lib/linter/persistSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +9 -0
- package/lib/linter/printError.js +75 -0
- package/lib/linter/printError.js.map +1 -0
- package/lib/linter/sampleSchema.d.ts +331 -0
- package/lib/linter/sampleSchema.js +70 -0
- package/lib/linter/sampleSchema.js.map +1 -0
- package/lib/linter/sourceSchema.d.ts +11 -0
- package/lib/linter/sourceSchema.js +73 -0
- package/lib/linter/sourceSchema.js.map +1 -0
- package/lib/linter/tagsSchema.d.ts +3 -0
- package/lib/linter/tagsSchema.js +44 -0
- package/lib/linter/tagsSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +5 -0
- package/lib/linter/testSchema.js +44 -0
- package/lib/linter/testSchema.js.map +1 -0
- package/lib/linter/transformsSchema.d.ts +29 -0
- package/lib/linter/transformsSchema.js +66 -0
- package/lib/linter/transformsSchema.js.map +1 -0
- package/lib/tester/createTestInstance.d.ts +16 -0
- package/lib/tester/createTestInstance.js +158 -0
- package/lib/tester/createTestInstance.js.map +1 -0
- package/lib/tester/executeTest.d.ts +24 -0
- package/lib/tester/executeTest.js +305 -0
- package/lib/tester/executeTest.js.map +1 -0
- package/lib/tester/index.d.ts +1 -0
- package/lib/tester/index.js +18 -0
- package/lib/tester/index.js.map +1 -0
- package/lib/tester/printTestResult.d.ts +10 -0
- package/lib/tester/printTestResult.js +80 -0
- package/lib/tester/printTestResult.js.map +1 -0
- package/lib/tester/testProject.d.ts +12 -0
- package/lib/tester/testProject.js +93 -0
- package/lib/tester/testProject.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +18 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/prettyDuration.d.ts +1 -0
- package/lib/utils/prettyDuration.js +27 -0
- package/lib/utils/prettyDuration.js.map +1 -0
- package/package.json +42 -0
- package/src/builder/buildProject.ts +222 -0
- package/src/builder/hashes.ts +30 -0
- package/src/builder/index.ts +1 -0
- package/src/cli/cli.ts +110 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/plugins.ts +13 -0
- package/src/config/index.ts +2 -0
- package/src/config/parsers.ts +40 -0
- package/src/config/projectConfig.ts +158 -0
- package/src/datasource/adapter.ts +23 -0
- package/src/datasource/datasource.ts +164 -0
- package/src/datasource/filesystemAdapter.ts +206 -0
- package/src/datasource/index.ts +3 -0
- package/src/dependencies.ts +13 -0
- package/src/index.spec.ts +5 -0
- package/src/index.ts +4 -0
- package/src/init/index.ts +65 -0
- package/src/linter/attributeSchema.ts +23 -0
- package/src/linter/conditionsSchema.ts +89 -0
- package/src/linter/destinationSchema.ts +25 -0
- package/src/linter/effectSchema.ts +49 -0
- package/src/linter/eventSchema.ts +40 -0
- package/src/linter/index.ts +1 -0
- package/src/linter/jsonSchema.spec.ts +934 -0
- package/src/linter/jsonSchema.ts +533 -0
- package/src/linter/lintProject.ts +182 -0
- package/src/linter/persistSchema.ts +21 -0
- package/src/linter/printError.ts +50 -0
- package/src/linter/sampleSchema.ts +45 -0
- package/src/linter/sourceSchema.ts +42 -0
- package/src/linter/tagsSchema.ts +12 -0
- package/src/linter/testSchema.ts +9 -0
- package/src/linter/transformsSchema.ts +35 -0
- package/src/tester/createTestInstance.ts +209 -0
- package/src/tester/executeTest.ts +436 -0
- package/src/tester/index.ts +1 -0
- package/src/tester/printTestResult.ts +60 -0
- package/src/tester/testProject.ts +129 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/prettyDuration.ts +27 -0
- package/tsconfig.cjs.json +11 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getTestSchema = getTestSchema;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
function getTestSchema(deps) {
|
|
40
|
+
return z.object({
|
|
41
|
+
archived: z.boolean().optional(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=testSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testSchema.js","sourceRoot":"","sources":["../../src/linter/testSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,sCAIC;AARD,uCAAyB;AAGzB,2BAA2B;AAC3B,SAAgB,aAAa,CAAC,IAAkB;IAC9C,OAAO,CAAC,CAAC,MAAM,CAAC;QACd,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;KACjC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { Dependencies } from "../dependencies";
|
|
3
|
+
export declare function getTransformsSchema(deps: Dependencies): z.ZodArray<z.ZodObject<{
|
|
4
|
+
type: z.ZodEnum<{
|
|
5
|
+
toString: "toString";
|
|
6
|
+
concat: "concat";
|
|
7
|
+
trim: "trim";
|
|
8
|
+
set: "set";
|
|
9
|
+
remove: "remove";
|
|
10
|
+
append: "append";
|
|
11
|
+
increment: "increment";
|
|
12
|
+
decrement: "decrement";
|
|
13
|
+
rename: "rename";
|
|
14
|
+
toInteger: "toInteger";
|
|
15
|
+
toDouble: "toDouble";
|
|
16
|
+
toBoolean: "toBoolean";
|
|
17
|
+
spread: "spread";
|
|
18
|
+
}>;
|
|
19
|
+
target: z.ZodOptional<z.ZodString>;
|
|
20
|
+
targetMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
21
|
+
value: z.ZodOptional<z.ZodAny>;
|
|
22
|
+
separator: z.ZodOptional<z.ZodString>;
|
|
23
|
+
source: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
24
|
+
attribute: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
25
|
+
state: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
26
|
+
effect: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
27
|
+
payload: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
28
|
+
lookup: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getTransformsSchema = getTransformsSchema;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
38
|
+
const sourceSchema_1 = require("./sourceSchema");
|
|
39
|
+
function getTransformsSchema(deps) {
|
|
40
|
+
return z.array(z.object({
|
|
41
|
+
// .refine() is intentionally not called here for now, since not all transforms need sources
|
|
42
|
+
// @TODO: make it stricter based on transform types
|
|
43
|
+
...(0, sourceSchema_1.getSourceBaseSchema)(deps).shape,
|
|
44
|
+
type: z.enum([
|
|
45
|
+
"increment",
|
|
46
|
+
"decrement",
|
|
47
|
+
"concat", // @TODO: rename to `join`?
|
|
48
|
+
"remove",
|
|
49
|
+
"rename",
|
|
50
|
+
"set",
|
|
51
|
+
"trim",
|
|
52
|
+
"toInteger",
|
|
53
|
+
"toDouble",
|
|
54
|
+
"toString",
|
|
55
|
+
"toBoolean",
|
|
56
|
+
"spread",
|
|
57
|
+
"append",
|
|
58
|
+
]),
|
|
59
|
+
target: z.string().optional(),
|
|
60
|
+
targetMap: z.record(z.string(), z.any()).optional(),
|
|
61
|
+
value: z.any().optional(),
|
|
62
|
+
// transform type specific params
|
|
63
|
+
separator: z.string().optional(),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=transformsSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformsSchema.js","sourceRoot":"","sources":["../../src/linter/transformsSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,kDA6BC;AAlCD,uCAAyB;AAGzB,iDAAqD;AAErD,SAAgB,mBAAmB,CAAC,IAAkB;IACpD,OAAO,CAAC,CAAC,KAAK,CACZ,CAAC,CAAC,MAAM,CAAC;QACP,4FAA4F;QAC5F,mDAAmD;QACnD,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAC,KAAK;QAClC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;YACX,WAAW;YACX,WAAW;YACX,QAAQ,EAAE,2BAA2B;YACrC,QAAQ;YACR,QAAQ;YACR,KAAK;YACL,MAAM;YACN,WAAW;YACX,UAAU;YACV,UAAU;YACV,WAAW;YACX,QAAQ;YACR,QAAQ;SACT,CAAC;QACF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE;QACnD,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;QAEzB,iCAAiC;QACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACjC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DatafileContent, WithLookups, Value, Step } from "@eventvisor/types";
|
|
2
|
+
import { Eventvisor } from "@eventvisor/sdk";
|
|
3
|
+
import type { TestProjectOptions } from "./testProject";
|
|
4
|
+
export interface CreateTestInstanceResult {
|
|
5
|
+
e: Eventvisor;
|
|
6
|
+
getBodiesByDestination: () => Record<string, Value[]>;
|
|
7
|
+
getBodiesBySingleDestination: (destinationName: string) => Value[] | undefined;
|
|
8
|
+
getCalledStepsByEffect: () => Record<string, Step[]>;
|
|
9
|
+
getCalledStepsBySingleEffect: (effectName: string) => Step[] | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateTestInstanceOptions {
|
|
12
|
+
datafile: DatafileContent;
|
|
13
|
+
cliOptions: TestProjectOptions;
|
|
14
|
+
withLookups?: WithLookups;
|
|
15
|
+
}
|
|
16
|
+
export declare function createTestInstance(options: CreateTestInstanceOptions): CreateTestInstanceResult;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestInstance = createTestInstance;
|
|
4
|
+
const sdk_1 = require("@eventvisor/sdk");
|
|
5
|
+
function createTestInstance(options) {
|
|
6
|
+
const { datafile, cliOptions, withLookups } = options;
|
|
7
|
+
/**
|
|
8
|
+
* Log level
|
|
9
|
+
*/
|
|
10
|
+
let logLevel = "error";
|
|
11
|
+
if (cliOptions.verbose) {
|
|
12
|
+
logLevel = "debug";
|
|
13
|
+
}
|
|
14
|
+
else if (cliOptions.quiet) {
|
|
15
|
+
logLevel = "fatal";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Transport names
|
|
19
|
+
*/
|
|
20
|
+
const transportNames = new Set();
|
|
21
|
+
const destinationNames = Object.keys(datafile.destinations);
|
|
22
|
+
for (const destinationName of destinationNames) {
|
|
23
|
+
const destination = datafile.destinations[destinationName];
|
|
24
|
+
if (destination.transport) {
|
|
25
|
+
transportNames.add(destination.transport);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Storage names
|
|
30
|
+
*/
|
|
31
|
+
const storageNames = new Set();
|
|
32
|
+
const attributes = Object.keys(datafile.attributes);
|
|
33
|
+
for (const attributeName of attributes) {
|
|
34
|
+
const attribute = datafile.attributes[attributeName];
|
|
35
|
+
if (attribute.persist) {
|
|
36
|
+
const persists = (0, sdk_1.getComplexPersists)(attribute.persist);
|
|
37
|
+
for (const persist of persists) {
|
|
38
|
+
storageNames.add(persist.storage);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Handler names
|
|
44
|
+
*/
|
|
45
|
+
const handlerNames = new Set();
|
|
46
|
+
const effects = Object.keys(datafile.effects);
|
|
47
|
+
for (const effectName of effects) {
|
|
48
|
+
const effect = datafile.effects[effectName];
|
|
49
|
+
// handler
|
|
50
|
+
if (effect.steps) {
|
|
51
|
+
for (const step of effect.steps) {
|
|
52
|
+
if (step.handler) {
|
|
53
|
+
handlerNames.add(step.handler);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// storage
|
|
58
|
+
if (effect.persist) {
|
|
59
|
+
const persists = (0, sdk_1.getComplexPersists)(effect.persist);
|
|
60
|
+
for (const persist of persists) {
|
|
61
|
+
storageNames.add(persist.storage);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Modules
|
|
67
|
+
*/
|
|
68
|
+
const modules = [];
|
|
69
|
+
const bodiesByDestination = {};
|
|
70
|
+
const calledStepsByEffect = {};
|
|
71
|
+
const lookupsMap = {};
|
|
72
|
+
for (const [key, value] of Object.entries(withLookups || {})) {
|
|
73
|
+
const [moduleName, ...keyParts] = key.split(".");
|
|
74
|
+
const lookupKey = keyParts.join(".");
|
|
75
|
+
if (typeof lookupsMap[moduleName] === "undefined") {
|
|
76
|
+
lookupsMap[moduleName] = {};
|
|
77
|
+
}
|
|
78
|
+
lookupsMap[moduleName][lookupKey] = value;
|
|
79
|
+
}
|
|
80
|
+
const allModuleNames = Array.from(handlerNames)
|
|
81
|
+
.concat(Array.from(transportNames))
|
|
82
|
+
.concat(Object.keys(lookupsMap))
|
|
83
|
+
.concat(Array.from(storageNames));
|
|
84
|
+
for (const moduleName of allModuleNames) {
|
|
85
|
+
const moduleObj = { name: moduleName };
|
|
86
|
+
// transport
|
|
87
|
+
if (transportNames.has(moduleName)) {
|
|
88
|
+
moduleObj.transport = (options) => {
|
|
89
|
+
const { destinationName, payload } = options;
|
|
90
|
+
if (typeof bodiesByDestination[destinationName] === "undefined") {
|
|
91
|
+
bodiesByDestination[destinationName] = [];
|
|
92
|
+
}
|
|
93
|
+
bodiesByDestination[destinationName].push(payload);
|
|
94
|
+
return Promise.resolve();
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// storage
|
|
98
|
+
if (storageNames.has(moduleName)) {
|
|
99
|
+
const storageData = {};
|
|
100
|
+
moduleObj.readFromStorage = (options) => {
|
|
101
|
+
const { key } = options;
|
|
102
|
+
return Promise.resolve(storageData[key]);
|
|
103
|
+
};
|
|
104
|
+
moduleObj.writeToStorage = (options) => {
|
|
105
|
+
const { key, value } = options;
|
|
106
|
+
storageData[key] = value;
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// handler
|
|
111
|
+
if (handlerNames.has(moduleName)) {
|
|
112
|
+
moduleObj.handle = (options) => {
|
|
113
|
+
const { effectName, step } = options;
|
|
114
|
+
if (typeof calledStepsByEffect[effectName] === "undefined") {
|
|
115
|
+
calledStepsByEffect[effectName] = [];
|
|
116
|
+
}
|
|
117
|
+
calledStepsByEffect[effectName].push(step);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// lookup
|
|
122
|
+
Object.keys(lookupsMap).forEach((moduleName) => {
|
|
123
|
+
if (moduleName === moduleObj.name) {
|
|
124
|
+
moduleObj.lookup = (options) => {
|
|
125
|
+
const { key } = options;
|
|
126
|
+
return Promise.resolve(lookupsMap[moduleName][key]);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
modules.push(moduleObj);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Instance
|
|
134
|
+
*/
|
|
135
|
+
const e = new sdk_1.Eventvisor({
|
|
136
|
+
datafile,
|
|
137
|
+
logLevel,
|
|
138
|
+
modules,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
e,
|
|
142
|
+
// destinations
|
|
143
|
+
getBodiesByDestination: () => {
|
|
144
|
+
return bodiesByDestination;
|
|
145
|
+
},
|
|
146
|
+
getBodiesBySingleDestination: (destinationName) => {
|
|
147
|
+
return bodiesByDestination[destinationName];
|
|
148
|
+
},
|
|
149
|
+
// effects
|
|
150
|
+
getCalledStepsByEffect: () => {
|
|
151
|
+
return calledStepsByEffect;
|
|
152
|
+
},
|
|
153
|
+
getCalledStepsBySingleEffect: (effectName) => {
|
|
154
|
+
return calledStepsByEffect[effectName];
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=createTestInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTestInstance.js","sourceRoot":"","sources":["../../src/tester/createTestInstance.ts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AAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,IAAI,gBAAU,CAAC;QACvB,QAAQ;QACR,QAAQ;QACR,OAAO;KACR,CAAC,CAAC;IAEH,OAAO;QACL,CAAC;QAED,eAAe;QACf,sBAAsB,EAAE,GAAG,EAAE;YAC3B,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QACD,4BAA4B,EAAE,CAAC,eAAuB,EAAE,EAAE;YACxD,OAAO,mBAAmB,CAAC,eAAe,CAAC,CAAC;QAC9C,CAAC;QAED,UAAU;QACV,sBAAsB,EAAE,GAAG,EAAE;YAC3B,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QACD,4BAA4B,EAAE,CAAC,UAAkB,EAAE,EAAE;YACnD,OAAO,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DatafileContent, Test } from "@eventvisor/types";
|
|
2
|
+
import type { TestProjectOptions } from "./testProject";
|
|
3
|
+
import type { Dependencies } from "../dependencies";
|
|
4
|
+
export interface TestAssertionResult {
|
|
5
|
+
passed: boolean;
|
|
6
|
+
description?: string;
|
|
7
|
+
errors?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface TestAssertionResult {
|
|
10
|
+
passed: boolean;
|
|
11
|
+
description?: string;
|
|
12
|
+
errors?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface TestResult {
|
|
15
|
+
passed: boolean;
|
|
16
|
+
assertions: TestAssertionResult[];
|
|
17
|
+
}
|
|
18
|
+
export interface ExecuteTestOptions {
|
|
19
|
+
deps: Dependencies;
|
|
20
|
+
datafileContent: DatafileContent;
|
|
21
|
+
test: Test;
|
|
22
|
+
cliOptions: TestProjectOptions;
|
|
23
|
+
}
|
|
24
|
+
export declare function executeTest(options: ExecuteTestOptions): Promise<TestResult>;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeTest = executeTest;
|
|
4
|
+
const createTestInstance_1 = require("./createTestInstance");
|
|
5
|
+
async function executeTest(options) {
|
|
6
|
+
const { datafileContent, test, cliOptions } = options;
|
|
7
|
+
const testResult = {
|
|
8
|
+
passed: true,
|
|
9
|
+
assertions: [],
|
|
10
|
+
};
|
|
11
|
+
let testPassed = true;
|
|
12
|
+
/**
|
|
13
|
+
* Attribute
|
|
14
|
+
*/
|
|
15
|
+
if ("attribute" in test) {
|
|
16
|
+
// attribute test spec
|
|
17
|
+
const attributeName = test.attribute;
|
|
18
|
+
const assertions = test.assertions;
|
|
19
|
+
for (const assertion of assertions) {
|
|
20
|
+
// @TODO: apply matrix
|
|
21
|
+
if (cliOptions.assertionPattern &&
|
|
22
|
+
!assertion.description?.includes(cliOptions.assertionPattern)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
let assertionPassed = true;
|
|
26
|
+
const { e } = (0, createTestInstance_1.createTestInstance)({
|
|
27
|
+
datafile: datafileContent,
|
|
28
|
+
cliOptions,
|
|
29
|
+
withLookups: assertion.withLookups,
|
|
30
|
+
});
|
|
31
|
+
if (assertion.setAttribute) {
|
|
32
|
+
await e.setAttributeAsync(attributeName, assertion.setAttribute);
|
|
33
|
+
}
|
|
34
|
+
const previouslySetAttribute = e.getAttributeValue(attributeName);
|
|
35
|
+
const isAttributeSet = e.isAttributeSet(attributeName);
|
|
36
|
+
const testAssertionResult = {
|
|
37
|
+
passed: assertionPassed,
|
|
38
|
+
description: assertion.description,
|
|
39
|
+
errors: [],
|
|
40
|
+
};
|
|
41
|
+
// expectedToBeValid
|
|
42
|
+
if (typeof assertion.expectedToBeValid === "boolean") {
|
|
43
|
+
if ((assertion.expectedToBeValid === true && !isAttributeSet) ||
|
|
44
|
+
(assertion.expectedToBeValid === false && isAttributeSet)) {
|
|
45
|
+
assertionPassed = false;
|
|
46
|
+
testAssertionResult.errors?.push(`expectedToBeValid: expected ${assertion.expectedToBeValid}, received ${!assertion.expectedToBeValid}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// expectedToBeSet
|
|
50
|
+
if (typeof assertion.expectedToBeSet === "boolean") {
|
|
51
|
+
if ((assertion.expectedToBeSet === true && !isAttributeSet) ||
|
|
52
|
+
(assertion.expectedToBeSet === false && isAttributeSet)) {
|
|
53
|
+
assertionPassed = false;
|
|
54
|
+
testAssertionResult.errors?.push(`expectedToBeSet: expected ${assertion.expectedToBeSet}, received ${!assertion.expectedToBeSet}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (assertion.expectedAttribute) {
|
|
58
|
+
if (!checkIfObjectsAreDeepEqual(previouslySetAttribute, assertion.expectedAttribute)) {
|
|
59
|
+
assertionPassed = false;
|
|
60
|
+
testAssertionResult.errors?.push(`expectedAttribute: \n expected: ${JSON.stringify(assertion.expectedAttribute)}\n received: ${JSON.stringify(previouslySetAttribute)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
testAssertionResult.passed = assertionPassed;
|
|
64
|
+
if (!assertionPassed) {
|
|
65
|
+
testPassed = false;
|
|
66
|
+
}
|
|
67
|
+
testResult.assertions.push(testAssertionResult);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Effect
|
|
72
|
+
*/
|
|
73
|
+
if ("effect" in test) {
|
|
74
|
+
const effectName = test.effect;
|
|
75
|
+
const assertions = test.assertions;
|
|
76
|
+
for (const assertion of assertions) {
|
|
77
|
+
// @TODO: apply matrix
|
|
78
|
+
if (cliOptions.assertionPattern &&
|
|
79
|
+
!assertion.description?.includes(cliOptions.assertionPattern)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
let assertionPassed = true;
|
|
83
|
+
const { e, getCalledStepsBySingleEffect } = (0, createTestInstance_1.createTestInstance)({
|
|
84
|
+
datafile: datafileContent,
|
|
85
|
+
cliOptions,
|
|
86
|
+
withLookups: assertion.withLookups,
|
|
87
|
+
});
|
|
88
|
+
await e.onReady();
|
|
89
|
+
if (assertion.actions) {
|
|
90
|
+
for (const action of assertion.actions) {
|
|
91
|
+
if (action.type === "track") {
|
|
92
|
+
await e.trackAsync(action.name, action.value);
|
|
93
|
+
}
|
|
94
|
+
else if (action.type === "setAttribute") {
|
|
95
|
+
await e.setAttributeAsync(action.name, action.value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const testAssertionResult = {
|
|
100
|
+
passed: assertionPassed,
|
|
101
|
+
description: assertion.description,
|
|
102
|
+
errors: [],
|
|
103
|
+
};
|
|
104
|
+
// expectedState
|
|
105
|
+
if (assertion.expectedState) {
|
|
106
|
+
const latestState = e.getStateValue(effectName);
|
|
107
|
+
if (!checkIfObjectsAreDeepEqual(latestState, assertion.expectedState)) {
|
|
108
|
+
assertionPassed = false;
|
|
109
|
+
testAssertionResult.errors?.push(`expectedState: \n expected: ${JSON.stringify(assertion.expectedState)}\n received: ${JSON.stringify(latestState)}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// expectedHandlersToBeCalled
|
|
113
|
+
if (assertion.expectedToBeCalled) {
|
|
114
|
+
const calledSteps = getCalledStepsBySingleEffect(effectName);
|
|
115
|
+
for (const expectedToBeCalled of assertion.expectedToBeCalled) {
|
|
116
|
+
const { handler, times } = expectedToBeCalled;
|
|
117
|
+
const calledStepsForHandler = calledSteps?.filter((step) => step.handler === handler);
|
|
118
|
+
if (times) {
|
|
119
|
+
if (calledStepsForHandler?.length !== times) {
|
|
120
|
+
assertionPassed = false;
|
|
121
|
+
testAssertionResult.errors?.push(`expectedToBeCalled: expected handler "${handler}" to be called ${times} times, received ${calledStepsForHandler?.length} times`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (!calledStepsForHandler?.length || calledStepsForHandler.length === 0) {
|
|
126
|
+
assertionPassed = false;
|
|
127
|
+
testAssertionResult.errors?.push(`expectedToBeCalled: expected handler "${handler}" to be called at least once`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
testAssertionResult.passed = assertionPassed;
|
|
133
|
+
if (!assertionPassed) {
|
|
134
|
+
testPassed = false;
|
|
135
|
+
}
|
|
136
|
+
testResult.assertions.push(testAssertionResult);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Event
|
|
141
|
+
*/
|
|
142
|
+
if ("event" in test) {
|
|
143
|
+
const eventName = test.event;
|
|
144
|
+
const assertions = test.assertions;
|
|
145
|
+
for (const assertion of assertions) {
|
|
146
|
+
// @TODO: apply matrix
|
|
147
|
+
if (cliOptions.assertionPattern &&
|
|
148
|
+
!assertion.description?.includes(cliOptions.assertionPattern)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
let assertionPassed = true;
|
|
152
|
+
const { e } = (0, createTestInstance_1.createTestInstance)({
|
|
153
|
+
datafile: datafileContent,
|
|
154
|
+
cliOptions,
|
|
155
|
+
withLookups: assertion.withLookups,
|
|
156
|
+
});
|
|
157
|
+
let trackedEvent = null;
|
|
158
|
+
if (assertion.track) {
|
|
159
|
+
trackedEvent = await e.trackAsync(eventName, assertion.track);
|
|
160
|
+
}
|
|
161
|
+
if (assertion.actions) {
|
|
162
|
+
for (const action of assertion.actions) {
|
|
163
|
+
if (action.type === "track") {
|
|
164
|
+
await e.trackAsync(action.name, action.value);
|
|
165
|
+
}
|
|
166
|
+
else if (action.type === "setAttribute") {
|
|
167
|
+
await e.setAttributeAsync(action.name, action.value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const testAssertionResult = {
|
|
172
|
+
passed: assertionPassed,
|
|
173
|
+
description: assertion.description,
|
|
174
|
+
errors: [],
|
|
175
|
+
};
|
|
176
|
+
// expectedToBeValid
|
|
177
|
+
if (typeof assertion.expectedToBeValid === "boolean") {
|
|
178
|
+
if ((assertion.expectedToBeValid === true && !trackedEvent) ||
|
|
179
|
+
(assertion.expectedToBeValid === false && trackedEvent)) {
|
|
180
|
+
assertionPassed = false;
|
|
181
|
+
testAssertionResult.errors?.push(`expectedToBeValid: expected ${assertion.expectedToBeValid}, received ${!assertion.expectedToBeValid}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// expectedToContinue
|
|
185
|
+
if (assertion.expectedToContinue) {
|
|
186
|
+
// @TODO: implement
|
|
187
|
+
}
|
|
188
|
+
// expectedEvent
|
|
189
|
+
if (assertion.expectedEvent) {
|
|
190
|
+
if (!checkIfObjectsAreDeepEqual(trackedEvent, assertion.expectedEvent)) {
|
|
191
|
+
assertionPassed = false;
|
|
192
|
+
testAssertionResult.errors?.push(`expectedEvent: \n expected: ${JSON.stringify(assertion.expectedEvent)}\n received: ${JSON.stringify(trackedEvent)}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// expectedDestinations
|
|
196
|
+
if (assertion.expectedDestinations) {
|
|
197
|
+
// if (!assertion.expectedDestinations.includes(m.getDestinationName())) {
|
|
198
|
+
// assertionPassed = false;
|
|
199
|
+
// testAssertionResult.errors?.push(
|
|
200
|
+
// `expectedDestinations: expected ${assertion.expectedDestinations.join(", ")}, received ${m.getDestinationName()}`,
|
|
201
|
+
// );
|
|
202
|
+
// }
|
|
203
|
+
}
|
|
204
|
+
// expectedDestinationsByTag
|
|
205
|
+
if (assertion.expectedDestinationsByTag) {
|
|
206
|
+
// @TODO: implement
|
|
207
|
+
}
|
|
208
|
+
testAssertionResult.passed = assertionPassed;
|
|
209
|
+
if (!assertionPassed) {
|
|
210
|
+
testPassed = false;
|
|
211
|
+
}
|
|
212
|
+
testResult.assertions.push(testAssertionResult);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Destination
|
|
217
|
+
*/
|
|
218
|
+
if ("destination" in test) {
|
|
219
|
+
const destinationName = test.destination;
|
|
220
|
+
const assertions = test.assertions;
|
|
221
|
+
for (const assertion of assertions) {
|
|
222
|
+
// @TODO: apply matrix
|
|
223
|
+
if (cliOptions.assertionPattern &&
|
|
224
|
+
!assertion.description?.includes(cliOptions.assertionPattern)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
let assertionPassed = true;
|
|
228
|
+
const { e, getBodiesBySingleDestination } = (0, createTestInstance_1.createTestInstance)({
|
|
229
|
+
datafile: datafileContent,
|
|
230
|
+
cliOptions,
|
|
231
|
+
withLookups: assertion.withLookups,
|
|
232
|
+
});
|
|
233
|
+
if (assertion.actions) {
|
|
234
|
+
for (const action of assertion.actions) {
|
|
235
|
+
if (action.type === "track") {
|
|
236
|
+
await e.trackAsync(action.name, action.value);
|
|
237
|
+
}
|
|
238
|
+
else if (action.type === "setAttribute") {
|
|
239
|
+
await e.setAttributeAsync(action.name, action.value);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const testAssertionResult = {
|
|
244
|
+
passed: assertionPassed,
|
|
245
|
+
description: assertion.description,
|
|
246
|
+
errors: [],
|
|
247
|
+
};
|
|
248
|
+
// expectedToBeTransported
|
|
249
|
+
if (typeof assertion.expectedToBeTransported === "boolean") {
|
|
250
|
+
const bodies = getBodiesBySingleDestination(destinationName);
|
|
251
|
+
if ((assertion.expectedToBeTransported === false && bodies && bodies.length > 0) ||
|
|
252
|
+
(assertion.expectedToBeTransported === true && (!bodies || bodies.length === 0))) {
|
|
253
|
+
assertionPassed = false;
|
|
254
|
+
testAssertionResult.errors?.push(`expectedToBeTransported: expected ${assertion.expectedToBeTransported}, received ${!assertion.expectedToBeTransported}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// expectedBody
|
|
258
|
+
if (assertion.expectedBody) {
|
|
259
|
+
const bodies = getBodiesBySingleDestination(destinationName);
|
|
260
|
+
if (!checkIfObjectsAreDeepEqual(bodies && bodies[0], assertion.expectedBody)) {
|
|
261
|
+
assertionPassed = false;
|
|
262
|
+
testAssertionResult.errors?.push(`expectedBody: \n expected: ${JSON.stringify(assertion.expectedBody, null, 2)}\n received: ${JSON.stringify(bodies && bodies[0], null, 2)}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// @TODO: expectedBodies
|
|
266
|
+
testAssertionResult.passed = assertionPassed;
|
|
267
|
+
if (!assertionPassed) {
|
|
268
|
+
testPassed = false;
|
|
269
|
+
}
|
|
270
|
+
testResult.assertions.push(testAssertionResult);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
testResult.passed = testPassed;
|
|
274
|
+
return testResult;
|
|
275
|
+
}
|
|
276
|
+
function checkIfObjectsAreDeepEqual(a, b) {
|
|
277
|
+
// Handle null/undefined cases
|
|
278
|
+
if (a === null || b === null || a === undefined || b === undefined) {
|
|
279
|
+
return a === b;
|
|
280
|
+
}
|
|
281
|
+
// Handle primitive types
|
|
282
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
283
|
+
return a === b;
|
|
284
|
+
}
|
|
285
|
+
// Handle arrays
|
|
286
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
287
|
+
if (a.length !== b.length) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
return a.every((item, index) => checkIfObjectsAreDeepEqual(item, b[index]));
|
|
291
|
+
}
|
|
292
|
+
// Handle objects
|
|
293
|
+
const aKeys = Object.keys(a);
|
|
294
|
+
const bKeys = Object.keys(b);
|
|
295
|
+
if (aKeys.length !== bKeys.length) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return aKeys.every((key) => {
|
|
299
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
return checkIfObjectsAreDeepEqual(a[key], b[key]);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=executeTest.js.map
|