@featurevisor/core 2.6.7 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/coverage/clover.xml +145 -474
- package/coverage/coverage-final.json +4 -10
- package/coverage/lcov-report/{src/builder → builder}/allocator.ts.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/buildScopedConditions.ts.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/buildScopedDatafile.ts.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/buildScopedSegments.ts.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/index.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/revision.ts.html +10 -10
- package/coverage/lcov-report/{src/builder → builder}/traffic.ts.html +10 -10
- package/coverage/lcov-report/index.html +35 -65
- package/coverage/lcov-report/{src/list → list}/index.html +24 -24
- package/coverage/lcov-report/{src/list → list}/matrix.ts.html +27 -18
- package/coverage/lcov-report/{lib/tester → parsers}/index.html +41 -26
- package/coverage/lcov-report/parsers/json.ts.html +118 -0
- package/coverage/lcov-report/parsers/yml.ts.html +589 -0
- package/coverage/lcov-report/{src/tester → tester}/helpers.ts.html +10 -10
- package/coverage/lcov-report/{src/tester → tester}/index.html +10 -10
- package/coverage/lcov.info +246 -899
- package/jest.config.js +1 -0
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +0 -1
- package/lib/config/index.js.map +1 -1
- package/lib/config/projectConfig.d.ts +1 -1
- package/lib/config/projectConfig.js +1 -1
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/filesystemAdapter.js +1 -1
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/linter/conditionSchema.js +45 -6
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +5 -0
- package/lib/linter/testSchema.js +6 -1
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/list/matrix.js +4 -1
- package/lib/list/matrix.js.map +1 -1
- package/lib/{config/parsers.d.ts → parsers/index.d.ts} +5 -5
- package/lib/parsers/index.js +15 -0
- package/lib/parsers/index.js.map +1 -0
- package/lib/parsers/json.d.ts +2 -0
- package/lib/parsers/json.js +13 -0
- package/lib/parsers/json.js.map +1 -0
- package/lib/parsers/json.spec.d.ts +1 -0
- package/lib/parsers/json.spec.js +35 -0
- package/lib/parsers/json.spec.js.map +1 -0
- package/lib/parsers/yml.d.ts +2 -0
- package/lib/parsers/yml.js +154 -0
- package/lib/parsers/yml.js.map +1 -0
- package/lib/parsers/yml.spec.d.ts +1 -0
- package/lib/parsers/yml.spec.js +143 -0
- package/lib/parsers/yml.spec.js.map +1 -0
- package/lib/tester/testFeature.js +6 -1
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +1 -0
- package/lib/tester/testProject.js +28 -2
- package/lib/tester/testProject.js.map +1 -1
- package/lib/utils/git.js.map +1 -1
- package/package.json +6 -6
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.ts +1 -1
- package/src/datasource/datasource.ts +2 -1
- package/src/datasource/filesystemAdapter.ts +3 -2
- package/src/index.ts +1 -0
- package/src/linter/conditionSchema.ts +43 -6
- package/src/linter/testSchema.ts +9 -1
- package/src/list/matrix.ts +4 -1
- package/src/parsers/index.ts +22 -0
- package/src/parsers/json.spec.ts +36 -0
- package/src/parsers/json.ts +11 -0
- package/src/parsers/yml.spec.ts +174 -0
- package/src/parsers/yml.ts +168 -0
- package/src/tester/testFeature.ts +6 -1
- package/src/tester/testProject.ts +41 -2
- package/src/utils/git.ts +2 -1
- package/coverage/lcov-report/lib/builder/allocator.js.html +0 -196
- package/coverage/lcov-report/lib/builder/buildScopedConditions.js.html +0 -373
- package/coverage/lcov-report/lib/builder/buildScopedDatafile.js.html +0 -403
- package/coverage/lcov-report/lib/builder/buildScopedSegments.js.html +0 -379
- package/coverage/lcov-report/lib/builder/index.html +0 -191
- package/coverage/lcov-report/lib/builder/revision.js.html +0 -148
- package/coverage/lcov-report/lib/builder/traffic.js.html +0 -493
- package/coverage/lcov-report/lib/list/index.html +0 -116
- package/coverage/lcov-report/lib/list/matrix.js.html +0 -523
- package/coverage/lcov-report/lib/tester/helpers.js.html +0 -295
- package/lib/config/parsers.js +0 -32
- package/lib/config/parsers.js.map +0 -1
- package/src/config/parsers.ts +0 -40
package/src/linter/testSchema.ts
CHANGED
|
@@ -84,7 +84,15 @@ export function getTestsZodSchema(
|
|
|
84
84
|
}),
|
|
85
85
|
)
|
|
86
86
|
: z.never().optional(),
|
|
87
|
-
|
|
87
|
+
tag: z
|
|
88
|
+
.string()
|
|
89
|
+
.refine(
|
|
90
|
+
(value) => projectConfig.tags.includes(value),
|
|
91
|
+
(value) => ({
|
|
92
|
+
message: `Unknown tag "${value}"`,
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
.optional(),
|
|
88
96
|
scope: z
|
|
89
97
|
.string()
|
|
90
98
|
.refine(
|
package/src/list/matrix.ts
CHANGED
|
@@ -101,7 +101,10 @@ export function applyCombinationToFeatureAssertion(
|
|
|
101
101
|
flattenedAssertion.scope = applyCombinationToValue(flattenedAssertion.scope, combination);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
//
|
|
104
|
+
// tag
|
|
105
|
+
if (flattenedAssertion.tag) {
|
|
106
|
+
flattenedAssertion.tag = applyCombinationToValue(flattenedAssertion.tag, combination);
|
|
107
|
+
}
|
|
105
108
|
|
|
106
109
|
return flattenedAssertion;
|
|
107
110
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsonParser } from "./json";
|
|
2
|
+
import { ymlParser } from "./yml";
|
|
3
|
+
|
|
4
|
+
export interface CustomParser {
|
|
5
|
+
extension: string;
|
|
6
|
+
parse: <T>(content: string, filePath?: string) => T;
|
|
7
|
+
stringify: (content: any, filePath?: string) => string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* If we want to add more built-in parsers,
|
|
12
|
+
* add them to this object with new file extension as the key,
|
|
13
|
+
* and a function that takes file content as string and returns parsed object as the value.
|
|
14
|
+
*/
|
|
15
|
+
export const parsers: { [key: string]: CustomParser } = {
|
|
16
|
+
yml: ymlParser,
|
|
17
|
+
json: jsonParser,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type BuiltInParser = keyof typeof parsers; // keys of parsers object
|
|
21
|
+
|
|
22
|
+
export type Parser = BuiltInParser | CustomParser;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsonParser } from "./json";
|
|
2
|
+
|
|
3
|
+
describe("core :: parser :: jsonParser", () => {
|
|
4
|
+
it("should parse JSON string into object", () => {
|
|
5
|
+
const jsonString = '{"foo":1,"bar":"baz","arr":[1,2]}';
|
|
6
|
+
const result = jsonParser.parse<{ foo: number; bar: string; arr: number[] }>(jsonString);
|
|
7
|
+
expect(result).toEqual({ foo: 1, bar: "baz", arr: [1, 2] });
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should stringify object into JSON string (pretty-printed)", () => {
|
|
11
|
+
const obj = { foo: 1, bar: "baz", arr: [1, 2] };
|
|
12
|
+
const jsonString = jsonParser.stringify(obj);
|
|
13
|
+
const expectedString = `{
|
|
14
|
+
"foo": 1,
|
|
15
|
+
"bar": "baz",
|
|
16
|
+
"arr": [
|
|
17
|
+
1,
|
|
18
|
+
2
|
|
19
|
+
]
|
|
20
|
+
}`;
|
|
21
|
+
expect(jsonString).toBe(expectedString);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should parse and then stringify to preserve content", () => {
|
|
25
|
+
const original = { alpha: "a", num: 42, bool: true, nullish: null, nested: { z: "x" } };
|
|
26
|
+
const str = jsonParser.stringify(original);
|
|
27
|
+
const reparsed = jsonParser.parse<typeof original>(str);
|
|
28
|
+
expect(reparsed).toEqual(original);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should throw if invalid JSON string is provided to parse", () => {
|
|
32
|
+
expect(() => {
|
|
33
|
+
jsonParser.parse("this is not json");
|
|
34
|
+
}).toThrow();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CustomParser } from "./index";
|
|
2
|
+
|
|
3
|
+
export const jsonParser: CustomParser = {
|
|
4
|
+
extension: "json",
|
|
5
|
+
parse: function <T>(content: string): T {
|
|
6
|
+
return JSON.parse(content) as T;
|
|
7
|
+
},
|
|
8
|
+
stringify: function (content: any) {
|
|
9
|
+
return JSON.stringify(content, null, 2);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { ymlParser } from "./yml";
|
|
2
|
+
|
|
3
|
+
describe("core :: parser :: ymlParser", () => {
|
|
4
|
+
it("should parse YAML string into object", () => {
|
|
5
|
+
const yamlString = `
|
|
6
|
+
foo: 1
|
|
7
|
+
bar: baz
|
|
8
|
+
arr:
|
|
9
|
+
- 1
|
|
10
|
+
- 2
|
|
11
|
+
`;
|
|
12
|
+
const result = ymlParser.parse<{ foo: number; bar: string; arr: number[] }>(yamlString);
|
|
13
|
+
expect(result).toEqual({ foo: 1, bar: "baz", arr: [1, 2] });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should stringify object into YAML string", () => {
|
|
17
|
+
const obj = { foo: 1, bar: "baz", arr: [1, 2] };
|
|
18
|
+
const yamlString = ymlParser.stringify(obj);
|
|
19
|
+
expect(yamlString.trim()).toBe(`foo: 1
|
|
20
|
+
bar: baz
|
|
21
|
+
arr:
|
|
22
|
+
- 1
|
|
23
|
+
- 2`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should parse and then stringify to preserve YAML content semantically", () => {
|
|
27
|
+
const original = {
|
|
28
|
+
alpha: "a",
|
|
29
|
+
num: 42,
|
|
30
|
+
bool: true,
|
|
31
|
+
nullish: null,
|
|
32
|
+
nested: { z: "x", y: [1, 2] },
|
|
33
|
+
};
|
|
34
|
+
const str = ymlParser.stringify(original);
|
|
35
|
+
const reparsed = ymlParser.parse<typeof original>(str);
|
|
36
|
+
expect(reparsed).toEqual(original);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should throw if invalid YAML string is provided to parse", () => {
|
|
40
|
+
expect(() => {
|
|
41
|
+
ymlParser.parse("foo: : bar");
|
|
42
|
+
}).toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("stringify() with filePath argument (existing file for ordering/comments only)", () => {
|
|
46
|
+
const fs = require("fs");
|
|
47
|
+
const path = require("path");
|
|
48
|
+
const os = require("os");
|
|
49
|
+
|
|
50
|
+
let tempFile: string;
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
tempFile = path.join(os.tmpdir(), `test_${Math.random()}.yml`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
if (fs.existsSync(tempFile)) {
|
|
58
|
+
fs.unlinkSync(tempFile);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should save exactly the new object; existing file is only for ordering/comments", () => {
|
|
63
|
+
const beforeYaml =
|
|
64
|
+
`
|
|
65
|
+
foo: 1 # foo comment here
|
|
66
|
+
extra: blah
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# Comment above nested
|
|
70
|
+
#
|
|
71
|
+
nested:
|
|
72
|
+
a: x
|
|
73
|
+
b: y # b comment
|
|
74
|
+
array:
|
|
75
|
+
- one # one
|
|
76
|
+
- two # two
|
|
77
|
+
- three # three
|
|
78
|
+
`.trim() + "\n";
|
|
79
|
+
|
|
80
|
+
const newContent = {
|
|
81
|
+
foo: 42,
|
|
82
|
+
bar: "new",
|
|
83
|
+
nested: { b: "updated", c: "added" },
|
|
84
|
+
array: ["two", "three", "four"],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const afterYaml =
|
|
88
|
+
`
|
|
89
|
+
foo: 42 # foo comment here
|
|
90
|
+
bar: new
|
|
91
|
+
##
|
|
92
|
+
# Comment above nested
|
|
93
|
+
#
|
|
94
|
+
nested:
|
|
95
|
+
b: updated # b comment
|
|
96
|
+
c: added
|
|
97
|
+
array:
|
|
98
|
+
- two # two
|
|
99
|
+
- three # three
|
|
100
|
+
- four
|
|
101
|
+
`.trim() + "\n";
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(tempFile, beforeYaml);
|
|
104
|
+
|
|
105
|
+
const output = ymlParser.stringify(newContent, tempFile);
|
|
106
|
+
|
|
107
|
+
expect(output).toBe(afterYaml);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should replace the root if YAML file is empty", () => {
|
|
111
|
+
const beforeYaml = "";
|
|
112
|
+
const afterYaml =
|
|
113
|
+
`
|
|
114
|
+
hello: world
|
|
115
|
+
test:
|
|
116
|
+
- 1
|
|
117
|
+
- 2
|
|
118
|
+
- 3
|
|
119
|
+
`.trim() + "\n";
|
|
120
|
+
|
|
121
|
+
fs.writeFileSync(tempFile, beforeYaml);
|
|
122
|
+
|
|
123
|
+
const obj = { hello: "world", test: [1, 2, 3] };
|
|
124
|
+
const output = ymlParser.stringify(obj, tempFile);
|
|
125
|
+
|
|
126
|
+
expect(output).toBe(afterYaml);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should throw if trying to set YAML document root to a primitive", () => {
|
|
130
|
+
const beforeYaml =
|
|
131
|
+
`
|
|
132
|
+
foo: bar
|
|
133
|
+
`.trim() + "\n";
|
|
134
|
+
|
|
135
|
+
fs.writeFileSync(tempFile, beforeYaml);
|
|
136
|
+
|
|
137
|
+
// Root must be an object when using filePath; primitives throw
|
|
138
|
+
expect(() => {
|
|
139
|
+
ymlParser.stringify("primitive", tempFile);
|
|
140
|
+
}).toThrow(/Cannot set root document to a primitive value/);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("should fall back to simple stringify if filePath does not exist", () => {
|
|
144
|
+
const fakeFilePath = path.join(os.tmpdir(), `notfound_${Math.random()}.yml`);
|
|
145
|
+
const afterYaml =
|
|
146
|
+
`
|
|
147
|
+
only: in-memory
|
|
148
|
+
`.trim() + "\n";
|
|
149
|
+
|
|
150
|
+
const obj = { only: "in-memory" };
|
|
151
|
+
const output = ymlParser.stringify(obj, fakeFilePath);
|
|
152
|
+
|
|
153
|
+
expect(output).toBe(afterYaml);
|
|
154
|
+
expect(fs.existsSync(fakeFilePath)).toBe(false); // should not create the file
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should not mutate the original YAML file", () => {
|
|
158
|
+
const beforeYaml =
|
|
159
|
+
`
|
|
160
|
+
foo: unchanged
|
|
161
|
+
bar: before
|
|
162
|
+
`.trim() + "\n";
|
|
163
|
+
|
|
164
|
+
fs.writeFileSync(tempFile, beforeYaml);
|
|
165
|
+
const onDiskBefore = fs.readFileSync(tempFile, "utf8");
|
|
166
|
+
|
|
167
|
+
const obj = { bar: "after" };
|
|
168
|
+
ymlParser.stringify(obj, tempFile);
|
|
169
|
+
|
|
170
|
+
const onDiskAfter = fs.readFileSync(tempFile, "utf8");
|
|
171
|
+
expect(onDiskAfter).toBe(onDiskBefore); // file on disk unchanged
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
|
|
3
|
+
import { parse, parseDocument, stringify } from "yaml";
|
|
4
|
+
import type { Pair, YAMLMap, YAMLSeq } from "yaml/types";
|
|
5
|
+
import { Scalar as ScalarCtor } from "yaml/types";
|
|
6
|
+
|
|
7
|
+
import type { CustomParser } from "./index";
|
|
8
|
+
|
|
9
|
+
function getKeyString(keyNode: unknown): string | undefined {
|
|
10
|
+
if (keyNode == null) return undefined;
|
|
11
|
+
if (typeof (keyNode as { value?: unknown }).value !== "undefined") {
|
|
12
|
+
return String((keyNode as { value: unknown }).value);
|
|
13
|
+
}
|
|
14
|
+
return typeof keyNode === "string" ? keyNode : undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function copyComments(source: Pair, target: Pair): void {
|
|
18
|
+
if (source.comment != null) target.comment = source.comment;
|
|
19
|
+
if (source.commentBefore != null) target.commentBefore = source.commentBefore;
|
|
20
|
+
const srcVal = source.value as
|
|
21
|
+
| { comment?: string | null; commentBefore?: string | null }
|
|
22
|
+
| undefined;
|
|
23
|
+
const tgtVal = target.value;
|
|
24
|
+
if (srcVal && tgtVal && typeof tgtVal === "object" && tgtVal !== null) {
|
|
25
|
+
const t = tgtVal as { comment?: string | null; commentBefore?: string | null };
|
|
26
|
+
if (srcVal.comment != null) t.comment = srcVal.comment;
|
|
27
|
+
if (srcVal.commentBefore != null) t.commentBefore = srcVal.commentBefore;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isYamlMap(node: unknown): node is YAMLMap {
|
|
32
|
+
return node != null && typeof node === "object" && Array.isArray((node as YAMLMap).items);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isYamlSeq(node: unknown): node is YAMLSeq {
|
|
36
|
+
return node != null && typeof node === "object" && Array.isArray((node as YAMLSeq).items);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function seqItemValueKey(item: unknown): string {
|
|
40
|
+
if (item == null) return String(item);
|
|
41
|
+
const n = item as { value?: unknown; toJSON?: () => unknown };
|
|
42
|
+
if (typeof n.value !== "undefined") return JSON.stringify(n.value);
|
|
43
|
+
if (typeof n.toJSON === "function") return JSON.stringify(n.toJSON());
|
|
44
|
+
return JSON.stringify(item);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function primitiveValueKey(v: unknown): string {
|
|
48
|
+
return JSON.stringify(v);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createValueWithComments(
|
|
52
|
+
schema: { createNode: (v: unknown) => unknown; createPair: (k: unknown, v: unknown) => Pair },
|
|
53
|
+
oldNode: unknown,
|
|
54
|
+
newValue: unknown,
|
|
55
|
+
): unknown {
|
|
56
|
+
if (newValue === null || typeof newValue !== "object") {
|
|
57
|
+
const node = new ScalarCtor(newValue);
|
|
58
|
+
const old = oldNode as { comment?: string | null; commentBefore?: string | null } | undefined;
|
|
59
|
+
if (old) {
|
|
60
|
+
if (old.comment != null) node.comment = old.comment;
|
|
61
|
+
if (old.commentBefore != null) node.commentBefore = old.commentBefore;
|
|
62
|
+
}
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(newValue)) {
|
|
66
|
+
const oldSeq = isYamlSeq(oldNode) ? (oldNode as YAMLSeq) : null;
|
|
67
|
+
const oldItemsByValue = new Map<string, unknown>();
|
|
68
|
+
if (oldSeq && oldSeq.items) {
|
|
69
|
+
for (const item of oldSeq.items) {
|
|
70
|
+
oldItemsByValue.set(seqItemValueKey(item), item);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const newSeq = schema.createNode([]) as YAMLSeq;
|
|
74
|
+
for (const el of newValue) {
|
|
75
|
+
const oldItem = oldItemsByValue.get(primitiveValueKey(el));
|
|
76
|
+
const itemNode = createValueWithComments(schema, oldItem, el);
|
|
77
|
+
newSeq.add(itemNode);
|
|
78
|
+
}
|
|
79
|
+
return newSeq;
|
|
80
|
+
}
|
|
81
|
+
// newValue is a plain object; preserve comments from old map if present
|
|
82
|
+
const oldMap = isYamlMap(oldNode) ? (oldNode as YAMLMap) : null;
|
|
83
|
+
const oldPairsByKey = new Map<string, Pair>();
|
|
84
|
+
if (oldMap) {
|
|
85
|
+
for (const pair of (oldMap.items || []) as Pair[]) {
|
|
86
|
+
const keyStr = getKeyString(pair.key);
|
|
87
|
+
if (keyStr !== undefined) oldPairsByKey.set(keyStr, pair);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const newMap = schema.createNode({}) as YAMLMap;
|
|
91
|
+
const obj = newValue as Record<string, unknown>;
|
|
92
|
+
for (const k of Object.keys(obj)) {
|
|
93
|
+
const oldPair = oldPairsByKey.get(k);
|
|
94
|
+
const childOldNode = oldPair ? oldPair.value : undefined;
|
|
95
|
+
const childNewValue = createValueWithComments(schema, childOldNode, obj[k]);
|
|
96
|
+
const newPair = schema.createPair(k, childNewValue);
|
|
97
|
+
if (oldPair) copyComments(oldPair, newPair);
|
|
98
|
+
newMap.add(newPair);
|
|
99
|
+
}
|
|
100
|
+
const result = newMap as { comment?: string | null; commentBefore?: string | null };
|
|
101
|
+
const oldVal = oldNode as { comment?: string | null; commentBefore?: string | null } | undefined;
|
|
102
|
+
if (oldVal && result) {
|
|
103
|
+
if (oldVal.comment != null) result.comment = oldVal.comment;
|
|
104
|
+
if (oldVal.commentBefore != null) result.commentBefore = oldVal.commentBefore;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function replaceContentsPreservingComments(
|
|
110
|
+
doc: {
|
|
111
|
+
contents: unknown;
|
|
112
|
+
schema: { createNode: (v: unknown) => unknown; createPair: (k: unknown, v: unknown) => Pair };
|
|
113
|
+
},
|
|
114
|
+
newContent: Record<string, unknown>,
|
|
115
|
+
): void {
|
|
116
|
+
const oldRoot = doc.contents as YAMLMap | null | undefined;
|
|
117
|
+
if (!oldRoot || !Array.isArray((oldRoot as YAMLMap).items)) {
|
|
118
|
+
doc.contents = doc.schema.createNode(newContent) as typeof doc.contents;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const schema = doc.schema;
|
|
123
|
+
const oldPairsByKey = new Map<string, Pair>();
|
|
124
|
+
for (const pair of (oldRoot as YAMLMap).items as Pair[]) {
|
|
125
|
+
const keyStr = getKeyString(pair.key);
|
|
126
|
+
if (keyStr !== undefined) oldPairsByKey.set(keyStr, pair);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const newMap = schema.createNode({}) as YAMLMap;
|
|
130
|
+
for (const key of Object.keys(newContent)) {
|
|
131
|
+
const oldPair = oldPairsByKey.get(key);
|
|
132
|
+
const valueNode = createValueWithComments(schema, oldPair?.value, newContent[key]);
|
|
133
|
+
const newPair = schema.createPair(key, valueNode);
|
|
134
|
+
if (oldPair) copyComments(oldPair, newPair);
|
|
135
|
+
newMap.add(newPair);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
(doc as { contents: unknown }).contents = newMap;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const ymlParser: CustomParser = {
|
|
142
|
+
extension: "yml",
|
|
143
|
+
parse: function <T>(content: string): T {
|
|
144
|
+
return parse(content) as T;
|
|
145
|
+
},
|
|
146
|
+
stringify: function (content: any, filePath?: string) {
|
|
147
|
+
if (!filePath || !fs.existsSync(filePath)) {
|
|
148
|
+
return stringify(content);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
152
|
+
if (!fileContent.trim()) {
|
|
153
|
+
return stringify(content);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// newObject is the final saved object; existing file is only for ordering/comments
|
|
157
|
+
if (content === null || typeof content !== "object" || Array.isArray(content)) {
|
|
158
|
+
throw new Error("Cannot set root document to a primitive value");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const doc = parseDocument(fileContent) as {
|
|
162
|
+
contents: unknown;
|
|
163
|
+
schema: { createNode: (v: unknown) => unknown; createPair: (k: unknown, v: unknown) => Pair };
|
|
164
|
+
};
|
|
165
|
+
replaceContentsPreservingComments(doc, content);
|
|
166
|
+
return doc.toString();
|
|
167
|
+
},
|
|
168
|
+
};
|
|
@@ -61,12 +61,17 @@ export async function testFeature(
|
|
|
61
61
|
|
|
62
62
|
let datafileContent = datafileContentByKey.get(assertion.environment || false);
|
|
63
63
|
|
|
64
|
+
// scope
|
|
64
65
|
const scopedDatafileKey = `${assertion.environment}-scope-${assertion.scope}`;
|
|
65
66
|
if (assertion.scope && datafileContentByKey.has(scopedDatafileKey)) {
|
|
66
67
|
datafileContent = datafileContentByKey.get(scopedDatafileKey);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
//
|
|
70
|
+
// tag
|
|
71
|
+
const taggedDatafileKey = `${assertion.environment}-tag-${assertion.tag}`;
|
|
72
|
+
if (assertion.tag && datafileContentByKey.has(taggedDatafileKey)) {
|
|
73
|
+
datafileContent = datafileContentByKey.get(taggedDatafileKey);
|
|
74
|
+
}
|
|
70
75
|
|
|
71
76
|
if (options.showDatafile) {
|
|
72
77
|
console.log("");
|
|
@@ -23,6 +23,7 @@ export interface TestProjectOptions {
|
|
|
23
23
|
schemaVersion?: string;
|
|
24
24
|
inflate?: number;
|
|
25
25
|
withScopes?: boolean;
|
|
26
|
+
withTags?: boolean;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface ExecutionResult {
|
|
@@ -173,7 +174,26 @@ export async function testProject(
|
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
//
|
|
177
|
+
// by tag
|
|
178
|
+
if (projectConfig.tags && options.withTags) {
|
|
179
|
+
for (const tag of projectConfig.tags) {
|
|
180
|
+
const existingState = await datasource.readState(environment);
|
|
181
|
+
const datafileContent = (await buildDatafile(
|
|
182
|
+
projectConfig,
|
|
183
|
+
datasource,
|
|
184
|
+
{
|
|
185
|
+
schemaVersion: options.schemaVersion || SCHEMA_VERSION,
|
|
186
|
+
revision: "include-tagged-features",
|
|
187
|
+
environment: environment,
|
|
188
|
+
inflate: options.inflate,
|
|
189
|
+
tag: tag,
|
|
190
|
+
},
|
|
191
|
+
existingState,
|
|
192
|
+
)) as DatafileContent;
|
|
193
|
+
|
|
194
|
+
datafileContentByKey.set(`${environment}-tag-${tag}`, datafileContent);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
177
197
|
}
|
|
178
198
|
}
|
|
179
199
|
|
|
@@ -221,7 +241,26 @@ export async function testProject(
|
|
|
221
241
|
}
|
|
222
242
|
}
|
|
223
243
|
|
|
224
|
-
//
|
|
244
|
+
// by tag
|
|
245
|
+
if (projectConfig.tags && options.withTags) {
|
|
246
|
+
for (const tag of projectConfig.tags) {
|
|
247
|
+
const existingState = await datasource.readState(false);
|
|
248
|
+
const datafileContent = (await buildDatafile(
|
|
249
|
+
projectConfig,
|
|
250
|
+
datasource,
|
|
251
|
+
{
|
|
252
|
+
schemaVersion: options.schemaVersion || SCHEMA_VERSION,
|
|
253
|
+
revision: "include-tagged-features",
|
|
254
|
+
environment: false,
|
|
255
|
+
inflate: options.inflate,
|
|
256
|
+
tag: tag,
|
|
257
|
+
},
|
|
258
|
+
existingState,
|
|
259
|
+
)) as DatafileContent;
|
|
260
|
+
|
|
261
|
+
datafileContentByKey.set(`tag-${tag}`, datafileContent);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
225
264
|
}
|
|
226
265
|
|
|
227
266
|
const tests = await listEntities<Test>(
|
package/src/utils/git.ts
CHANGED
|
@@ -2,7 +2,8 @@ import * as path from "path";
|
|
|
2
2
|
|
|
3
3
|
import type { Commit, EntityDiff, EntityType } from "@featurevisor/types";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ProjectConfig } from "../config";
|
|
6
|
+
import { CustomParser } from "../parsers";
|
|
6
7
|
|
|
7
8
|
function parseGitCommitShowOutput(gitShowOutput: string) {
|
|
8
9
|
const result = {
|