@diagonal-hq/cli 0.31.0 → 0.32.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/dist/cli.mjs +70 -12
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -289115,6 +289115,13 @@ function packageName(specifier) {
|
|
|
289115
289115
|
const parts = specifier.split("/");
|
|
289116
289116
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
289117
289117
|
}
|
|
289118
|
+
var TEST_SOURCE_PREFIX = "tests/";
|
|
289119
|
+
function testSourceImportMessage(from, target) {
|
|
289120
|
+
if (!target.startsWith(TEST_SOURCE_PREFIX) || from.startsWith(TEST_SOURCE_PREFIX)) {
|
|
289121
|
+
return null;
|
|
289122
|
+
}
|
|
289123
|
+
return `${from} imports ${target}. Only a file of tests/ can import a file of tests/. Move the shared code to another folder, such as lib/`;
|
|
289124
|
+
}
|
|
289118
289125
|
function resolveLocalSpecifier(root, from, specifier) {
|
|
289119
289126
|
return localCandidates(from, specifier).find((candidate) => isExactFile(join(root, candidate))) ?? null;
|
|
289120
289127
|
}
|
|
@@ -313309,6 +313316,12 @@ function checkModuleImports(root, path, ast, packages) {
|
|
|
313309
313316
|
blocksUnitBuild ||= importType === "app" && !found2.dynamic;
|
|
313310
313317
|
continue;
|
|
313311
313318
|
}
|
|
313319
|
+
const testSource = testSourceImportMessage(path, target);
|
|
313320
|
+
if (testSource !== null) {
|
|
313321
|
+
diagnostics.push(diagnosticAt(path, found2.node, testSource));
|
|
313322
|
+
blocksUnitBuild = true;
|
|
313323
|
+
continue;
|
|
313324
|
+
}
|
|
313312
313325
|
if (GENERATED_IMPORT_KINDS.has(target)) {
|
|
313313
313326
|
imports.push({
|
|
313314
313327
|
specifier: found2.specifier,
|
|
@@ -313589,6 +313602,10 @@ function appImportsOf(root, path, ast, { ui = false } = {}) {
|
|
|
313589
313602
|
statement2.source
|
|
313590
313603
|
);
|
|
313591
313604
|
}
|
|
313605
|
+
const testSource = testSourceImportMessage(path, target);
|
|
313606
|
+
if (testSource !== null) {
|
|
313607
|
+
throw new SourceError(testSource, statement2.source);
|
|
313608
|
+
}
|
|
313592
313609
|
imports.push({ statement: statement2, specifier: statement2.source.value, path: target, from: path });
|
|
313593
313610
|
}
|
|
313594
313611
|
return imports;
|
|
@@ -313676,6 +313693,10 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
|
|
|
313676
313693
|
statement2.source
|
|
313677
313694
|
);
|
|
313678
313695
|
}
|
|
313696
|
+
const testSource = testSourceImportMessage(path, target);
|
|
313697
|
+
if (testSource !== null) {
|
|
313698
|
+
throw new SourceError(testSource, statement2.source);
|
|
313699
|
+
}
|
|
313679
313700
|
requires[specifier] = target;
|
|
313680
313701
|
pending.push(target);
|
|
313681
313702
|
}
|
|
@@ -321500,7 +321521,7 @@ var TEST_DEFINE = "defineTest";
|
|
|
321500
321521
|
var TEST_FILE_PATTERN = /^tests\/[^/]+\/([^/]+)\.ts$/;
|
|
321501
321522
|
var SPLIT_TEST_FILE_PATTERN = /\.(browser|setup|assert)$/;
|
|
321502
321523
|
var TEST_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,99}$/;
|
|
321503
|
-
var SUITE_PROPERTIES = /* @__PURE__ */ new Set(["uid", "name", "description"]);
|
|
321524
|
+
var SUITE_PROPERTIES = /* @__PURE__ */ new Set(["uid", "name", "description", "order"]);
|
|
321504
321525
|
var TEST_PROPERTIES = /* @__PURE__ */ new Set(["name", "description", "enabled", "timeoutSeconds"]);
|
|
321505
321526
|
var HANDLERS = ["setup", "test", "assert"];
|
|
321506
321527
|
var TEST_FIXTURES = /* @__PURE__ */ new Set(["page", "context", "request", "browser", "expect", "Sdk", "ctx"]);
|
|
@@ -321605,7 +321626,50 @@ function readSuite(file2, report) {
|
|
|
321605
321626
|
{ allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename13(dirname8(file2.path)) },
|
|
321606
321627
|
report
|
|
321607
321628
|
);
|
|
321608
|
-
|
|
321629
|
+
if (read2 === null) {
|
|
321630
|
+
return null;
|
|
321631
|
+
}
|
|
321632
|
+
const order = read2.value.order ?? null;
|
|
321633
|
+
if (order !== null && (!Array.isArray(order) || order.some((key) => typeof key !== "string" || !TEST_KEY_PATTERN.test(key)))) {
|
|
321634
|
+
read2.problem(read2.at("order"), '"order" must list test keys, the file names of the tests without .ts');
|
|
321635
|
+
return null;
|
|
321636
|
+
}
|
|
321637
|
+
if (order !== null && order.length > MAX_TESTS_PER_SUITE) {
|
|
321638
|
+
read2.problem(read2.at("order"), `"order" can list at most ${MAX_TESTS_PER_SUITE} tests`);
|
|
321639
|
+
return null;
|
|
321640
|
+
}
|
|
321641
|
+
const seen = /* @__PURE__ */ new Set();
|
|
321642
|
+
const repeated = order?.find((key) => seen.has(key) || !seen.add(key));
|
|
321643
|
+
if (repeated !== void 0) {
|
|
321644
|
+
read2.problem(read2.at("order"), `"order" lists the test "${repeated}" more than once`);
|
|
321645
|
+
return null;
|
|
321646
|
+
}
|
|
321647
|
+
return { name: read2.name, description: read2.description, order, value: read2.value };
|
|
321648
|
+
}
|
|
321649
|
+
function testSettings({ value, at, problem: problem2 }) {
|
|
321650
|
+
if (value.enabled !== void 0 && typeof value.enabled !== "boolean") {
|
|
321651
|
+
problem2(at("enabled"), '"enabled" must be true or false');
|
|
321652
|
+
return null;
|
|
321653
|
+
}
|
|
321654
|
+
const timeout = value.timeoutSeconds ?? null;
|
|
321655
|
+
if (timeout !== null && (!Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)) {
|
|
321656
|
+
problem2(at("timeoutSeconds"), `"timeoutSeconds" must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`);
|
|
321657
|
+
return null;
|
|
321658
|
+
}
|
|
321659
|
+
return { enabled: value.enabled ?? true, timeout_seconds: timeout };
|
|
321660
|
+
}
|
|
321661
|
+
function orderedTests(files, order, report) {
|
|
321662
|
+
const byName = files.toSorted((left, right) => left.path < right.path ? -1 : 1);
|
|
321663
|
+
if (order === null) {
|
|
321664
|
+
return byName;
|
|
321665
|
+
}
|
|
321666
|
+
const byKey = new Map(byName.map((file2) => [TEST_FILE_PATTERN.exec(file2.path)[1], file2]));
|
|
321667
|
+
const missing = order.filter((key) => !byKey.has(key));
|
|
321668
|
+
if (missing.length > 0) {
|
|
321669
|
+
report(null, `"order" lists ${missing.map((key) => `"${key}"`).join(", ")}, which this folder has no test file for`);
|
|
321670
|
+
}
|
|
321671
|
+
const listed = order.filter((key) => byKey.has(key)).map((key) => byKey.get(key));
|
|
321672
|
+
return [...listed, ...byName.filter((file2) => !listed.includes(file2))];
|
|
321609
321673
|
}
|
|
321610
321674
|
function readHandlers(node, report) {
|
|
321611
321675
|
if (node.type !== "ObjectExpression") {
|
|
@@ -321862,17 +321926,11 @@ function buildTest(file2, context, diagnostics) {
|
|
|
321862
321926
|
if (config === null || handlers === null) {
|
|
321863
321927
|
return null;
|
|
321864
321928
|
}
|
|
321865
|
-
const
|
|
321866
|
-
if (
|
|
321867
|
-
problem2(at("enabled"), '"enabled" must be true or false');
|
|
321868
|
-
return null;
|
|
321869
|
-
}
|
|
321870
|
-
const timeout = value.timeoutSeconds ?? null;
|
|
321871
|
-
if (timeout !== null && (!Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)) {
|
|
321872
|
-
problem2(at("timeoutSeconds"), `"timeoutSeconds" must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`);
|
|
321929
|
+
const settings = testSettings(config);
|
|
321930
|
+
if (settings === null) {
|
|
321873
321931
|
return null;
|
|
321874
321932
|
}
|
|
321875
|
-
const enabled2
|
|
321933
|
+
const { enabled: enabled2, timeout_seconds: timeout } = settings;
|
|
321876
321934
|
const code2 = readTestFunction(handlers.test, file2.source, file2.ast, enabled2, report);
|
|
321877
321935
|
if (code2 === null) {
|
|
321878
321936
|
return null;
|
|
@@ -321950,7 +322008,7 @@ function buildTestSuites({
|
|
|
321950
322008
|
for (const suite of suites) {
|
|
321951
322009
|
const directory = dirname8(suite.path);
|
|
321952
322010
|
const read2 = readSuite(suite, report(suite.path));
|
|
321953
|
-
const files = (testsByDirectory.get(directory) ?? []
|
|
322011
|
+
const files = orderedTests(testsByDirectory.get(directory) ?? [], read2?.order ?? null, report(suite.path));
|
|
321954
322012
|
if (files.length > MAX_TESTS_PER_SUITE) {
|
|
321955
322013
|
report(suite.path)(null, `A suite can hold at most ${MAX_TESTS_PER_SUITE} tests`);
|
|
321956
322014
|
continue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1236,6 +1236,11 @@ export type TestSuiteDefinition = UidOption & {
|
|
|
1236
1236
|
name?: string;
|
|
1237
1237
|
/** Up to 5,000 characters. */
|
|
1238
1238
|
description?: string | null;
|
|
1239
|
+
/**
|
|
1240
|
+
* The run order of the tests, by test key: the file name without `.ts`. The tests that the list
|
|
1241
|
+
* leaves out run after the listed tests, in the order of their file names. Default: file name order.
|
|
1242
|
+
*/
|
|
1243
|
+
order?: readonly string[];
|
|
1239
1244
|
};
|
|
1240
1245
|
|
|
1241
1246
|
export declare function defineTestSuite<const T extends TestSuiteDefinition>(suite: T): T;
|