@jskit-ai/jskit-catalog 0.2.48 → 0.2.50
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/catalog/packages.json +266 -261
- package/package.json +1 -1
- package/scripts/jskit.mjs +3 -1
- package/scripts/test-command.mjs +22 -0
package/package.json
CHANGED
package/scripts/jskit.mjs
CHANGED
|
@@ -67,7 +67,9 @@ function usage() {
|
|
|
67
67
|
" (at least 1). A file whose first line is `// jskit-test: alone - <reason>` runs after the others,",
|
|
68
68
|
" on its own. With --databases, each file running at once gets its own copy of TEST_DB_NAME,",
|
|
69
69
|
" restored from a schema snapshot (the app's knexfile.js and @jskit-ai/database-runtime); with no",
|
|
70
|
-
" usable TEST_DB_NAME, the files run one at a time on the connected database.",
|
|
70
|
+
" usable TEST_DB_NAME, the files run one at a time on the connected database. Given no files, it",
|
|
71
|
+
" fails when a file under tests/ is named as a test (x.integration.js, x.spec.js) that node's",
|
|
72
|
+
" default pattern would leave out; a database test is named x.integration.test.js.",
|
|
71
73
|
"",
|
|
72
74
|
"<locale> is a BCP 47 language tag, such as fr or pt-BR."
|
|
73
75
|
].join("\n");
|
package/scripts/test-command.mjs
CHANGED
|
@@ -15,11 +15,18 @@ import { reportTestTimes, writeFileStops } from "./test-time-report.mjs";
|
|
|
15
15
|
// first line, `// jskit-test: alone - <reason>`, and runs after the others, one such file at a time. That second run
|
|
16
16
|
// writes a reporter's file destination beside the first run's (`<name>.alone<ext>`) instead of over it, and with
|
|
17
17
|
// --test-shard=<index>/<total> it runs only its shard's alone files, picked the way node --test picks a shard's files.
|
|
18
|
+
// Given no files, it fails instead of leaving out a file under tests/ named as a test that node's default misses.
|
|
18
19
|
// Every run also reports to test-time-report.mjs, which times the command's files against coarse bounds, and preloads
|
|
19
20
|
// test-file-stop.mjs, which stops a file still running at a generous multiple of its time.
|
|
20
21
|
|
|
21
22
|
// node --test's own default (Node 26) when it is given no files.
|
|
22
23
|
const DEFAULT_PATTERN = "**/{test,test/**/*,test-*,*[._-]test}.{js,mjs,cjs,ts,mts,cts}";
|
|
24
|
+
// Files under a tests/ folder named as tests that the default leaves out (`x.integration.js`, `x.spec.js`, `x.tests.js`);
|
|
25
|
+
// every file under a test/ folder already matches it. Files in Playwright's e2e and browser folders, and files that
|
|
26
|
+
// import Vitest or Playwright, belong to those runners.
|
|
27
|
+
const TEST_LIKE_PATTERN = "**/tests/**/*[._-]{integration,spec,specs,tests}.{js,mjs,cjs,ts,mts,cts}";
|
|
28
|
+
const OTHER_RUNNER_FOLDER = /(?:^|\/)(?:e2e|browser)\//u;
|
|
29
|
+
const OTHER_RUNNER_IMPORT = /\b(?:from|import|require)\s*\(?\s*["'](?:vitest|@playwright\/test)["']/u;
|
|
23
30
|
const MARKER = /^\s*\/\/\s*jskit-test:(.*)$/u;
|
|
24
31
|
const ALONE = /^\s*alone\s+-\s+(\S.*)$/u;
|
|
25
32
|
const SHARD = "--test-shard";
|
|
@@ -40,6 +47,13 @@ function findTestFiles(patterns, cwd) {
|
|
|
40
47
|
return [...new Set(files)].sort();
|
|
41
48
|
}
|
|
42
49
|
|
|
50
|
+
/** The files named as Node tests that a run of node's default files would silently leave out. */
|
|
51
|
+
function missedTestFiles(defaultFiles, cwd) {
|
|
52
|
+
const found = new Set(defaultFiles);
|
|
53
|
+
return findTestFiles([TEST_LIKE_PATTERN], cwd).filter((file) => !found.has(file) && !OTHER_RUNNER_FOLDER.test(file) &&
|
|
54
|
+
!OTHER_RUNNER_IMPORT.test(readFileSync(path.resolve(cwd, file), "utf8")));
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
/**
|
|
44
58
|
* The files of a run that must run alone, from their first line. A marker that is malformed or not on the first line
|
|
45
59
|
* (after a shebang) is an error, so a file never runs in parallel because its marker was missed.
|
|
@@ -113,6 +127,14 @@ function planTestRuns(args, { cwd = process.cwd(), concurrency = testConcurrency
|
|
|
113
127
|
const matched = new Map(candidates.map((candidate) => [candidate, findTestFiles([candidate], cwd)]));
|
|
114
128
|
const named = [...new Set([...matched.values()].flat())].sort();
|
|
115
129
|
const files = named.length > 0 ? named : findTestFiles([DEFAULT_PATTERN], cwd);
|
|
130
|
+
const missed = named.length > 0 ? [] : missedTestFiles(files, cwd);
|
|
131
|
+
if (missed.length > 0) {
|
|
132
|
+
throw new Error("jskit test: given no files, node --test runs only the files its default pattern matches " +
|
|
133
|
+
"(test.js, test-*.js, *.test.js, *_test.js, *-test.js, or any file under a test/ folder), so these test files " +
|
|
134
|
+
"would never run:\n" +
|
|
135
|
+
`- ${missed.join("\n- ")}\nRename each to end in .test.js (a database test: <name>.integration.test.js), or ` +
|
|
136
|
+
"name the files to run.");
|
|
137
|
+
}
|
|
116
138
|
const { alone, problems } = readAloneFiles(files, cwd);
|
|
117
139
|
if (problems.length > 0) throw new Error(`jskit test:\n- ${problems.join("\n- ")}`);
|
|
118
140
|
const parallel = ["--test", `--test-concurrency=${concurrency}`];
|