@featurevisor/core 3.0.1 → 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 -2238
- 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,47 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
import { ProjectConfig } from "../config";
|
|
4
|
-
import { Datasource } from "../datasource";
|
|
5
|
-
import { refineWithMessage } from "./zodHelpers";
|
|
6
|
-
|
|
7
|
-
export function getGroupZodSchema(
|
|
8
|
-
projectConfig: ProjectConfig,
|
|
9
|
-
datasource: Datasource,
|
|
10
|
-
availableFeatureKeys: string[],
|
|
11
|
-
) {
|
|
12
|
-
const groupZodSchema = z
|
|
13
|
-
.object({
|
|
14
|
-
description: z.string(),
|
|
15
|
-
promotable: z.boolean().optional(),
|
|
16
|
-
slots: z
|
|
17
|
-
.array(
|
|
18
|
-
z
|
|
19
|
-
.object({
|
|
20
|
-
feature: refineWithMessage(
|
|
21
|
-
z.string().optional(),
|
|
22
|
-
(value) => {
|
|
23
|
-
if (value && availableFeatureKeys.indexOf(value) === -1) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
(value) => `Unknown feature "${value}"`,
|
|
30
|
-
),
|
|
31
|
-
percentage: z.number().min(0).max(100),
|
|
32
|
-
})
|
|
33
|
-
.strict(),
|
|
34
|
-
)
|
|
35
|
-
.refine(
|
|
36
|
-
(value) => {
|
|
37
|
-
const totalPercentage = value.reduce((acc, slot) => acc + slot.percentage, 0);
|
|
38
|
-
|
|
39
|
-
return totalPercentage === 100;
|
|
40
|
-
},
|
|
41
|
-
{ message: "Total percentage of all slots is not 100" },
|
|
42
|
-
),
|
|
43
|
-
})
|
|
44
|
-
.strict();
|
|
45
|
-
|
|
46
|
-
return groupZodSchema;
|
|
47
|
-
}
|
package/src/linter/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./lintProject";
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as os from "os";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
|
|
5
|
-
import { getProjectConfig } from "../config/projectConfig";
|
|
6
|
-
import { Datasource } from "../datasource";
|
|
7
|
-
import { lintPlugin, lintProject, type LintResult } from "./lintProject";
|
|
8
|
-
|
|
9
|
-
function createTempProjectFromExample1() {
|
|
10
|
-
const fixturePath = path.resolve(__dirname, "../../../../examples/example-1");
|
|
11
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "featurevisor-lint-"));
|
|
12
|
-
|
|
13
|
-
fs.cpSync(fixturePath, tempRoot, { recursive: true });
|
|
14
|
-
|
|
15
|
-
return tempRoot;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function createTempProject(configBody = "module.exports = {};") {
|
|
19
|
-
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "featurevisor-lint-"));
|
|
20
|
-
|
|
21
|
-
fs.writeFileSync(path.join(tempRoot, "featurevisor.config.js"), configBody, "utf8");
|
|
22
|
-
|
|
23
|
-
return tempRoot;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function replaceInFile(filePath: string, search: string, replacement: string) {
|
|
27
|
-
const contents = fs.readFileSync(filePath, "utf8");
|
|
28
|
-
fs.writeFileSync(filePath, contents.replace(search, replacement), "utf8");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getDeps(rootDirectoryPath: string) {
|
|
32
|
-
const projectConfig = getProjectConfig(rootDirectoryPath);
|
|
33
|
-
const datasource = new Datasource(projectConfig, rootDirectoryPath);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
rootDirectoryPath,
|
|
37
|
-
projectConfig,
|
|
38
|
-
datasource,
|
|
39
|
-
options: {},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe("core: lintProject", function () {
|
|
44
|
-
let tempProjectPath: string;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
tempProjectPath = createTempProjectFromExample1();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
fs.rmSync(tempProjectPath, { recursive: true, force: true });
|
|
52
|
-
jest.restoreAllMocks();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("returns JSON-friendly empty errors array for a valid project", async () => {
|
|
56
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
57
|
-
|
|
58
|
-
expect(result).toEqual({
|
|
59
|
-
hasError: false,
|
|
60
|
-
errors: [],
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("rejects entity file names containing the namespace character", async () => {
|
|
65
|
-
const root = createTempProject();
|
|
66
|
-
tempProjectPath = root;
|
|
67
|
-
|
|
68
|
-
fs.mkdirSync(path.join(root, "segments"), { recursive: true });
|
|
69
|
-
fs.writeFileSync(
|
|
70
|
-
path.join(root, "segments", "version_5.5.yml"),
|
|
71
|
-
[
|
|
72
|
-
"description: Version 5.5",
|
|
73
|
-
"conditions:",
|
|
74
|
-
" - attribute: version",
|
|
75
|
-
" operator: semverEquals",
|
|
76
|
-
" value: 5.5.0",
|
|
77
|
-
"",
|
|
78
|
-
].join("\n"),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const result = await lintProject(getDeps(root) as any, { json: true });
|
|
82
|
-
|
|
83
|
-
expect(result.hasError).toBe(true);
|
|
84
|
-
expect(result.errors).toEqual(
|
|
85
|
-
expect.arrayContaining([
|
|
86
|
-
expect.objectContaining({
|
|
87
|
-
entityType: "segment",
|
|
88
|
-
filePath: expect.stringContaining(path.join("segments", "version_5.5.yml")),
|
|
89
|
-
message: 'Invalid file or directory name: "version_5.5.yml"',
|
|
90
|
-
code: "invalid_name",
|
|
91
|
-
}),
|
|
92
|
-
]),
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("allows established test file suffixes with the namespace character", async () => {
|
|
97
|
-
const root = createTempProject();
|
|
98
|
-
tempProjectPath = root;
|
|
99
|
-
|
|
100
|
-
fs.mkdirSync(path.join(root, "tests", "features"), { recursive: true });
|
|
101
|
-
fs.writeFileSync(
|
|
102
|
-
path.join(root, "tests", "features", "checkout.spec.yml"),
|
|
103
|
-
["feature: checkout", "assertions: []", ""].join("\n"),
|
|
104
|
-
"utf8",
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const result = await lintProject(getDeps(root) as any, { json: true, entityType: "test" });
|
|
108
|
-
|
|
109
|
-
expect(
|
|
110
|
-
result.errors.some(
|
|
111
|
-
(error) =>
|
|
112
|
-
error.code === "invalid_name" &&
|
|
113
|
-
error.filePath.includes(path.join("tests", "features", "checkout.spec.yml")),
|
|
114
|
-
),
|
|
115
|
-
).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("accepts promotable flags on top-level authored entities", async () => {
|
|
119
|
-
const files = [
|
|
120
|
-
path.join(tempProjectPath, "attributes", "userId.yml"),
|
|
121
|
-
path.join(tempProjectPath, "segments", "everyone.yml"),
|
|
122
|
-
path.join(tempProjectPath, "features", "showHeader.yml"),
|
|
123
|
-
path.join(tempProjectPath, "groups", "myExclusionGroup.yml"),
|
|
124
|
-
path.join(tempProjectPath, "schemas", "money.yml"),
|
|
125
|
-
path.join(tempProjectPath, "tests", "features", "showHeader.spec.yml"),
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
for (const file of files) {
|
|
129
|
-
fs.appendFileSync(file, "\npromotable: false\n");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
133
|
-
|
|
134
|
-
expect(result).toEqual({
|
|
135
|
-
hasError: false,
|
|
136
|
-
errors: [],
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("accepts promotable flags on feature rules", async () => {
|
|
141
|
-
replaceInFile(
|
|
142
|
-
path.join(tempProjectPath, "features", "showHeader.yml"),
|
|
143
|
-
' - key: "1"',
|
|
144
|
-
' - key: "1"\n promotable: false',
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
148
|
-
|
|
149
|
-
expect(result).toEqual({
|
|
150
|
-
hasError: false,
|
|
151
|
-
errors: [],
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("rejects non-boolean promotable values", async () => {
|
|
156
|
-
fs.appendFileSync(
|
|
157
|
-
path.join(tempProjectPath, "attributes", "userId.yml"),
|
|
158
|
-
"\npromotable: nope\n",
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
162
|
-
|
|
163
|
-
expect(result.hasError).toEqual(true);
|
|
164
|
-
expect(
|
|
165
|
-
result.errors.some(
|
|
166
|
-
(error) => error.path.join(".") === "promotable" && error.message.includes("boolean"),
|
|
167
|
-
),
|
|
168
|
-
).toEqual(true);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("rejects non-boolean rule promotable values", async () => {
|
|
172
|
-
replaceInFile(
|
|
173
|
-
path.join(tempProjectPath, "features", "showHeader.yml"),
|
|
174
|
-
' - key: "1"',
|
|
175
|
-
' - key: "1"\n promotable: nope',
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
179
|
-
|
|
180
|
-
expect(result.hasError).toEqual(true);
|
|
181
|
-
expect(
|
|
182
|
-
result.errors.some(
|
|
183
|
-
(error) =>
|
|
184
|
-
error.path.join(".") === "rules.staging.0.promotable" &&
|
|
185
|
-
error.message.includes("boolean"),
|
|
186
|
-
),
|
|
187
|
-
).toEqual(true);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("returns structured errors in JSON mode", async () => {
|
|
191
|
-
fs.writeFileSync(
|
|
192
|
-
path.join(tempProjectPath, "attributes", "invalid name.yml"),
|
|
193
|
-
`
|
|
194
|
-
description: this has an invalid key name
|
|
195
|
-
type: string
|
|
196
|
-
`.trimStart(),
|
|
197
|
-
"utf8",
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, {
|
|
201
|
-
json: true,
|
|
202
|
-
entityType: "attribute",
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
expect(result.hasError).toBe(true);
|
|
206
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
207
|
-
|
|
208
|
-
expect(result.errors[0]).toMatchObject({
|
|
209
|
-
entityType: "attribute",
|
|
210
|
-
key: "invalid name",
|
|
211
|
-
message: 'Invalid name: "invalid name"',
|
|
212
|
-
code: "invalid_name",
|
|
213
|
-
path: [],
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
expect(result.errors[0].filePath).toContain("attributes");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("reports real example-1 segment, feature, and test schema mistakes with useful paths", async () => {
|
|
220
|
-
replaceInFile(
|
|
221
|
-
path.join(tempProjectPath, "segments", "desktop.yml"),
|
|
222
|
-
`
|
|
223
|
-
conditions:
|
|
224
|
-
- attribute: device
|
|
225
|
-
operator: equals
|
|
226
|
-
value: desktop
|
|
227
|
-
`.trimStart(),
|
|
228
|
-
`
|
|
229
|
-
conditions:
|
|
230
|
-
- attribute: device
|
|
231
|
-
operator: equals
|
|
232
|
-
value: desktop
|
|
233
|
-
- attribute: notARealAttribute
|
|
234
|
-
operator: equals
|
|
235
|
-
value: nope
|
|
236
|
-
`.trimStart(),
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
replaceInFile(
|
|
240
|
-
path.join(tempProjectPath, "features", "withSchema.yml"),
|
|
241
|
-
`
|
|
242
|
-
singleLink:
|
|
243
|
-
schema: link
|
|
244
|
-
defaultValue:
|
|
245
|
-
title: Home
|
|
246
|
-
url: /
|
|
247
|
-
`.trimStart(),
|
|
248
|
-
`
|
|
249
|
-
singleLink:
|
|
250
|
-
schema: link
|
|
251
|
-
defaultValue:
|
|
252
|
-
title: Home
|
|
253
|
-
url: 123
|
|
254
|
-
`.trimStart(),
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
replaceInFile(
|
|
258
|
-
path.join(tempProjectPath, "tests", "features", "withSchema.spec.yml"),
|
|
259
|
-
" environment: staging",
|
|
260
|
-
" environment: qa",
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
const result = await lintProject(getDeps(tempProjectPath) as any, { json: true });
|
|
264
|
-
|
|
265
|
-
expect(result.hasError).toBe(true);
|
|
266
|
-
expect(result.errors).toEqual(
|
|
267
|
-
expect.arrayContaining([
|
|
268
|
-
expect.objectContaining({
|
|
269
|
-
filePath: expect.stringContaining(path.join("segments", "desktop.yml")),
|
|
270
|
-
entityType: "segment",
|
|
271
|
-
key: "desktop",
|
|
272
|
-
message: 'Unknown attribute "notARealAttribute"',
|
|
273
|
-
path: ["conditions", 1, "attribute"],
|
|
274
|
-
code: "custom",
|
|
275
|
-
}),
|
|
276
|
-
expect.objectContaining({
|
|
277
|
-
filePath: expect.stringContaining(path.join("features", "withSchema.yml")),
|
|
278
|
-
entityType: "feature",
|
|
279
|
-
key: "withSchema",
|
|
280
|
-
message: 'Variable "url" (type string) must be a string; got number.',
|
|
281
|
-
path: ["variablesSchema", "singleLink", "defaultValue", "url"],
|
|
282
|
-
code: "custom",
|
|
283
|
-
}),
|
|
284
|
-
expect.objectContaining({
|
|
285
|
-
filePath: expect.stringContaining(path.join("tests", "features", "withSchema.spec.yml")),
|
|
286
|
-
entityType: "test",
|
|
287
|
-
key: "features.withSchema.spec",
|
|
288
|
-
message: 'Unknown environment "qa"',
|
|
289
|
-
path: ["assertions", 0, "environment"],
|
|
290
|
-
code: "custom",
|
|
291
|
-
}),
|
|
292
|
-
]),
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("plugin prints pretty JSON only once in --json --pretty mode", async () => {
|
|
297
|
-
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
|
|
298
|
-
|
|
299
|
-
const pluginResult = await lintPlugin.handler({
|
|
300
|
-
...getDeps(tempProjectPath),
|
|
301
|
-
parsed: {
|
|
302
|
-
json: true,
|
|
303
|
-
pretty: true,
|
|
304
|
-
},
|
|
305
|
-
} as any);
|
|
306
|
-
|
|
307
|
-
expect(pluginResult).toBeUndefined();
|
|
308
|
-
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
|
|
309
|
-
|
|
310
|
-
const output = consoleLogSpy.mock.calls[0][0] as string;
|
|
311
|
-
expect(output).toContain('\n "errors": []\n');
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("does not call process.exit for zod validation errors while linting tests", async () => {
|
|
315
|
-
fs.writeFileSync(
|
|
316
|
-
path.join(tempProjectPath, "tests", "broken.spec.yml"),
|
|
317
|
-
`
|
|
318
|
-
feature: foo
|
|
319
|
-
`.trimStart(),
|
|
320
|
-
"utf8",
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
const processExitSpy = jest
|
|
324
|
-
.spyOn(process, "exit")
|
|
325
|
-
.mockImplementation((() => undefined) as unknown as typeof process.exit);
|
|
326
|
-
|
|
327
|
-
const result: LintResult = await lintProject(getDeps(tempProjectPath) as any, {
|
|
328
|
-
json: true,
|
|
329
|
-
entityType: "test",
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
expect(result.hasError).toBe(true);
|
|
333
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
334
|
-
expect(processExitSpy).not.toHaveBeenCalled();
|
|
335
|
-
});
|
|
336
|
-
});
|