@featurevisor/core 3.1.0 → 3.3.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/linter/testSchema.d.ts +4 -0
- package/lib/linter/testSchema.js +46 -4
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/promoter/index.js +62 -1
- package/lib/promoter/index.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,258 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
import type { ProjectConfig } from "../config";
|
|
4
|
-
import { getLintIssuesFromZodError } from "./printError";
|
|
5
|
-
import { getTestsZodSchema } from "./testSchema";
|
|
6
|
-
|
|
7
|
-
function minimalProjectConfig(overrides: Partial<ProjectConfig> = {}): ProjectConfig {
|
|
8
|
-
return {
|
|
9
|
-
featuresDirectoryPath: "",
|
|
10
|
-
segmentsDirectoryPath: "",
|
|
11
|
-
attributesDirectoryPath: "",
|
|
12
|
-
groupsDirectoryPath: "",
|
|
13
|
-
schemasDirectoryPath: "",
|
|
14
|
-
targetsDirectoryPath: "",
|
|
15
|
-
testsDirectoryPath: "",
|
|
16
|
-
stateDirectoryPath: "",
|
|
17
|
-
datafilesDirectoryPath: "",
|
|
18
|
-
datafileNamePattern: "",
|
|
19
|
-
revisionFileName: "",
|
|
20
|
-
catalogDirectoryPath: "",
|
|
21
|
-
setsDirectoryPath: "",
|
|
22
|
-
environments: ["staging", "production"],
|
|
23
|
-
sets: false,
|
|
24
|
-
namespaceCharacter: ".",
|
|
25
|
-
tags: ["all", "beta"],
|
|
26
|
-
adapter: {},
|
|
27
|
-
plugins: [],
|
|
28
|
-
defaultBucketBy: "userId",
|
|
29
|
-
parser: "yml",
|
|
30
|
-
prettyState: true,
|
|
31
|
-
prettyDatafile: false,
|
|
32
|
-
stringify: true,
|
|
33
|
-
...overrides,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getSchema(projectConfig = minimalProjectConfig()) {
|
|
38
|
-
return getTestsZodSchema(projectConfig, ["checkout"], ["desktop"], ["web"]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function parseTest(input: unknown): z.ZodSafeParseResult<unknown> {
|
|
42
|
-
return getSchema().safeParse(input);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function expectTestSuccess(input: unknown): void {
|
|
46
|
-
const result = parseTest(input);
|
|
47
|
-
expect(result.success).toBe(true);
|
|
48
|
-
if (!result.success) {
|
|
49
|
-
const error = (result as z.ZodSafeParseError<unknown>).error;
|
|
50
|
-
throw new Error(error.issues.map((issue) => issue.message).join("; "));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function expectTestFailure(input: unknown, messageSubstring: string): z.ZodError {
|
|
55
|
-
const result = parseTest(input);
|
|
56
|
-
expect(result.success).toBe(false);
|
|
57
|
-
if (result.success) {
|
|
58
|
-
throw new Error("Expected test schema to fail");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const error = (result as z.ZodSafeParseError<unknown>).error;
|
|
62
|
-
expect(error.issues.map((issue) => issue.message).join(" ")).toContain(messageSubstring);
|
|
63
|
-
|
|
64
|
-
return error;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
describe("testSchema.ts :: getTestsZodSchema", () => {
|
|
68
|
-
it("accepts a valid feature test with matrix, context, sticky, and expected evaluations", () => {
|
|
69
|
-
expectTestSuccess({
|
|
70
|
-
feature: "checkout",
|
|
71
|
-
assertions: [
|
|
72
|
-
{
|
|
73
|
-
matrix: {
|
|
74
|
-
country: ["nl", "de"],
|
|
75
|
-
loggedIn: [true, false],
|
|
76
|
-
score: [1, 2],
|
|
77
|
-
empty: [null],
|
|
78
|
-
},
|
|
79
|
-
description: "feature assertion",
|
|
80
|
-
at: "${{ score }}",
|
|
81
|
-
environment: "staging",
|
|
82
|
-
target: "web",
|
|
83
|
-
sticky: {
|
|
84
|
-
flag: { checkout: "cached" },
|
|
85
|
-
},
|
|
86
|
-
context: {
|
|
87
|
-
userId: "user-1",
|
|
88
|
-
},
|
|
89
|
-
defaultVariableValues: {
|
|
90
|
-
title: "Fallback",
|
|
91
|
-
},
|
|
92
|
-
expectedToBeEnabled: true,
|
|
93
|
-
expectedVariation: "control",
|
|
94
|
-
expectedVariables: {
|
|
95
|
-
title: "Checkout",
|
|
96
|
-
},
|
|
97
|
-
expectedEvaluations: {
|
|
98
|
-
flag: { reason: "rule" },
|
|
99
|
-
variation: { reason: "bucketed" },
|
|
100
|
-
variables: { title: { reason: "default" } },
|
|
101
|
-
},
|
|
102
|
-
children: [
|
|
103
|
-
{
|
|
104
|
-
context: {
|
|
105
|
-
userId: "child-1",
|
|
106
|
-
},
|
|
107
|
-
expectedToBeEnabled: false,
|
|
108
|
-
expectedVariation: null,
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("accepts matrix placeholders for environment values", () => {
|
|
117
|
-
expectTestSuccess({
|
|
118
|
-
feature: "checkout",
|
|
119
|
-
assertions: [
|
|
120
|
-
{
|
|
121
|
-
matrix: {
|
|
122
|
-
environment: ["staging", "production"],
|
|
123
|
-
},
|
|
124
|
-
at: 1,
|
|
125
|
-
environment: "${{ environment }}",
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("accepts matrix placeholders for target values", () => {
|
|
132
|
-
expectTestSuccess({
|
|
133
|
-
feature: "checkout",
|
|
134
|
-
assertions: [
|
|
135
|
-
{
|
|
136
|
-
matrix: {
|
|
137
|
-
target: ["web", "mobile"],
|
|
138
|
-
},
|
|
139
|
-
at: 1,
|
|
140
|
-
environment: "staging",
|
|
141
|
-
target: "${{ target }}",
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("rejects unknown targets", () => {
|
|
148
|
-
expectTestFailure(
|
|
149
|
-
{
|
|
150
|
-
feature: "checkout",
|
|
151
|
-
assertions: [
|
|
152
|
-
{
|
|
153
|
-
at: 1,
|
|
154
|
-
environment: "staging",
|
|
155
|
-
target: "mobile",
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
'Unknown target "mobile"',
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("rejects unknown environments with a precise path", () => {
|
|
164
|
-
const error = expectTestFailure(
|
|
165
|
-
{
|
|
166
|
-
feature: "checkout",
|
|
167
|
-
assertions: [
|
|
168
|
-
{
|
|
169
|
-
at: 1,
|
|
170
|
-
environment: "qa",
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
'Unknown environment "qa"',
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
expect(error.issues.some((issue) => issue.path.join(".") === "assertions.0.environment")).toBe(
|
|
178
|
-
true,
|
|
179
|
-
);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("rejects environment in assertions when environments are omitted", () => {
|
|
183
|
-
const schema = getSchema(minimalProjectConfig({ environments: undefined }));
|
|
184
|
-
const testSpec = {
|
|
185
|
-
feature: "checkout",
|
|
186
|
-
assertions: [
|
|
187
|
-
{
|
|
188
|
-
at: 1,
|
|
189
|
-
expectedToBeEnabled: true,
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
expect(schema.safeParse(testSpec).success).toBe(true);
|
|
195
|
-
|
|
196
|
-
const result = schema.safeParse({
|
|
197
|
-
feature: "checkout",
|
|
198
|
-
assertions: [
|
|
199
|
-
{
|
|
200
|
-
at: 1,
|
|
201
|
-
environment: "staging",
|
|
202
|
-
expectedToBeEnabled: true,
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
expect(result.success).toBe(false);
|
|
208
|
-
if (!result.success) {
|
|
209
|
-
expect(result.error.issues.length).toBeGreaterThan(0);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it("rejects unknown feature and segment keys", () => {
|
|
214
|
-
expectTestFailure(
|
|
215
|
-
{
|
|
216
|
-
feature: "not-real",
|
|
217
|
-
assertions: [{ at: 1, environment: "staging" }],
|
|
218
|
-
},
|
|
219
|
-
'Unknown feature "not-real"',
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
expectTestFailure(
|
|
223
|
-
{
|
|
224
|
-
segment: "not-real",
|
|
225
|
-
assertions: [
|
|
226
|
-
{
|
|
227
|
-
context: {},
|
|
228
|
-
expectedToMatch: true,
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
},
|
|
232
|
-
'Unknown segment "not-real"',
|
|
233
|
-
);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("rejects invalid matrix values", () => {
|
|
237
|
-
const error = expectTestFailure(
|
|
238
|
-
{
|
|
239
|
-
feature: "checkout",
|
|
240
|
-
assertions: [
|
|
241
|
-
{
|
|
242
|
-
matrix: {
|
|
243
|
-
country: [{ code: "nl" }],
|
|
244
|
-
},
|
|
245
|
-
at: 1,
|
|
246
|
-
environment: "staging",
|
|
247
|
-
},
|
|
248
|
-
],
|
|
249
|
-
},
|
|
250
|
-
"Invalid input",
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
const lintIssues = getLintIssuesFromZodError(error);
|
|
254
|
-
expect(lintIssues.some((issue) => issue.path.join(".").includes("matrix.country.0"))).toBe(
|
|
255
|
-
true,
|
|
256
|
-
);
|
|
257
|
-
});
|
|
258
|
-
});
|
package/src/linter/testSchema.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
import { ProjectConfig } from "../config";
|
|
4
|
-
import { refineWithMessage } from "./zodHelpers";
|
|
5
|
-
|
|
6
|
-
export function getTestsZodSchema(
|
|
7
|
-
projectConfig: ProjectConfig,
|
|
8
|
-
availableFeatureKeys: [string, ...string[]],
|
|
9
|
-
availableSegmentKeys: [string, ...string[]],
|
|
10
|
-
availableTargetKeys: [string, ...string[]],
|
|
11
|
-
) {
|
|
12
|
-
const matrixZodSchema = z.record(
|
|
13
|
-
z.string(),
|
|
14
|
-
z.array(
|
|
15
|
-
z.union([
|
|
16
|
-
// allowed values in arrays
|
|
17
|
-
z.string(),
|
|
18
|
-
z.number(),
|
|
19
|
-
z.boolean(),
|
|
20
|
-
z.null(),
|
|
21
|
-
]),
|
|
22
|
-
),
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const segmentTestZodSchema = z
|
|
26
|
-
.object({
|
|
27
|
-
promotable: z.boolean().optional(),
|
|
28
|
-
segment: refineWithMessage(
|
|
29
|
-
z.string(),
|
|
30
|
-
(value) => availableSegmentKeys.includes(value),
|
|
31
|
-
(value) => `Unknown segment "${value}"`,
|
|
32
|
-
),
|
|
33
|
-
assertions: z.array(
|
|
34
|
-
z
|
|
35
|
-
.object({
|
|
36
|
-
matrix: matrixZodSchema.optional(),
|
|
37
|
-
description: z.string().optional(),
|
|
38
|
-
context: z.record(z.string(), z.unknown()),
|
|
39
|
-
expectedToMatch: z.boolean(),
|
|
40
|
-
})
|
|
41
|
-
.strict(),
|
|
42
|
-
),
|
|
43
|
-
})
|
|
44
|
-
.strict();
|
|
45
|
-
|
|
46
|
-
const featureTestZodSchema = z
|
|
47
|
-
.object({
|
|
48
|
-
promotable: z.boolean().optional(),
|
|
49
|
-
feature: refineWithMessage(
|
|
50
|
-
z.string(),
|
|
51
|
-
(value) => availableFeatureKeys.includes(value),
|
|
52
|
-
(value) => `Unknown feature "${value}"`,
|
|
53
|
-
),
|
|
54
|
-
assertions: z.array(
|
|
55
|
-
z
|
|
56
|
-
.object({
|
|
57
|
-
matrix: matrixZodSchema.optional(),
|
|
58
|
-
description: z.string().optional(),
|
|
59
|
-
at: z.union([
|
|
60
|
-
z.number().min(0).max(100),
|
|
61
|
-
|
|
62
|
-
// because of supporting matrix
|
|
63
|
-
z.string(),
|
|
64
|
-
]),
|
|
65
|
-
environment: Array.isArray(projectConfig.environments)
|
|
66
|
-
? refineWithMessage(
|
|
67
|
-
z.string(),
|
|
68
|
-
(value) => {
|
|
69
|
-
if (value.indexOf("${{") === 0) {
|
|
70
|
-
// allow unknown strings for matrix
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// otherwise only known environments should be passed
|
|
75
|
-
if (
|
|
76
|
-
Array.isArray(projectConfig.environments) &&
|
|
77
|
-
projectConfig.environments.includes(value)
|
|
78
|
-
) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return false;
|
|
83
|
-
},
|
|
84
|
-
(value) => `Unknown environment "${value}"`,
|
|
85
|
-
)
|
|
86
|
-
: z.never().optional(),
|
|
87
|
-
target: refineWithMessage(
|
|
88
|
-
z.string(),
|
|
89
|
-
(value) => {
|
|
90
|
-
if (value.indexOf("${{") === 0) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return availableTargetKeys.includes(value);
|
|
95
|
-
},
|
|
96
|
-
(value) => `Unknown target "${value}"`,
|
|
97
|
-
).optional(),
|
|
98
|
-
|
|
99
|
-
// parent
|
|
100
|
-
sticky: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
101
|
-
context: z.record(z.string(), z.unknown()).optional(),
|
|
102
|
-
|
|
103
|
-
defaultVariationValue: z.string().optional(),
|
|
104
|
-
defaultVariableValues: z.record(z.string(), z.unknown()).optional(),
|
|
105
|
-
|
|
106
|
-
expectedToBeEnabled: z.boolean().optional(),
|
|
107
|
-
expectedVariation: z.string().nullable().optional(),
|
|
108
|
-
expectedVariables: z.record(z.string(), z.unknown()).optional(),
|
|
109
|
-
expectedEvaluations: z
|
|
110
|
-
.object({
|
|
111
|
-
flag: z.record(z.string(), z.any()).optional(),
|
|
112
|
-
variation: z.record(z.string(), z.any()).optional(),
|
|
113
|
-
variables: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
114
|
-
})
|
|
115
|
-
.optional(),
|
|
116
|
-
|
|
117
|
-
children: z
|
|
118
|
-
.array(
|
|
119
|
-
z.object({
|
|
120
|
-
// copied from parent
|
|
121
|
-
sticky: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
122
|
-
context: z.record(z.string(), z.unknown()).optional(),
|
|
123
|
-
|
|
124
|
-
defaultVariationValue: z.string().optional(),
|
|
125
|
-
defaultVariableValues: z.record(z.string(), z.unknown()).optional(),
|
|
126
|
-
|
|
127
|
-
expectedToBeEnabled: z.boolean().optional(),
|
|
128
|
-
expectedVariation: z.string().nullable().optional(),
|
|
129
|
-
expectedVariables: z.record(z.string(), z.unknown()).optional(),
|
|
130
|
-
|
|
131
|
-
expectedEvaluations: z
|
|
132
|
-
.object({
|
|
133
|
-
flag: z.record(z.string(), z.any()).optional(),
|
|
134
|
-
variation: z.record(z.string(), z.any()).optional(),
|
|
135
|
-
variables: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
136
|
-
})
|
|
137
|
-
.optional(),
|
|
138
|
-
}),
|
|
139
|
-
)
|
|
140
|
-
.optional(),
|
|
141
|
-
})
|
|
142
|
-
.strict(),
|
|
143
|
-
),
|
|
144
|
-
})
|
|
145
|
-
.strict();
|
|
146
|
-
|
|
147
|
-
return z.union([segmentTestZodSchema, featureTestZodSchema]);
|
|
148
|
-
}
|
package/src/linter/zodHelpers.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export function refineWithMessage<T>(
|
|
4
|
-
schema: z.ZodType<T>,
|
|
5
|
-
predicate: (value: T) => boolean,
|
|
6
|
-
getMessage: (value: T) => string,
|
|
7
|
-
) {
|
|
8
|
-
return schema.superRefine((value, ctx) => {
|
|
9
|
-
if (!predicate(value)) {
|
|
10
|
-
ctx.addIssue({
|
|
11
|
-
code: z.ZodIssueCode.custom,
|
|
12
|
-
message: getMessage(value),
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
package/src/list/index.spec.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { ParsedFeature } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
import { formatDatafileSize, listEntities, listProject } from "./index";
|
|
4
|
-
|
|
5
|
-
function createFeatureFixture(overrides: Partial<ParsedFeature> = {}): ParsedFeature {
|
|
6
|
-
return {
|
|
7
|
-
key: "untagged",
|
|
8
|
-
description: "Untagged feature",
|
|
9
|
-
bucketBy: "userId",
|
|
10
|
-
rules: {
|
|
11
|
-
staging: [{ key: "everyone", segments: "*", percentage: 100 }],
|
|
12
|
-
production: [{ key: "everyone", segments: "*", percentage: 100 }],
|
|
13
|
-
},
|
|
14
|
-
...overrides,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe("core: list", function () {
|
|
19
|
-
test("excludes features with missing tags when tag filter is provided", async function () {
|
|
20
|
-
const datasource = {
|
|
21
|
-
listFeatures: async () => ["untagged"],
|
|
22
|
-
readFeature: async () => createFeatureFixture(),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const result = await listEntities<ParsedFeature>(
|
|
26
|
-
{
|
|
27
|
-
rootDirectoryPath: "",
|
|
28
|
-
projectConfig: {} as any,
|
|
29
|
-
datasource: datasource as any,
|
|
30
|
-
options: {
|
|
31
|
-
tag: "all",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
"feature",
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
expect(result).toEqual([]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("lists the union of features selected by repeated targets", async function () {
|
|
41
|
-
const featureFixtures = {
|
|
42
|
-
web: createFeatureFixture({ key: "web", tags: ["web"] }),
|
|
43
|
-
mobile: createFeatureFixture({ key: "mobile", tags: ["mobile"] }),
|
|
44
|
-
internal: createFeatureFixture({ key: "internal", tags: ["internal"] }),
|
|
45
|
-
};
|
|
46
|
-
const datasource = {
|
|
47
|
-
listFeatures: async () => Object.keys(featureFixtures),
|
|
48
|
-
readFeature: async (key: keyof typeof featureFixtures) => featureFixtures[key],
|
|
49
|
-
listTargets: async () => ["web", "mobile"],
|
|
50
|
-
readTarget: async (key: string) => ({ description: key, tag: key }),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const result = await listEntities<ParsedFeature>(
|
|
54
|
-
{
|
|
55
|
-
rootDirectoryPath: "",
|
|
56
|
-
projectConfig: {} as any,
|
|
57
|
-
datasource: datasource as any,
|
|
58
|
-
options: { target: ["web", "mobile"] },
|
|
59
|
-
},
|
|
60
|
-
"feature",
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(result.map((feature) => feature.key).sort()).toEqual(["mobile", "web"]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("lists generated datafiles", async function () {
|
|
67
|
-
const log = jest.spyOn(console, "log").mockImplementation();
|
|
68
|
-
const datasource = {
|
|
69
|
-
listDatafiles: async () => [
|
|
70
|
-
{ path: "production/featurevisor-all.json", size: 42, gzipSize: 62 },
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
await listProject({
|
|
75
|
-
rootDirectoryPath: "",
|
|
76
|
-
projectConfig: {} as any,
|
|
77
|
-
datasource: datasource as any,
|
|
78
|
-
options: { datafiles: true, json: true },
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(log).toHaveBeenCalledWith(
|
|
82
|
-
'[{"path":"production/featurevisor-all.json","size":42,"gzipSize":62}]',
|
|
83
|
-
);
|
|
84
|
-
log.mockRestore();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("formats datafile sizes with colored units", function () {
|
|
88
|
-
expect(formatDatafileSize(42)).toBe("42.00 \u001b[33mB\u001b[0m");
|
|
89
|
-
expect(formatDatafileSize(1024)).toBe("1.00 \u001b[36mkB\u001b[0m");
|
|
90
|
-
expect(formatDatafileSize(1024 * 1024)).toBe("1.00 \u001b[32mmB\u001b[0m");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("prints datafiles in aligned columns", async function () {
|
|
94
|
-
const log = jest.spyOn(console, "log").mockImplementation();
|
|
95
|
-
const datasource = {
|
|
96
|
-
listDatafiles: async () => [
|
|
97
|
-
{ path: "production/featurevisor-all.json", size: 1024 * 1024, gzipSize: 1024 },
|
|
98
|
-
{ path: "staging/featurevisor-checkout.json", size: 42, gzipSize: 24 },
|
|
99
|
-
{ path: "development/featurevisor-all.json", size: 1024, gzipSize: 512 },
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
await listProject({
|
|
104
|
-
rootDirectoryPath: "",
|
|
105
|
-
projectConfig: {} as any,
|
|
106
|
-
datasource: datasource as any,
|
|
107
|
-
options: { datafiles: true },
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const output = log.mock.calls.map(([message]) => message).join("\n");
|
|
111
|
-
const uncoloredOutput = output.replace(/\u001b\[[0-9;]*m/g, "");
|
|
112
|
-
|
|
113
|
-
expect(uncoloredOutput).toContain("Datafile");
|
|
114
|
-
expect(uncoloredOutput).toContain("Size");
|
|
115
|
-
expect(uncoloredOutput).toContain("Gzip");
|
|
116
|
-
expect(uncoloredOutput).toContain("production/featurevisor-all.json");
|
|
117
|
-
expect(uncoloredOutput).toContain("staging/featurevisor-checkout.json");
|
|
118
|
-
expect(uncoloredOutput.indexOf("development/featurevisor-all.json")).toBeLessThan(
|
|
119
|
-
uncoloredOutput.indexOf("staging/featurevisor-checkout.json"),
|
|
120
|
-
);
|
|
121
|
-
expect(uncoloredOutput.indexOf("staging/featurevisor-checkout.json")).toBeLessThan(
|
|
122
|
-
uncoloredOutput.indexOf("production/featurevisor-all.json"),
|
|
123
|
-
);
|
|
124
|
-
expect(uncoloredOutput).toMatch(/development\/featurevisor-all\.json\s+1\.00 kB/);
|
|
125
|
-
expect(uncoloredOutput).toMatch(/development\/featurevisor-all\.json\s+1\.00 kB\s+512\.00 B/);
|
|
126
|
-
expect(uncoloredOutput).toMatch(/staging\/featurevisor-checkout\.json\s+42\.00 B/);
|
|
127
|
-
expect(uncoloredOutput).toMatch(/production\/featurevisor-all\.json\s+1\.00 mB/);
|
|
128
|
-
expect(uncoloredOutput).toContain("512.00 B\n\n staging/");
|
|
129
|
-
expect(uncoloredOutput).toContain("24.00 B\n\n production/");
|
|
130
|
-
expect(output).toContain("\u001b[36mkB\u001b[0m");
|
|
131
|
-
expect(output).toContain("\u001b[33mB\u001b[0m");
|
|
132
|
-
expect(output).toContain("\u001b[32mmB\u001b[0m");
|
|
133
|
-
log.mockRestore();
|
|
134
|
-
});
|
|
135
|
-
});
|