@featurevisor/core 3.1.0 → 3.2.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/lib/datasource/datasource.d.ts +1 -1
- package/lib/datasource/datasource.js +4 -14
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/requiredFeatures.d.ts +7 -0
- package/lib/datasource/requiredFeatures.js +38 -0
- package/lib/datasource/requiredFeatures.js.map +1 -0
- package/lib/linter/checkCircularDependency.d.ts +1 -1
- package/lib/linter/checkCircularDependency.js +3 -22
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/conditionSchema.js +27 -3
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2246
- package/coverage/clover.xml +0 -5456
- package/coverage/coverage-final.json +0 -64
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -371
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
- package/coverage/lcov-report/src/benchmark/index.html +0 -116
- package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
- package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
- package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
- package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
- package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
- package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
- package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
- package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
- package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
- package/coverage/lcov-report/src/builder/index.html +0 -311
- package/coverage/lcov-report/src/builder/index.ts.html +0 -91
- package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
- package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
- package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
- package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
- package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
- package/coverage/lcov-report/src/cli/index.html +0 -131
- package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
- package/coverage/lcov-report/src/config/index.html +0 -131
- package/coverage/lcov-report/src/config/index.ts.html +0 -88
- package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
- package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
- package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
- package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
- package/coverage/lcov-report/src/datasource/index.html +0 -161
- package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
- package/coverage/lcov-report/src/evaluate/index.html +0 -116
- package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
- package/coverage/lcov-report/src/find-usage/index.html +0 -116
- package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
- package/coverage/lcov-report/src/generate-code/index.html +0 -131
- package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
- package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/info/index.html +0 -116
- package/coverage/lcov-report/src/info/index.ts.html +0 -472
- package/coverage/lcov-report/src/init/index.html +0 -116
- package/coverage/lcov-report/src/init/index.ts.html +0 -280
- package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
- package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
- package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
- package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
- package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
- package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
- package/coverage/lcov-report/src/linter/index.html +0 -326
- package/coverage/lcov-report/src/linter/index.ts.html +0 -88
- package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
- package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
- package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
- package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
- package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
- package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
- package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
- package/coverage/lcov-report/src/list/index.html +0 -131
- package/coverage/lcov-report/src/list/index.ts.html +0 -2065
- package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
- package/coverage/lcov-report/src/promoter/index.html +0 -116
- package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
- package/coverage/lcov-report/src/sets.ts.html +0 -313
- package/coverage/lcov-report/src/targeting.ts.html +0 -403
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
- package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
- package/coverage/lcov-report/src/tester/index.html +0 -206
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
- package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
- package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
- package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
- package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
- package/coverage/lcov-report/src/utils/git.ts.html +0 -559
- package/coverage/lcov-report/src/utils/index.html +0 -161
- package/coverage/lcov-report/src/utils/index.ts.html +0 -94
- package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
- package/coverage/lcov.info +0 -11615
- package/jest.config.js +0 -22
- package/json-schema/README.md +0 -5
- package/json-schema/attribute.json +0 -40
- package/json-schema/feature.json +0 -394
- package/json-schema/segment.json +0 -137
- package/src/assess-distribution/index.ts +0 -223
- package/src/benchmark/index.ts +0 -236
- package/src/builder/allocator.spec.ts +0 -105
- package/src/builder/allocator.ts +0 -45
- package/src/builder/applyContextToConditions.spec.ts +0 -2677
- package/src/builder/applyContextToConditions.ts +0 -139
- package/src/builder/applyContextToDatafile.spec.ts +0 -2626
- package/src/builder/applyContextToDatafile.ts +0 -229
- package/src/builder/applyContextToSegments.spec.ts +0 -1593
- package/src/builder/applyContextToSegments.ts +0 -165
- package/src/builder/buildDatafile.spec.ts +0 -445
- package/src/builder/buildDatafile.ts +0 -656
- package/src/builder/buildProject.ts +0 -344
- package/src/builder/buildRuntimeDatafiles.ts +0 -57
- package/src/builder/getFeatureRanges.ts +0 -61
- package/src/builder/hashes.ts +0 -109
- package/src/builder/index.ts +0 -2
- package/src/builder/mutateVariables.spec.ts +0 -1179
- package/src/builder/mutateVariables.ts +0 -112
- package/src/builder/mutator.spec.ts +0 -413
- package/src/builder/mutator.ts +0 -237
- package/src/builder/revision.spec.ts +0 -22
- package/src/builder/revision.ts +0 -22
- package/src/builder/traffic.spec.ts +0 -946
- package/src/builder/traffic.ts +0 -192
- package/src/cli/cli.ts +0 -105
- package/src/cli/index.ts +0 -2
- package/src/cli/plugins.ts +0 -43
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.spec.ts +0 -194
- package/src/config/projectConfig.ts +0 -280
- package/src/datasource/adapter.ts +0 -56
- package/src/datasource/datasource.ts +0 -305
- package/src/datasource/filesystemAdapter.spec.ts +0 -212
- package/src/datasource/filesystemAdapter.ts +0 -497
- package/src/datasource/index.ts +0 -3
- package/src/dependencies.ts +0 -13
- package/src/evaluate/index.ts +0 -243
- package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
- package/src/find-duplicate-segments/index.ts +0 -74
- package/src/find-usage/index.ts +0 -565
- package/src/generate-code/index.ts +0 -106
- package/src/generate-code/typescript.spec.ts +0 -214
- package/src/generate-code/typescript.ts +0 -608
- package/src/index.ts +0 -20
- package/src/info/index.ts +0 -129
- package/src/init/index.ts +0 -65
- package/src/linter/attributeSchema.spec.ts +0 -342
- package/src/linter/attributeSchema.ts +0 -626
- package/src/linter/checkCircularDependency.ts +0 -45
- package/src/linter/checkPercentageExceedingSlot.ts +0 -61
- package/src/linter/conditionSchema.spec.ts +0 -510
- package/src/linter/conditionSchema.ts +0 -713
- package/src/linter/featureSchema.spec.ts +0 -1985
- package/src/linter/featureSchema.ts +0 -1922
- package/src/linter/groupSchema.ts +0 -47
- package/src/linter/index.ts +0 -1
- package/src/linter/lintProject.spec.ts +0 -336
- package/src/linter/lintProject.ts +0 -873
- package/src/linter/mutationNotation.spec.ts +0 -704
- package/src/linter/mutationNotation.ts +0 -442
- package/src/linter/printError.ts +0 -68
- package/src/linter/schema.spec.ts +0 -690
- package/src/linter/schema.ts +0 -491
- package/src/linter/segmentSchema.spec.ts +0 -358
- package/src/linter/segmentSchema.ts +0 -18
- package/src/linter/targetSchema.spec.ts +0 -159
- package/src/linter/targetSchema.ts +0 -46
- package/src/linter/testSchema.spec.ts +0 -258
- package/src/linter/testSchema.ts +0 -148
- package/src/linter/zodHelpers.ts +0 -16
- package/src/list/index.spec.ts +0 -135
- package/src/list/index.ts +0 -660
- package/src/list/matrix.spec.ts +0 -49
- package/src/list/matrix.ts +0 -212
- package/src/promoter/index.spec.ts +0 -617
- package/src/promoter/index.ts +0 -1266
- package/src/sets.ts +0 -76
- package/src/targeting.spec.ts +0 -74
- package/src/targeting.ts +0 -106
- package/src/tester/cliFormat.ts +0 -16
- package/src/tester/helpers.spec.ts +0 -149
- package/src/tester/helpers.ts +0 -76
- package/src/tester/index.ts +0 -2
- package/src/tester/prettyDuration.ts +0 -34
- package/src/tester/printTestResult.ts +0 -84
- package/src/tester/testFeature.ts +0 -367
- package/src/tester/testProject.spec.ts +0 -50
- package/src/tester/testProject.ts +0 -311
- package/src/tester/testSegment.ts +0 -77
- package/src/utils/extractKeys.ts +0 -136
- package/src/utils/git.ts +0 -158
- package/src/utils/index.ts +0 -3
- package/src/utils/pretty.ts +0 -12
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.typecheck.json +0 -9
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DatafileContent,
|
|
3
|
-
TestFeature,
|
|
4
|
-
TestResult,
|
|
5
|
-
TestResultAssertion,
|
|
6
|
-
TestResultAssertionError,
|
|
7
|
-
} from "@featurevisor/types";
|
|
8
|
-
import { createFeaturevisor } from "@featurevisor/sdk";
|
|
9
|
-
import type { Featurevisor, FeaturevisorLogLevel, OverrideOptions } from "@featurevisor/sdk";
|
|
10
|
-
import { MAX_BUCKETED_NUMBER } from "@featurevisor/sdk";
|
|
11
|
-
|
|
12
|
-
import { Datasource } from "../datasource";
|
|
13
|
-
import { ProjectConfig } from "../config";
|
|
14
|
-
|
|
15
|
-
import { checkIfArraysAreEqual, checkIfObjectsAreEqual } from "./helpers";
|
|
16
|
-
import type { DatafileContentByKey } from "./testProject";
|
|
17
|
-
|
|
18
|
-
export interface TestFeatureOptions {
|
|
19
|
-
verbose?: boolean;
|
|
20
|
-
quiet?: boolean;
|
|
21
|
-
showDatafile?: boolean;
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function testFeature(
|
|
26
|
-
datasource: Datasource,
|
|
27
|
-
projectConfig: ProjectConfig,
|
|
28
|
-
test: TestFeature,
|
|
29
|
-
options: TestFeatureOptions = {},
|
|
30
|
-
datafileContentByKey: DatafileContentByKey,
|
|
31
|
-
): Promise<TestResult> {
|
|
32
|
-
const testStartTime = Date.now();
|
|
33
|
-
const featureKey = test.feature;
|
|
34
|
-
|
|
35
|
-
const testResult: TestResult = {
|
|
36
|
-
type: "feature",
|
|
37
|
-
key: featureKey,
|
|
38
|
-
|
|
39
|
-
// to be updated later
|
|
40
|
-
notFound: false,
|
|
41
|
-
duration: 0,
|
|
42
|
-
passed: true,
|
|
43
|
-
assertions: [],
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
for (let aIndex = 0; aIndex < test.assertions.length; aIndex++) {
|
|
47
|
-
const assertionStartTime = Date.now();
|
|
48
|
-
const assertion = test.assertions[aIndex];
|
|
49
|
-
|
|
50
|
-
const testResultAssertion: TestResultAssertion = {
|
|
51
|
-
description: assertion.description as string,
|
|
52
|
-
duration: 0,
|
|
53
|
-
passed: true,
|
|
54
|
-
errors: [],
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
let datafileContent = datafileContentByKey.get(assertion.environment || false);
|
|
58
|
-
|
|
59
|
-
// target
|
|
60
|
-
const targetDatafileKey = `${assertion.environment || false}-target-${assertion.target}`;
|
|
61
|
-
if (assertion.target && datafileContentByKey.has(targetDatafileKey)) {
|
|
62
|
-
datafileContent = datafileContentByKey.get(targetDatafileKey);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (options.showDatafile) {
|
|
66
|
-
console.log("");
|
|
67
|
-
console.log(JSON.stringify(datafileContent, null, 2));
|
|
68
|
-
console.log("");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let logLevel: FeaturevisorLogLevel = "warn";
|
|
72
|
-
if (options.verbose) {
|
|
73
|
-
logLevel = "debug";
|
|
74
|
-
} else if (options.quiet) {
|
|
75
|
-
logLevel = "fatal";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const sdk: Featurevisor = createFeaturevisor({
|
|
79
|
-
datafile: datafileContent as DatafileContent,
|
|
80
|
-
sticky: assertion.sticky ? assertion.sticky : {},
|
|
81
|
-
modules: [
|
|
82
|
-
{
|
|
83
|
-
name: "tester",
|
|
84
|
-
bucketValue: ({ bucketValue }) => {
|
|
85
|
-
if (typeof assertion.at !== "undefined") {
|
|
86
|
-
return assertion.at * (MAX_BUCKETED_NUMBER / 100);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return bucketValue;
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
logLevel,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const parsedFeature = await datasource.readFeature(featureKey);
|
|
97
|
-
if (!parsedFeature) {
|
|
98
|
-
testResult.notFound = true;
|
|
99
|
-
testResult.passed = false;
|
|
100
|
-
|
|
101
|
-
return testResult;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let context = {};
|
|
105
|
-
|
|
106
|
-
if (assertion.context) {
|
|
107
|
-
context = {
|
|
108
|
-
...context,
|
|
109
|
-
...assertion.context,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (context) {
|
|
114
|
-
sdk.setContext(context);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* expectedToBeEnabled
|
|
119
|
-
*/
|
|
120
|
-
function testExpectedToBeEnabled(sdk, assertion, details = {}) {
|
|
121
|
-
const isEnabled = sdk.isEnabled(featureKey, context);
|
|
122
|
-
|
|
123
|
-
if (isEnabled !== assertion.expectedToBeEnabled) {
|
|
124
|
-
testResult.passed = false;
|
|
125
|
-
testResultAssertion.passed = false;
|
|
126
|
-
|
|
127
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
128
|
-
type: "flag",
|
|
129
|
-
expected: assertion.expectedToBeEnabled,
|
|
130
|
-
actual: isEnabled,
|
|
131
|
-
details,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if ("expectedToBeEnabled" in assertion) {
|
|
137
|
-
testExpectedToBeEnabled(sdk, assertion);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* expectedVariation
|
|
142
|
-
*/
|
|
143
|
-
function testExpectedVariation(sdk, assertion, details = {}) {
|
|
144
|
-
const overrideOptions: OverrideOptions = {};
|
|
145
|
-
if (assertion.defaultVariationValue) {
|
|
146
|
-
overrideOptions.defaultVariationValue = assertion.defaultVariationValue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const variation = sdk.getVariation(featureKey, context, overrideOptions);
|
|
150
|
-
|
|
151
|
-
if (variation !== assertion.expectedVariation) {
|
|
152
|
-
testResult.passed = false;
|
|
153
|
-
testResultAssertion.passed = false;
|
|
154
|
-
|
|
155
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
156
|
-
type: "variation",
|
|
157
|
-
expected: assertion.expectedVariation,
|
|
158
|
-
actual: variation,
|
|
159
|
-
details,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if ("expectedVariation" in assertion) {
|
|
165
|
-
testExpectedVariation(sdk, assertion);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* expectedVariables
|
|
170
|
-
*/
|
|
171
|
-
function testExpectedVariables(sdk, assertion, details = {}) {
|
|
172
|
-
Object.keys(assertion.expectedVariables).forEach(function (variableKey) {
|
|
173
|
-
const expectedValue =
|
|
174
|
-
assertion.expectedVariables && assertion.expectedVariables[variableKey];
|
|
175
|
-
|
|
176
|
-
const overrideOptions: OverrideOptions = {};
|
|
177
|
-
if (assertion.defaultVariableValues && assertion.defaultVariableValues[variableKey]) {
|
|
178
|
-
overrideOptions.defaultVariableValue = assertion.defaultVariableValues[variableKey];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const actualValue = sdk.getVariable(featureKey, variableKey, context, overrideOptions);
|
|
182
|
-
|
|
183
|
-
let passed;
|
|
184
|
-
|
|
185
|
-
// Use feature from datafile so variable schema is always resolved (ResolvedVariableSchema)
|
|
186
|
-
const featureFromDatafile = datafileContent?.features?.[featureKey];
|
|
187
|
-
const variableSchema = featureFromDatafile?.variablesSchema?.[variableKey];
|
|
188
|
-
|
|
189
|
-
if (!variableSchema) {
|
|
190
|
-
testResult.passed = false;
|
|
191
|
-
testResultAssertion.passed = false;
|
|
192
|
-
|
|
193
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
194
|
-
type: "variable",
|
|
195
|
-
expected: assertion.expectedVariation,
|
|
196
|
-
actual: undefined,
|
|
197
|
-
message: `schema for variable "${variableKey}" not found in feature`,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (variableSchema.type === "json") {
|
|
204
|
-
// JSON type
|
|
205
|
-
const parsedExpectedValue =
|
|
206
|
-
typeof expectedValue === "string" ? JSON.parse(expectedValue as string) : expectedValue;
|
|
207
|
-
|
|
208
|
-
if (Array.isArray(actualValue)) {
|
|
209
|
-
passed = checkIfArraysAreEqual(parsedExpectedValue, actualValue);
|
|
210
|
-
} else if (typeof actualValue === "object") {
|
|
211
|
-
passed = checkIfObjectsAreEqual(parsedExpectedValue, actualValue);
|
|
212
|
-
} else {
|
|
213
|
-
passed = JSON.stringify(parsedExpectedValue) === JSON.stringify(actualValue);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (!passed) {
|
|
217
|
-
testResult.passed = false;
|
|
218
|
-
testResultAssertion.passed = false;
|
|
219
|
-
|
|
220
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
221
|
-
type: "variable",
|
|
222
|
-
expected:
|
|
223
|
-
typeof expectedValue !== "string" ? JSON.stringify(expectedValue) : expectedValue,
|
|
224
|
-
actual: typeof actualValue !== "string" ? JSON.stringify(actualValue) : actualValue,
|
|
225
|
-
details: {
|
|
226
|
-
...details,
|
|
227
|
-
variableKey,
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
// other types
|
|
233
|
-
if (typeof expectedValue === "object") {
|
|
234
|
-
passed = checkIfObjectsAreEqual(expectedValue, actualValue);
|
|
235
|
-
} else if (Array.isArray(expectedValue)) {
|
|
236
|
-
passed = checkIfArraysAreEqual(expectedValue, actualValue);
|
|
237
|
-
} else {
|
|
238
|
-
passed = expectedValue === actualValue;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (!passed) {
|
|
242
|
-
testResult.passed = false;
|
|
243
|
-
testResultAssertion.passed = false;
|
|
244
|
-
|
|
245
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
246
|
-
type: "variable",
|
|
247
|
-
expected: expectedValue as string,
|
|
248
|
-
actual: actualValue as string,
|
|
249
|
-
details: {
|
|
250
|
-
...details,
|
|
251
|
-
variableKey,
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (typeof assertion.expectedVariables === "object") {
|
|
260
|
-
testExpectedVariables(sdk, assertion);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* expectedEvaluations
|
|
265
|
-
*/
|
|
266
|
-
function testExpectedEvaluations(sdk, assertion, rootDetails = {}) {
|
|
267
|
-
function testEvaluation(type, evaluation, expected, details = {}) {
|
|
268
|
-
for (const [key, value] of Object.entries(expected)) {
|
|
269
|
-
if (evaluation[key] !== value) {
|
|
270
|
-
testResult.passed = false;
|
|
271
|
-
testResultAssertion.passed = false;
|
|
272
|
-
|
|
273
|
-
(testResultAssertion.errors as TestResultAssertionError[]).push({
|
|
274
|
-
type: "evaluation",
|
|
275
|
-
expected: value as string | number | boolean | null | undefined,
|
|
276
|
-
actual: evaluation[key],
|
|
277
|
-
details: {
|
|
278
|
-
...rootDetails,
|
|
279
|
-
...details,
|
|
280
|
-
evaluationType: type,
|
|
281
|
-
evaluationKey: key,
|
|
282
|
-
},
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (assertion.expectedEvaluations.flag) {
|
|
289
|
-
const evaluation = sdk.evaluateFlag(featureKey, context);
|
|
290
|
-
testEvaluation("flag", evaluation, assertion.expectedEvaluations.flag);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (assertion.expectedEvaluations.variation) {
|
|
294
|
-
const evaluation = sdk.evaluateVariation(featureKey, context);
|
|
295
|
-
testEvaluation("variation", evaluation, assertion.expectedEvaluations.variation);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (assertion.expectedEvaluations.variables) {
|
|
299
|
-
const variableKeys = Object.keys(assertion.expectedEvaluations.variables);
|
|
300
|
-
|
|
301
|
-
for (const variableKey of variableKeys) {
|
|
302
|
-
const evaluation = sdk.evaluateVariable(featureKey, variableKey, context);
|
|
303
|
-
testEvaluation(
|
|
304
|
-
"variable",
|
|
305
|
-
evaluation,
|
|
306
|
-
assertion.expectedEvaluations.variables[variableKey],
|
|
307
|
-
{ variableKey },
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (assertion.expectedEvaluations) {
|
|
314
|
-
testExpectedEvaluations(sdk, assertion);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* children
|
|
319
|
-
*/
|
|
320
|
-
if (Array.isArray(assertion.children)) {
|
|
321
|
-
let childIndex = 0;
|
|
322
|
-
|
|
323
|
-
for (const child of assertion.children) {
|
|
324
|
-
const childSdk = sdk.spawn(child.context || {}, {
|
|
325
|
-
sticky: assertion.sticky || {},
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
// expectedToBeEnabled
|
|
329
|
-
if (typeof child.expectedToBeEnabled !== "undefined") {
|
|
330
|
-
testExpectedToBeEnabled(childSdk, child, {
|
|
331
|
-
childIndex,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// expectedVariation
|
|
336
|
-
if (typeof child.expectedVariation !== "undefined") {
|
|
337
|
-
testExpectedVariation(childSdk, child, {
|
|
338
|
-
childIndex,
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// expectedVariables
|
|
343
|
-
if (typeof child.expectedVariables === "object") {
|
|
344
|
-
testExpectedVariables(childSdk, child, {
|
|
345
|
-
childIndex,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// expectedEvaluations
|
|
350
|
-
if (typeof child.expectedEvaluations === "object") {
|
|
351
|
-
testExpectedEvaluations(childSdk, child, {
|
|
352
|
-
childIndex,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
childIndex++;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
testResultAssertion.duration = Date.now() - assertionStartTime;
|
|
361
|
-
testResult.assertions.push(testResultAssertion);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
testResult.duration = Date.now() - testStartTime;
|
|
365
|
-
|
|
366
|
-
return testResult;
|
|
367
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Test, TestFeature } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
import { filterTestForTargets } from "./testProject";
|
|
4
|
-
|
|
5
|
-
describe("core: test target selection", () => {
|
|
6
|
-
const featureTest = {
|
|
7
|
-
key: "checkout",
|
|
8
|
-
feature: "checkout",
|
|
9
|
-
assertions: [
|
|
10
|
-
{ description: "base", context: {}, expectedToBeEnabled: true },
|
|
11
|
-
{ description: "web", target: "web", context: {}, expectedToBeEnabled: true },
|
|
12
|
-
{ description: "mobile", target: "mobile", context: {}, expectedToBeEnabled: true },
|
|
13
|
-
],
|
|
14
|
-
} as TestFeature;
|
|
15
|
-
|
|
16
|
-
it("keeps untargeted assertions and assertions for all selected targets", () => {
|
|
17
|
-
const filtered = filterTestForTargets(featureTest, ["web", "mobile"]) as TestFeature;
|
|
18
|
-
|
|
19
|
-
expect(filtered.assertions.map((assertion) => assertion.description)).toEqual([
|
|
20
|
-
"base",
|
|
21
|
-
"web",
|
|
22
|
-
"mobile",
|
|
23
|
-
]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("removes assertions for targets that were not selected", () => {
|
|
27
|
-
const filtered = filterTestForTargets(featureTest, ["web"]) as TestFeature;
|
|
28
|
-
|
|
29
|
-
expect(filtered.assertions.map((assertion) => assertion.description)).toEqual(["base", "web"]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("skips a feature test when none of its targeted assertions were selected", () => {
|
|
33
|
-
const targetedOnly = {
|
|
34
|
-
...featureTest,
|
|
35
|
-
assertions: featureTest.assertions.slice(1),
|
|
36
|
-
} as TestFeature;
|
|
37
|
-
|
|
38
|
-
expect(filterTestForTargets(targetedOnly, ["api"])).toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("does not filter segment tests", () => {
|
|
42
|
-
const segmentTest = {
|
|
43
|
-
key: "everyone",
|
|
44
|
-
segment: "everyone",
|
|
45
|
-
assertions: [],
|
|
46
|
-
} as unknown as Test;
|
|
47
|
-
|
|
48
|
-
expect(filterTestForTargets(segmentTest, ["web"])).toBe(segmentTest);
|
|
49
|
-
});
|
|
50
|
-
});
|