sedum-cli 0.1.0-alpha.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/LICENSE +21 -0
- package/dist/chunk-BEV24G7S.js +444 -0
- package/dist/chunk-OB6ZUJ6X.js +242 -0
- package/dist/chunk-TU5MIKGA.js +963 -0
- package/dist/chunk-TZGSCV23.js +704 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/doctor-command-2PMOA32Y.js +17 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +19 -0
- package/dist/init-command-54R2FQ2U.js +237 -0
- package/dist/run-command-VAVFPCWG.js +1269 -0
- package/package.json +36 -0
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { readFile, readdir } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { parseEnv } from "util";
|
|
5
|
+
import { minimatch } from "minimatch";
|
|
6
|
+
import { isMap, LineCounter, parseDocument, visit } from "yaml";
|
|
7
|
+
var CONFIG_FILE = "sedum.config.yaml";
|
|
8
|
+
var ProjectConfigError = class extends Error {
|
|
9
|
+
constructor(diagnostics) {
|
|
10
|
+
super(diagnostics[0]?.message ?? "The Sedum configuration is invalid.");
|
|
11
|
+
this.diagnostics = diagnostics;
|
|
12
|
+
this.name = "ProjectConfigError";
|
|
13
|
+
}
|
|
14
|
+
diagnostics;
|
|
15
|
+
};
|
|
16
|
+
var DEFAULTS = {
|
|
17
|
+
testDirectory: "tests",
|
|
18
|
+
include: ["**/*.test.yaml"],
|
|
19
|
+
exclude: [],
|
|
20
|
+
browser: "chrome",
|
|
21
|
+
viewport: { width: 1280, height: 900 },
|
|
22
|
+
thresholds: {
|
|
23
|
+
minP: 0.75,
|
|
24
|
+
band: 0.15,
|
|
25
|
+
contradictionCutoff: 0.5
|
|
26
|
+
},
|
|
27
|
+
outputDir: ".sedum/runs",
|
|
28
|
+
reporterDir: ".sedum/reports"
|
|
29
|
+
};
|
|
30
|
+
var allowed = {
|
|
31
|
+
root: /* @__PURE__ */ new Set([
|
|
32
|
+
"tests",
|
|
33
|
+
"browser",
|
|
34
|
+
"viewport",
|
|
35
|
+
"thresholds",
|
|
36
|
+
"outputDir",
|
|
37
|
+
"reporterDir",
|
|
38
|
+
"baseUrl",
|
|
39
|
+
"environment",
|
|
40
|
+
"variables",
|
|
41
|
+
"environments"
|
|
42
|
+
]),
|
|
43
|
+
tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
|
|
44
|
+
viewport: /* @__PURE__ */ new Set(["width", "height"]),
|
|
45
|
+
thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
|
|
46
|
+
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"])
|
|
47
|
+
};
|
|
48
|
+
function source(file, counter, node) {
|
|
49
|
+
const position = counter.linePos(node?.range?.[0] ?? 0);
|
|
50
|
+
return { file, line: position.line, col: position.col };
|
|
51
|
+
}
|
|
52
|
+
function diagnostic(diagnostics, file, counter, node, key, code, message, fix) {
|
|
53
|
+
diagnostics.push({
|
|
54
|
+
code,
|
|
55
|
+
...source(file, counter, node),
|
|
56
|
+
key,
|
|
57
|
+
message,
|
|
58
|
+
fix
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function mapUnknownKeys(value, names, prefix, file, counter, diagnostics) {
|
|
62
|
+
if (!isMap(value)) return;
|
|
63
|
+
for (const pair of value.items) {
|
|
64
|
+
const key = String(pair.key);
|
|
65
|
+
if (!names.has(key))
|
|
66
|
+
diagnostic(
|
|
67
|
+
diagnostics,
|
|
68
|
+
file,
|
|
69
|
+
counter,
|
|
70
|
+
pair.key,
|
|
71
|
+
prefix ? `${prefix}.${key}` : key,
|
|
72
|
+
"unknown_config_key",
|
|
73
|
+
`Unknown configuration key \`${prefix ? `${prefix}.` : ""}${key}\`.`,
|
|
74
|
+
"Remove the key or use one documented by `sedum run --help`."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function object(value) {
|
|
79
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
80
|
+
}
|
|
81
|
+
function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
82
|
+
if (value === void 0) return {};
|
|
83
|
+
if (!object(value)) {
|
|
84
|
+
diagnostic(
|
|
85
|
+
diagnostics,
|
|
86
|
+
file,
|
|
87
|
+
counter,
|
|
88
|
+
node,
|
|
89
|
+
key,
|
|
90
|
+
"invalid_config_type",
|
|
91
|
+
`Configuration key \`${key}\` must be a mapping of scalar values.`,
|
|
92
|
+
`Write \`${key}: { NAME: value }\`.`
|
|
93
|
+
);
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
const result = {};
|
|
97
|
+
for (const [name, item] of Object.entries(value)) {
|
|
98
|
+
if (name === "TYPESAFE_API_KEY") {
|
|
99
|
+
diagnostic(
|
|
100
|
+
diagnostics,
|
|
101
|
+
file,
|
|
102
|
+
counter,
|
|
103
|
+
node,
|
|
104
|
+
`${key}.${name}`,
|
|
105
|
+
"api_key_in_config",
|
|
106
|
+
"TYPESAFE_API_KEY must not be stored in sedum.config.yaml.",
|
|
107
|
+
"Put TYPESAFE_API_KEY in the project-root .env or invoking process environment."
|
|
108
|
+
);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (item === null || ["string", "number", "boolean"].includes(typeof item))
|
|
112
|
+
result[name] = item === null ? "" : String(item);
|
|
113
|
+
else
|
|
114
|
+
diagnostic(
|
|
115
|
+
diagnostics,
|
|
116
|
+
file,
|
|
117
|
+
counter,
|
|
118
|
+
node,
|
|
119
|
+
`${key}.${name}`,
|
|
120
|
+
"invalid_config_variable",
|
|
121
|
+
`Configuration variable \`${key}.${name}\` must be a scalar.`,
|
|
122
|
+
"Use text, a number, a boolean, or null."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function relativePath(root, value, fallback, key, diagnostics, file, counter, node) {
|
|
128
|
+
if (value === void 0) value = fallback;
|
|
129
|
+
if (typeof value !== "string" || value.length === 0 || path.isAbsolute(value)) {
|
|
130
|
+
diagnostic(
|
|
131
|
+
diagnostics,
|
|
132
|
+
file,
|
|
133
|
+
counter,
|
|
134
|
+
node,
|
|
135
|
+
key,
|
|
136
|
+
"invalid_config_path",
|
|
137
|
+
`Configuration key \`${key}\` must be a nonempty project-relative path.`,
|
|
138
|
+
`Use a relative path such as \`${fallback}\`.`
|
|
139
|
+
);
|
|
140
|
+
return path.resolve(root, fallback);
|
|
141
|
+
}
|
|
142
|
+
const resolved = path.resolve(root, value);
|
|
143
|
+
const relation = path.relative(root, resolved);
|
|
144
|
+
if (relation === ".." || relation.startsWith(`..${path.sep}`)) {
|
|
145
|
+
diagnostic(
|
|
146
|
+
diagnostics,
|
|
147
|
+
file,
|
|
148
|
+
counter,
|
|
149
|
+
node,
|
|
150
|
+
key,
|
|
151
|
+
"config_path_escape",
|
|
152
|
+
`Configuration key \`${key}\` escapes the project root.`,
|
|
153
|
+
"Choose a path inside the project root."
|
|
154
|
+
);
|
|
155
|
+
return path.resolve(root, fallback);
|
|
156
|
+
}
|
|
157
|
+
return resolved;
|
|
158
|
+
}
|
|
159
|
+
function probability(value, fallback, key, diagnostics, file, counter, node) {
|
|
160
|
+
if (value === void 0) return fallback;
|
|
161
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
|
|
162
|
+
diagnostic(
|
|
163
|
+
diagnostics,
|
|
164
|
+
file,
|
|
165
|
+
counter,
|
|
166
|
+
node,
|
|
167
|
+
key,
|
|
168
|
+
"invalid_config_probability",
|
|
169
|
+
`Configuration key \`${key}\` must be a probability from 0 to 1.`,
|
|
170
|
+
"Use a finite number such as 0.75."
|
|
171
|
+
);
|
|
172
|
+
return fallback;
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
function positiveInteger(value, fallback, key, diagnostics, file, counter, node) {
|
|
177
|
+
if (value === void 0) return fallback;
|
|
178
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 16384) {
|
|
179
|
+
diagnostic(
|
|
180
|
+
diagnostics,
|
|
181
|
+
file,
|
|
182
|
+
counter,
|
|
183
|
+
node,
|
|
184
|
+
key,
|
|
185
|
+
"invalid_config_dimension",
|
|
186
|
+
`Configuration key \`${key}\` must be an integer from 1 to 16384.`,
|
|
187
|
+
"Use a positive viewport size such as 1280."
|
|
188
|
+
);
|
|
189
|
+
return fallback;
|
|
190
|
+
}
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
function stringList(value, fallback, key, diagnostics, file, counter, node) {
|
|
194
|
+
if (value === void 0) return [...fallback];
|
|
195
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item)) {
|
|
196
|
+
diagnostic(
|
|
197
|
+
diagnostics,
|
|
198
|
+
file,
|
|
199
|
+
counter,
|
|
200
|
+
node,
|
|
201
|
+
key,
|
|
202
|
+
"invalid_config_globs",
|
|
203
|
+
`Configuration key \`${key}\` must be a list of nonempty glob strings.`,
|
|
204
|
+
`Write \`${key}: ["**/*.test.yaml"]\`.`
|
|
205
|
+
);
|
|
206
|
+
return [...fallback];
|
|
207
|
+
}
|
|
208
|
+
for (const pattern of value) {
|
|
209
|
+
if (path.isAbsolute(pattern) || pattern.split(/[\\/]/u).includes(".."))
|
|
210
|
+
diagnostic(
|
|
211
|
+
diagnostics,
|
|
212
|
+
file,
|
|
213
|
+
counter,
|
|
214
|
+
node,
|
|
215
|
+
key,
|
|
216
|
+
"unsafe_config_glob",
|
|
217
|
+
`Configuration key \`${key}\` contains a glob outside its test directory.`,
|
|
218
|
+
"Use project-relative glob segments without `..`."
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
return [...value];
|
|
222
|
+
}
|
|
223
|
+
function absoluteUrl(value, key, diagnostics, file, counter, node) {
|
|
224
|
+
if (value === void 0) return null;
|
|
225
|
+
try {
|
|
226
|
+
if (typeof value !== "string") throw new Error("not text");
|
|
227
|
+
const parsed = new URL(value);
|
|
228
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
229
|
+
throw new Error("unsupported protocol");
|
|
230
|
+
return parsed.href;
|
|
231
|
+
} catch {
|
|
232
|
+
diagnostic(
|
|
233
|
+
diagnostics,
|
|
234
|
+
file,
|
|
235
|
+
counter,
|
|
236
|
+
node,
|
|
237
|
+
key,
|
|
238
|
+
"invalid_config_url",
|
|
239
|
+
`Configuration key \`${key}\` must be an absolute HTTP(S) URL.`,
|
|
240
|
+
"Use a URL such as `https://example.com/`."
|
|
241
|
+
);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function findConfig(start) {
|
|
246
|
+
let current = path.resolve(start);
|
|
247
|
+
for (; ; ) {
|
|
248
|
+
const candidate = path.join(current, CONFIG_FILE);
|
|
249
|
+
try {
|
|
250
|
+
await readFile(candidate, "utf8");
|
|
251
|
+
return { root: current, file: candidate };
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (error.code !== "ENOENT")
|
|
254
|
+
throw new ProjectConfigError([
|
|
255
|
+
{
|
|
256
|
+
code: "unreadable_config",
|
|
257
|
+
file: candidate,
|
|
258
|
+
line: 1,
|
|
259
|
+
col: 1,
|
|
260
|
+
key: "<file>",
|
|
261
|
+
message: `Could not read ${CONFIG_FILE}.`,
|
|
262
|
+
fix: "Check the file permissions and try again."
|
|
263
|
+
}
|
|
264
|
+
]);
|
|
265
|
+
}
|
|
266
|
+
const parent = path.dirname(current);
|
|
267
|
+
if (parent === current) return { root: path.resolve(start), file: null };
|
|
268
|
+
current = parent;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function freeze(config) {
|
|
272
|
+
Object.freeze(config.include);
|
|
273
|
+
Object.freeze(config.exclude);
|
|
274
|
+
Object.freeze(config.viewport);
|
|
275
|
+
Object.freeze(config.thresholds);
|
|
276
|
+
Object.freeze(config.variables);
|
|
277
|
+
return Object.freeze(config);
|
|
278
|
+
}
|
|
279
|
+
async function loadProjectConfig(start = process.cwd(), hostEnvironment = process.env, overrides = {}, loadOptions = {}) {
|
|
280
|
+
const found = await findConfig(start);
|
|
281
|
+
const file = found.file ?? path.join(found.root, CONFIG_FILE);
|
|
282
|
+
const counter = new LineCounter();
|
|
283
|
+
const diagnostics = [];
|
|
284
|
+
let raw = {};
|
|
285
|
+
let document = null;
|
|
286
|
+
if (found.file) {
|
|
287
|
+
const contents = await readFile(found.file, "utf8");
|
|
288
|
+
document = parseDocument(contents, {
|
|
289
|
+
lineCounter: counter,
|
|
290
|
+
strict: true,
|
|
291
|
+
uniqueKeys: true
|
|
292
|
+
});
|
|
293
|
+
for (const error of document.errors)
|
|
294
|
+
diagnostic(
|
|
295
|
+
diagnostics,
|
|
296
|
+
file,
|
|
297
|
+
counter,
|
|
298
|
+
void 0,
|
|
299
|
+
"<yaml>",
|
|
300
|
+
"invalid_config_yaml",
|
|
301
|
+
`Could not parse ${CONFIG_FILE}: ${error.message}`,
|
|
302
|
+
"Correct the YAML syntax and duplicate keys."
|
|
303
|
+
);
|
|
304
|
+
let unsafeYaml = false;
|
|
305
|
+
visit(document, {
|
|
306
|
+
Alias(_key, alias) {
|
|
307
|
+
unsafeYaml = true;
|
|
308
|
+
diagnostic(
|
|
309
|
+
diagnostics,
|
|
310
|
+
file,
|
|
311
|
+
counter,
|
|
312
|
+
alias,
|
|
313
|
+
"<yaml>",
|
|
314
|
+
"unsupported_config_alias",
|
|
315
|
+
"YAML aliases are not supported in sedum.config.yaml.",
|
|
316
|
+
"Write the value explicitly instead of using an anchor or alias."
|
|
317
|
+
);
|
|
318
|
+
},
|
|
319
|
+
Node(_key, value2) {
|
|
320
|
+
if ("tag" in value2 && value2.tag) {
|
|
321
|
+
unsafeYaml = true;
|
|
322
|
+
diagnostic(
|
|
323
|
+
diagnostics,
|
|
324
|
+
file,
|
|
325
|
+
counter,
|
|
326
|
+
value2,
|
|
327
|
+
"<yaml>",
|
|
328
|
+
"unsupported_config_tag",
|
|
329
|
+
"YAML tags are not supported in sedum.config.yaml.",
|
|
330
|
+
"Use ordinary YAML scalar, mapping, and sequence values."
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
let value = {};
|
|
336
|
+
if (!unsafeYaml)
|
|
337
|
+
try {
|
|
338
|
+
value = document.toJS({ maxAliasCount: 0 });
|
|
339
|
+
} catch {
|
|
340
|
+
diagnostic(
|
|
341
|
+
diagnostics,
|
|
342
|
+
file,
|
|
343
|
+
counter,
|
|
344
|
+
document.contents,
|
|
345
|
+
"<yaml>",
|
|
346
|
+
"invalid_config_yaml",
|
|
347
|
+
`Could not safely decode ${CONFIG_FILE}.`,
|
|
348
|
+
"Remove aliases, tags, or recursive YAML structures."
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
if (value !== null && !object(value))
|
|
352
|
+
diagnostic(
|
|
353
|
+
diagnostics,
|
|
354
|
+
file,
|
|
355
|
+
counter,
|
|
356
|
+
document.contents,
|
|
357
|
+
"<root>",
|
|
358
|
+
"invalid_config_root",
|
|
359
|
+
`${CONFIG_FILE} must contain a YAML mapping.`,
|
|
360
|
+
"Write configuration as key/value pairs."
|
|
361
|
+
);
|
|
362
|
+
else raw = value ?? {};
|
|
363
|
+
mapUnknownKeys(
|
|
364
|
+
document.contents,
|
|
365
|
+
allowed.root,
|
|
366
|
+
"",
|
|
367
|
+
file,
|
|
368
|
+
counter,
|
|
369
|
+
diagnostics
|
|
370
|
+
);
|
|
371
|
+
const maps = [
|
|
372
|
+
["tests", allowed.tests],
|
|
373
|
+
["viewport", allowed.viewport],
|
|
374
|
+
["thresholds", allowed.thresholds]
|
|
375
|
+
];
|
|
376
|
+
for (const [key, names] of maps)
|
|
377
|
+
mapUnknownKeys(
|
|
378
|
+
document.get(key, true),
|
|
379
|
+
names,
|
|
380
|
+
key,
|
|
381
|
+
file,
|
|
382
|
+
counter,
|
|
383
|
+
diagnostics
|
|
384
|
+
);
|
|
385
|
+
const environmentNode = document.get("environments", true);
|
|
386
|
+
if (isMap(environmentNode))
|
|
387
|
+
for (const pair of environmentNode.items)
|
|
388
|
+
mapUnknownKeys(
|
|
389
|
+
pair.value,
|
|
390
|
+
allowed.environment,
|
|
391
|
+
`environments.${String(pair.key)}`,
|
|
392
|
+
file,
|
|
393
|
+
counter,
|
|
394
|
+
diagnostics
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
const node = (key) => document?.getIn(key.split("."), true);
|
|
398
|
+
const tests = object(raw.tests) ? raw.tests : {};
|
|
399
|
+
if (raw.tests !== void 0 && !object(raw.tests))
|
|
400
|
+
diagnostic(
|
|
401
|
+
diagnostics,
|
|
402
|
+
file,
|
|
403
|
+
counter,
|
|
404
|
+
node("tests"),
|
|
405
|
+
"tests",
|
|
406
|
+
"invalid_config_type",
|
|
407
|
+
"Configuration key `tests` must be a mapping.",
|
|
408
|
+
"Use `tests: { directory: tests }`."
|
|
409
|
+
);
|
|
410
|
+
for (const [key, value] of [
|
|
411
|
+
["viewport", raw.viewport],
|
|
412
|
+
["thresholds", raw.thresholds],
|
|
413
|
+
["environments", raw.environments]
|
|
414
|
+
])
|
|
415
|
+
if (value !== void 0 && !object(value))
|
|
416
|
+
diagnostic(
|
|
417
|
+
diagnostics,
|
|
418
|
+
file,
|
|
419
|
+
counter,
|
|
420
|
+
node(key),
|
|
421
|
+
key,
|
|
422
|
+
"invalid_config_type",
|
|
423
|
+
`Configuration key \`${key}\` must be a mapping.`,
|
|
424
|
+
`Write \`${key}: {}\` and add its documented child keys.`
|
|
425
|
+
);
|
|
426
|
+
const viewport = object(raw.viewport) ? raw.viewport : {};
|
|
427
|
+
const thresholds = object(raw.thresholds) ? raw.thresholds : {};
|
|
428
|
+
const environments = object(raw.environments) ? raw.environments : {};
|
|
429
|
+
for (const [name, value] of Object.entries(environments)) {
|
|
430
|
+
if (!object(value)) {
|
|
431
|
+
diagnostic(
|
|
432
|
+
diagnostics,
|
|
433
|
+
file,
|
|
434
|
+
counter,
|
|
435
|
+
node(`environments.${name}`),
|
|
436
|
+
`environments.${name}`,
|
|
437
|
+
"invalid_config_environment",
|
|
438
|
+
`Environment \`${name}\` must be a mapping.`,
|
|
439
|
+
`Write \`environments.${name}: { baseUrl: https://example.com/ }\`.`
|
|
440
|
+
);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
scalarVariables(
|
|
444
|
+
value.variables,
|
|
445
|
+
`environments.${name}.variables`,
|
|
446
|
+
diagnostics,
|
|
447
|
+
file,
|
|
448
|
+
counter,
|
|
449
|
+
node(`environments.${name}.variables`)
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
const selectedValue = overrides.environment ?? raw.environment;
|
|
453
|
+
const selected = selectedValue === void 0 ? null : selectedValue;
|
|
454
|
+
if (selected !== null && (typeof selected !== "string" || !selected))
|
|
455
|
+
diagnostic(
|
|
456
|
+
diagnostics,
|
|
457
|
+
file,
|
|
458
|
+
counter,
|
|
459
|
+
node("environment"),
|
|
460
|
+
"environment",
|
|
461
|
+
"invalid_config_environment",
|
|
462
|
+
"Configuration key `environment` must name an environment.",
|
|
463
|
+
"Use a nonempty name declared under `environments`."
|
|
464
|
+
);
|
|
465
|
+
const selectedRaw = typeof selected === "string" ? environments[selected] : void 0;
|
|
466
|
+
if (typeof selected === "string" && !object(selectedRaw))
|
|
467
|
+
diagnostic(
|
|
468
|
+
diagnostics,
|
|
469
|
+
file,
|
|
470
|
+
counter,
|
|
471
|
+
node("environment"),
|
|
472
|
+
"environment",
|
|
473
|
+
"unknown_config_environment",
|
|
474
|
+
`Environment \`${selected}\` is not declared.`,
|
|
475
|
+
`Add \`environments.${selected}\` or choose an existing environment.`
|
|
476
|
+
);
|
|
477
|
+
const environment = object(selectedRaw) ? selectedRaw : {};
|
|
478
|
+
const browserValue = overrides.browser ?? raw.browser ?? DEFAULTS.browser;
|
|
479
|
+
const browser = browserValue === "chrome" || browserValue === "chromium" ? browserValue : DEFAULTS.browser;
|
|
480
|
+
if (browserValue !== "chrome" && browserValue !== "chromium")
|
|
481
|
+
diagnostic(
|
|
482
|
+
diagnostics,
|
|
483
|
+
file,
|
|
484
|
+
counter,
|
|
485
|
+
node("browser"),
|
|
486
|
+
"browser",
|
|
487
|
+
"invalid_config_browser",
|
|
488
|
+
"Configuration key `browser` must be `chrome` or `chromium`.",
|
|
489
|
+
"Choose one of the supported browser names."
|
|
490
|
+
);
|
|
491
|
+
const verify = probability(
|
|
492
|
+
overrides.thresholds?.minP ?? thresholds.verify,
|
|
493
|
+
DEFAULTS.thresholds.minP,
|
|
494
|
+
"thresholds.verify",
|
|
495
|
+
diagnostics,
|
|
496
|
+
file,
|
|
497
|
+
counter,
|
|
498
|
+
node("thresholds.verify")
|
|
499
|
+
);
|
|
500
|
+
const band = probability(
|
|
501
|
+
overrides.thresholds?.band ?? thresholds.lowConfidenceBand,
|
|
502
|
+
DEFAULTS.thresholds.band,
|
|
503
|
+
"thresholds.lowConfidenceBand",
|
|
504
|
+
diagnostics,
|
|
505
|
+
file,
|
|
506
|
+
counter,
|
|
507
|
+
node("thresholds.lowConfidenceBand")
|
|
508
|
+
);
|
|
509
|
+
const contradictionCutoff = probability(
|
|
510
|
+
overrides.thresholds?.contradictionCutoff ?? thresholds.contradiction,
|
|
511
|
+
DEFAULTS.thresholds.contradictionCutoff,
|
|
512
|
+
"thresholds.contradiction",
|
|
513
|
+
diagnostics,
|
|
514
|
+
file,
|
|
515
|
+
counter,
|
|
516
|
+
node("thresholds.contradiction")
|
|
517
|
+
);
|
|
518
|
+
if (band > verify)
|
|
519
|
+
diagnostic(
|
|
520
|
+
diagnostics,
|
|
521
|
+
file,
|
|
522
|
+
counter,
|
|
523
|
+
node("thresholds.lowConfidenceBand"),
|
|
524
|
+
"thresholds.lowConfidenceBand",
|
|
525
|
+
"invalid_threshold_policy",
|
|
526
|
+
"The low-confidence band cannot exceed the verify threshold.",
|
|
527
|
+
"Lower `lowConfidenceBand` or raise `verify`."
|
|
528
|
+
);
|
|
529
|
+
const baseUrl = absoluteUrl(
|
|
530
|
+
overrides.baseUrl ?? environment.baseUrl ?? raw.baseUrl,
|
|
531
|
+
environment.baseUrl !== void 0 ? `environments.${String(selected)}.baseUrl` : "baseUrl",
|
|
532
|
+
diagnostics,
|
|
533
|
+
file,
|
|
534
|
+
counter,
|
|
535
|
+
node(
|
|
536
|
+
environment.baseUrl !== void 0 ? `environments.${String(selected)}.baseUrl` : "baseUrl"
|
|
537
|
+
)
|
|
538
|
+
);
|
|
539
|
+
const rootVariables = scalarVariables(
|
|
540
|
+
raw.variables,
|
|
541
|
+
"variables",
|
|
542
|
+
diagnostics,
|
|
543
|
+
file,
|
|
544
|
+
counter,
|
|
545
|
+
node("variables")
|
|
546
|
+
);
|
|
547
|
+
const selectedVariables = scalarVariables(
|
|
548
|
+
environment.variables,
|
|
549
|
+
`environments.${String(selected)}.variables`,
|
|
550
|
+
diagnostics,
|
|
551
|
+
file,
|
|
552
|
+
counter,
|
|
553
|
+
node(`environments.${String(selected)}.variables`)
|
|
554
|
+
);
|
|
555
|
+
let fileEnvironment = {};
|
|
556
|
+
const environmentFile = path.join(found.root, ".env");
|
|
557
|
+
try {
|
|
558
|
+
if (loadOptions.readEnvironmentFile !== false)
|
|
559
|
+
fileEnvironment = parseEnv(await readFile(environmentFile, "utf8"));
|
|
560
|
+
} catch (error) {
|
|
561
|
+
if (error.code !== "ENOENT")
|
|
562
|
+
diagnostic(
|
|
563
|
+
diagnostics,
|
|
564
|
+
environmentFile,
|
|
565
|
+
counter,
|
|
566
|
+
void 0,
|
|
567
|
+
"<file>",
|
|
568
|
+
"invalid_env_file",
|
|
569
|
+
"Could not read or parse the project-root .env file.",
|
|
570
|
+
"Correct its dotenv syntax and permissions, or remove it."
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
const include = stringList(
|
|
574
|
+
tests.include,
|
|
575
|
+
DEFAULTS.include,
|
|
576
|
+
"tests.include",
|
|
577
|
+
diagnostics,
|
|
578
|
+
file,
|
|
579
|
+
counter,
|
|
580
|
+
node("tests.include")
|
|
581
|
+
);
|
|
582
|
+
const exclude = stringList(
|
|
583
|
+
tests.exclude,
|
|
584
|
+
DEFAULTS.exclude,
|
|
585
|
+
"tests.exclude",
|
|
586
|
+
diagnostics,
|
|
587
|
+
file,
|
|
588
|
+
counter,
|
|
589
|
+
node("tests.exclude")
|
|
590
|
+
);
|
|
591
|
+
if (include.length === 0)
|
|
592
|
+
diagnostic(
|
|
593
|
+
diagnostics,
|
|
594
|
+
file,
|
|
595
|
+
counter,
|
|
596
|
+
node("tests.include"),
|
|
597
|
+
"tests.include",
|
|
598
|
+
"empty_config_globs",
|
|
599
|
+
"Configuration key `tests.include` must select at least one pattern.",
|
|
600
|
+
"Add `**/*.test.yaml` or another test glob."
|
|
601
|
+
);
|
|
602
|
+
const variables = {
|
|
603
|
+
...rootVariables,
|
|
604
|
+
...selectedVariables,
|
|
605
|
+
...fileEnvironment,
|
|
606
|
+
...hostEnvironment
|
|
607
|
+
};
|
|
608
|
+
const apiKey = hostEnvironment.TYPESAFE_API_KEY?.trim() || fileEnvironment.TYPESAFE_API_KEY?.trim() || void 0;
|
|
609
|
+
const testDirectory = relativePath(
|
|
610
|
+
found.root,
|
|
611
|
+
tests.directory,
|
|
612
|
+
DEFAULTS.testDirectory,
|
|
613
|
+
"tests.directory",
|
|
614
|
+
diagnostics,
|
|
615
|
+
file,
|
|
616
|
+
counter,
|
|
617
|
+
node("tests.directory")
|
|
618
|
+
);
|
|
619
|
+
const outputDir = relativePath(
|
|
620
|
+
found.root,
|
|
621
|
+
overrides.outputDir ?? raw.outputDir,
|
|
622
|
+
DEFAULTS.outputDir,
|
|
623
|
+
"outputDir",
|
|
624
|
+
diagnostics,
|
|
625
|
+
file,
|
|
626
|
+
counter,
|
|
627
|
+
node("outputDir")
|
|
628
|
+
);
|
|
629
|
+
const reporterDir = relativePath(
|
|
630
|
+
found.root,
|
|
631
|
+
overrides.reporterDir ?? raw.reporterDir,
|
|
632
|
+
DEFAULTS.reporterDir,
|
|
633
|
+
"reporterDir",
|
|
634
|
+
diagnostics,
|
|
635
|
+
file,
|
|
636
|
+
counter,
|
|
637
|
+
node("reporterDir")
|
|
638
|
+
);
|
|
639
|
+
const width = positiveInteger(
|
|
640
|
+
overrides.viewport?.width ?? viewport.width,
|
|
641
|
+
DEFAULTS.viewport.width,
|
|
642
|
+
"viewport.width",
|
|
643
|
+
diagnostics,
|
|
644
|
+
file,
|
|
645
|
+
counter,
|
|
646
|
+
node("viewport.width")
|
|
647
|
+
);
|
|
648
|
+
const height = positiveInteger(
|
|
649
|
+
overrides.viewport?.height ?? viewport.height,
|
|
650
|
+
DEFAULTS.viewport.height,
|
|
651
|
+
"viewport.height",
|
|
652
|
+
diagnostics,
|
|
653
|
+
file,
|
|
654
|
+
counter,
|
|
655
|
+
node("viewport.height")
|
|
656
|
+
);
|
|
657
|
+
if (diagnostics.length) throw new ProjectConfigError(diagnostics);
|
|
658
|
+
return freeze({
|
|
659
|
+
projectRoot: found.root,
|
|
660
|
+
configPath: found.file,
|
|
661
|
+
environment: typeof selected === "string" ? selected : null,
|
|
662
|
+
testDirectory,
|
|
663
|
+
include,
|
|
664
|
+
exclude,
|
|
665
|
+
browser,
|
|
666
|
+
viewport: { width, height },
|
|
667
|
+
thresholds: { minP: verify, band, contradictionCutoff },
|
|
668
|
+
outputDir,
|
|
669
|
+
reporterDir,
|
|
670
|
+
baseUrl,
|
|
671
|
+
variables,
|
|
672
|
+
apiKey
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
async function discoverConfiguredTests(config) {
|
|
676
|
+
const files = [];
|
|
677
|
+
async function visit2(directory) {
|
|
678
|
+
let entries;
|
|
679
|
+
try {
|
|
680
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
681
|
+
} catch (error) {
|
|
682
|
+
if (error.code === "ENOENT") return;
|
|
683
|
+
throw error;
|
|
684
|
+
}
|
|
685
|
+
for (const entry of entries) {
|
|
686
|
+
if (entry.isSymbolicLink()) continue;
|
|
687
|
+
const absolute = path.join(directory, entry.name);
|
|
688
|
+
if (entry.isDirectory()) await visit2(absolute);
|
|
689
|
+
else if (entry.isFile()) {
|
|
690
|
+
const relative = path.relative(config.testDirectory, absolute).split(path.sep).join("/");
|
|
691
|
+
if (relative.endsWith(".test.yaml") && config.include.some((pattern) => minimatch(relative, pattern)) && !config.exclude.some((pattern) => minimatch(relative, pattern)))
|
|
692
|
+
files.push(absolute);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
await visit2(config.testDirectory);
|
|
697
|
+
return files.sort((left, right) => left.localeCompare(right));
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export {
|
|
701
|
+
ProjectConfigError,
|
|
702
|
+
loadProjectConfig,
|
|
703
|
+
discoverConfiguredTests
|
|
704
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|