@jskit-ai/jskit-catalog 0.2.103 → 0.2.104
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 +180 -176
- package/package.json +1 -1
- package/scripts/browser-test-server.mjs +48 -0
- package/scripts/browser-test-servers.mjs +40 -10
- package/scripts/jskit.mjs +13 -1
- package/scripts/project-packages.mjs +6 -3
- package/scripts/test-command.mjs +3 -1
- package/scripts/test-databases.mjs +7 -3
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// `jskit browser-test-server [host] [port]`: the app as a host serves it for a browser test run, such as a Vibe64 Outputs
|
|
2
|
+
// target with `Data: test`. It is one worker of a local run (browser-tests.mjs, browser-test-servers.mjs), read from the
|
|
3
|
+
// app's own playwright.config.mjs: the production build, the database the app's `prepare` module gives that worker (its
|
|
4
|
+
// own copy of BROWSER_TEST_DB_NAME in the database patterns), the test-only `env` and APP_ENV=test, on the host's address
|
|
5
|
+
// in place of the run's own port. The host's suite then runs against it as a managed target (PLAYWRIGHT_BASE_URL),
|
|
6
|
+
// signed in with the login state its host supplies, so this server signs nothing in. The host and port come from the
|
|
7
|
+
// arguments, else HOST and PORT. The app server's output also reaches this command's own; stopping the command stops it.
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { SETTINGS_VARIABLE } from "./browser-tests.mjs";
|
|
13
|
+
|
|
14
|
+
const CONFIG_FILES = Object.freeze(["playwright.config.mjs", "playwright.config.js"]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Serves the app in `appRoot` as one browser test server, until it is stopped.
|
|
18
|
+
* @param {string[]} args `[host, port]`, either of which may be left to HOST and PORT.
|
|
19
|
+
* @param {Record<string, string | undefined>} [environment] This process's environment, given the run's settings.
|
|
20
|
+
* @param {string} [appRoot]
|
|
21
|
+
*/
|
|
22
|
+
async function serveBrowserTestTarget(args = [], environment = process.env, appRoot = process.cwd()) {
|
|
23
|
+
if (args.length > 2) throw new Error("Usage: jskit browser-test-server [host] [port]");
|
|
24
|
+
const host = String(args[0] || environment.HOST || "").trim() || "127.0.0.1";
|
|
25
|
+
const port = String(args[1] || environment.PORT || "").trim();
|
|
26
|
+
if (!/^[1-9]\d{0,4}$/u.test(port) || Number(port) > 65_535) {
|
|
27
|
+
throw new Error(`jskit browser-test-server needs the port to serve on, as its second argument or PORT, not ${port || "nothing"}.`);
|
|
28
|
+
}
|
|
29
|
+
// What a local run's config reads for one worker on this port. A suite runner's settings left in a host's environment
|
|
30
|
+
// (its managed target, login state, worker count or index) are not this server's.
|
|
31
|
+
for (const name of ["PLAYWRIGHT_BASE_URL", "PLAYWRIGHT_STORAGE_STATE", "TEST_PARALLEL_INDEX"]) delete environment[name];
|
|
32
|
+
Object.assign(environment, { PLAYWRIGHT_PORT: port, PLAYWRIGHT_WORKERS: "1" });
|
|
33
|
+
const config = CONFIG_FILES.map((name) => path.join(appRoot, name)).find((file) => existsSync(file));
|
|
34
|
+
const loaded = config ? (await import(pathToFileURL(config).href)).default : null;
|
|
35
|
+
const settings = loaded?.webServer?.env?.[SETTINGS_VARIABLE];
|
|
36
|
+
if (!settings) {
|
|
37
|
+
throw new Error(`jskit browser-test-server serves the app as its Playwright config's browserTestConfig() describes, and ` +
|
|
38
|
+
`${config ? path.basename(config) : "playwright.config.mjs"} ${config ? "does not use it" : "is missing"}: export ` +
|
|
39
|
+
"defineConfig(browserTestConfig({ ... })) from @jskit-ai/jskit-catalog/browser-tests there.");
|
|
40
|
+
}
|
|
41
|
+
const served = { ...JSON.parse(settings), host, terminal: true };
|
|
42
|
+
delete served.signIn;
|
|
43
|
+
delete served.signedInStates;
|
|
44
|
+
environment[SETTINGS_VARIABLE] = JSON.stringify(served);
|
|
45
|
+
await import("./browser-test-servers.mjs");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { serveBrowserTestTarget };
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// ends the run. A port that already answers is refused before anything is built or started: a server left there by an
|
|
8
8
|
// earlier run would answer for this run's. Stopped by Playwright (SIGTERM), by Ctrl-C, or by the end of the stdin pipe
|
|
9
9
|
// Playwright gives its webServer (a Playwright that ended without stopping it), the launcher stops its servers and
|
|
10
|
-
// waits for them, within Playwright's grace, before it
|
|
10
|
+
// waits for them, then drops the numbered database copies the prepare module made, within Playwright's grace, before it
|
|
11
|
+
// exits; it drops them too when its start fails. `jskit browser-test-server` (browser-test-server.mjs) runs it
|
|
12
|
+
// for one server a host starts, with `terminal`: that server's output also reaches the launcher's own.
|
|
11
13
|
import { spawn } from "node:child_process";
|
|
12
14
|
import { once } from "node:events";
|
|
13
15
|
import { createWriteStream, fstatSync, mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -22,8 +24,13 @@ import { useTestAppEnvironment } from "./test-environment.mjs";
|
|
|
22
24
|
const SETTINGS_VARIABLE = "JSKIT_BROWSER_TESTS";
|
|
23
25
|
const LOG_DIRECTORY = path.join("test-results", "browser-test-servers");
|
|
24
26
|
const READY_TIMEOUT_MS = 60_000;
|
|
25
|
-
// Within the 10 s gracefulShutdown browser-tests.mjs gives Playwright's webServer
|
|
26
|
-
|
|
27
|
+
// Within the 10 s gracefulShutdown browser-tests.mjs gives Playwright's webServer: the servers stop first (one still
|
|
28
|
+
// running then is killed), since a server's sessions keep its database copy, then the copies are dropped.
|
|
29
|
+
const STOP_WAIT_MS = 4_000;
|
|
30
|
+
const DROP_WAIT_MS = 5_000;
|
|
31
|
+
// Where database-runtime's prepareTestDatabases() keeps, in this process, each set of numbered copies it made with its
|
|
32
|
+
// drop: the app's prepare module loads the app's own copy of that package, so the launcher reads them here.
|
|
33
|
+
const PREPARED_COPIES = Symbol.for("@jskit-ai/database-runtime/preparedTestDatabaseCopies");
|
|
27
34
|
|
|
28
35
|
const seconds = (since) => `${((performance.now() - since) / 1000).toFixed(1)}s`;
|
|
29
36
|
const words = (command) => String(command).trim().split(/\s+/u).filter(Boolean);
|
|
@@ -95,17 +102,33 @@ async function waitUntilReady(url, server, name) {
|
|
|
95
102
|
|
|
96
103
|
const servers = [];
|
|
97
104
|
let stopping = false;
|
|
105
|
+
// The prepare module's work, which a stop waits for (within DROP_WAIT_MS) so the copies it is making are dropped too.
|
|
106
|
+
let preparing = Promise.resolve();
|
|
98
107
|
const running = (server) => server.exitCode === null && server.signalCode === null;
|
|
108
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms, false));
|
|
99
109
|
function stopServers() {
|
|
100
110
|
stopping = true;
|
|
101
111
|
for (const server of servers) if (running(server)) server.kill("SIGTERM");
|
|
102
112
|
}
|
|
113
|
+
/** Drops every set of numbered copies prepare made, once the servers have exited, and says what it did. */
|
|
114
|
+
async function dropPreparedCopies(exited) {
|
|
115
|
+
await Promise.all([preparing.catch(() => {}), exited]);
|
|
116
|
+
const drops = [...(globalThis[PREPARED_COPIES]?.values() ?? [])];
|
|
117
|
+
for (const report of await Promise.all(drops.map((drop) => drop()))) if (report) console.log(`[browser-tests] ${report}.`);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
103
120
|
async function stopAndExit(code) {
|
|
104
121
|
if (stopping) return;
|
|
105
122
|
stopServers();
|
|
106
123
|
const stopped = Promise.all(servers.filter(running).map((server) => once(server, "exit")));
|
|
107
|
-
await Promise.race([stopped,
|
|
108
|
-
|
|
124
|
+
await Promise.race([stopped, delay(STOP_WAIT_MS)]);
|
|
125
|
+
const killed = servers.filter(running);
|
|
126
|
+
for (const server of killed) server.kill("SIGKILL");
|
|
127
|
+
const exited = Promise.all(killed.map((server) => once(server, "exit")));
|
|
128
|
+
if (!(await Promise.race([dropPreparedCopies(exited), delay(DROP_WAIT_MS)]))) {
|
|
129
|
+
console.error(`[browser-tests] The prepared test database copies were not all dropped within ${DROP_WAIT_MS / 1000}s; ` +
|
|
130
|
+
"the next run makes them afresh and drops them.");
|
|
131
|
+
}
|
|
109
132
|
process.exit(code);
|
|
110
133
|
}
|
|
111
134
|
process.once("SIGINT", () => stopAndExit(130));
|
|
@@ -122,7 +145,7 @@ const started = performance.now();
|
|
|
122
145
|
const appRoot = process.cwd();
|
|
123
146
|
const {
|
|
124
147
|
workers, host, basePort, server, build, prepare, env, health, workerEnvironments: workerEnvironmentsFile, signIn,
|
|
125
|
-
signedInStates
|
|
148
|
+
signedInStates, terminal
|
|
126
149
|
} = JSON.parse(process.env[SETTINGS_VARIABLE] || "{}");
|
|
127
150
|
// The servers, and the databases prepared for them, are APP_ENV=test.
|
|
128
151
|
useTestAppEnvironment(process.env, "jskit browser tests");
|
|
@@ -131,10 +154,13 @@ delete baseEnvironment[SETTINGS_VARIABLE];
|
|
|
131
154
|
const baseUrls = Array.from({ length: workers }, (_, index) => `http://${host}:${basePort + index}`);
|
|
132
155
|
try {
|
|
133
156
|
await refuseBusyPorts(host, baseUrls.map((_, index) => basePort + index));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
]);
|
|
157
|
+
preparing = prepareWorkers(appRoot, prepare, workers, baseUrls);
|
|
158
|
+
// Both settle before a failure of either ends the start, so the copies prepare makes are all made when they are dropped.
|
|
159
|
+
const [built, prepared] = await Promise.allSettled([buildFrontend({ appRoot, build }), preparing]);
|
|
160
|
+
for (const result of [built, prepared]) if (result.status === "rejected") throw result.reason;
|
|
161
|
+
// A stop during the start drops the copies; no server starts on them.
|
|
162
|
+
if (stopping) throw new Error("The run was stopped while it started.");
|
|
163
|
+
const workerEnvironments = prepared.value;
|
|
138
164
|
mkdirSync(path.join(appRoot, LOG_DIRECTORY), { recursive: true });
|
|
139
165
|
mkdirSync(path.dirname(workerEnvironmentsFile), { recursive: true });
|
|
140
166
|
writeFileSync(workerEnvironmentsFile, JSON.stringify(workerEnvironments.slice(0, workers)), { mode: 0o600 });
|
|
@@ -156,6 +182,10 @@ try {
|
|
|
156
182
|
const output = createWriteStream(path.join(appRoot, log));
|
|
157
183
|
child.stdout.pipe(output);
|
|
158
184
|
child.stderr.pipe(output);
|
|
185
|
+
if (terminal) {
|
|
186
|
+
child.stdout.pipe(process.stdout, { end: false });
|
|
187
|
+
child.stderr.pipe(process.stderr, { end: false });
|
|
188
|
+
}
|
|
159
189
|
child.once("exit", (code, signal) => {
|
|
160
190
|
if (stopping) return;
|
|
161
191
|
console.error(`[browser-tests] ${name} stopped (${signal || `exit ${code}`}); log: ${log}`);
|
package/scripts/jskit.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
formatCheckReport,
|
|
12
12
|
formatExportSummary
|
|
13
13
|
} from "./i18n.mjs";
|
|
14
|
+
import { serveBrowserTestTarget } from "./browser-test-server.mjs";
|
|
14
15
|
import { checkDataAccess, formatDataAccessReport } from "./data-access.mjs";
|
|
15
16
|
import { checkManifestCapabilities, formatManifestCapabilitiesReport } from "./manifest-capabilities.mjs";
|
|
16
17
|
import { checkMaterial3, formatMaterial3Report } from "./material3.mjs";
|
|
@@ -34,6 +35,7 @@ function usage() {
|
|
|
34
35
|
" jskit i18n check <locale> [--root <path>]",
|
|
35
36
|
" jskit package nix [--root <path>]",
|
|
36
37
|
" jskit test [node options] [files or globs]",
|
|
38
|
+
" jskit browser-test-server [host] [port]",
|
|
37
39
|
"",
|
|
38
40
|
"Commands:",
|
|
39
41
|
" update Align root and workspace @jskit-ai/* declarations to this published catalog, then run npm install.",
|
|
@@ -83,6 +85,12 @@ function usage() {
|
|
|
83
85
|
" connected database. Given no files, it",
|
|
84
86
|
" fails when a file under tests/ is named as a test (x.integration.js, x.spec.js) that node's",
|
|
85
87
|
" default pattern would leave out; a database test is named x.integration.test.js.",
|
|
88
|
+
" browser-test-server",
|
|
89
|
+
" Serve the app for a host's browser test run, such as a Vibe64 Outputs target with Data test, on",
|
|
90
|
+
" [host] [port] (else HOST and PORT): one worker's server of the app's playwright.config.mjs",
|
|
91
|
+
" browserTestConfig(), on the production build, with the database its prepare module gives that",
|
|
92
|
+
" worker, its test-only env and APP_ENV=test. The host's suite runs against it with",
|
|
93
|
+
" PLAYWRIGHT_BASE_URL and the login state the host supplies. It runs until it is stopped.",
|
|
86
94
|
"",
|
|
87
95
|
"<locale> is a BCP 47 language tag, such as fr or pt-BR."
|
|
88
96
|
].join("\n");
|
|
@@ -94,7 +102,7 @@ function parseArgs(argv = []) {
|
|
|
94
102
|
const command = commandArgument === "--help" || commandArgument === "-h"
|
|
95
103
|
? "help"
|
|
96
104
|
: commandArgument;
|
|
97
|
-
if (command === "test") {
|
|
105
|
+
if (command === "test" || command === "browser-test-server") {
|
|
98
106
|
return { command, args };
|
|
99
107
|
}
|
|
100
108
|
const options = {
|
|
@@ -287,6 +295,10 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
287
295
|
process.exitCode = await runTests(options.args);
|
|
288
296
|
return;
|
|
289
297
|
}
|
|
298
|
+
if (options.command === "browser-test-server") {
|
|
299
|
+
await serveBrowserTestTarget(options.args);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
290
302
|
|
|
291
303
|
const catalog = await readCatalog();
|
|
292
304
|
if (options.command === "update") {
|
|
@@ -13,6 +13,7 @@ const DEPENDENCY_FIELDS = Object.freeze([
|
|
|
13
13
|
"optionalDependencies"
|
|
14
14
|
]);
|
|
15
15
|
const UPDATE_SCRIPT = "npx --yes @jskit-ai/jskit-catalog@latest update";
|
|
16
|
+
const UPDATE_FIX = "Run npm run jskit:update, which moves every JSKIT pin to this catalog and installs it.";
|
|
16
17
|
// JSKIT packages a release retired, each with what replaced it. The updater removes their declarations itself, and
|
|
17
18
|
// refuses while the application's own code still imports one, naming the import to use instead.
|
|
18
19
|
const RETIRED_PACKAGES = Object.freeze({
|
|
@@ -206,7 +207,7 @@ async function checkProject({ projectRoot = process.cwd(), catalog, additionalMa
|
|
|
206
207
|
if (declaration.declaredVersion !== expectedVersion) {
|
|
207
208
|
issues.push(
|
|
208
209
|
`${declaration.source}#${declaration.field}.${declaration.packageId} is ${declaration.declaredVersion}; ` +
|
|
209
|
-
`expected ${expectedVersion}
|
|
210
|
+
`expected ${expectedVersion}. ${UPDATE_FIX}`
|
|
210
211
|
);
|
|
211
212
|
}
|
|
212
213
|
}
|
|
@@ -238,7 +239,9 @@ async function checkProject({ projectRoot = process.cwd(), catalog, additionalMa
|
|
|
238
239
|
}
|
|
239
240
|
const installed = (await readJsonRecord(installedPath)).value;
|
|
240
241
|
if (installed.version !== record.version) {
|
|
241
|
-
|
|
242
|
+
// The catalog that runs comes from a newer JSKIT copy (a source under development); npm ci would put the old one back.
|
|
243
|
+
const ahead = installed.version === normalizedCatalog.versions.get(resolveLockPackageName(packagePath, record));
|
|
244
|
+
issues.push(`${packagePath} installed ${installed.version}; lockfile requires ${record.version}. ${ahead ? `${installed.version} is the version this catalog names, so the project's pins are behind it. ${UPDATE_FIX}` : "Run npm ci."}`);
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
for (const manifest of manifests) {
|
|
@@ -268,7 +271,7 @@ async function checkProject({ projectRoot = process.cwd(), catalog, additionalMa
|
|
|
268
271
|
}
|
|
269
272
|
if (installation.version !== expectedVersion) {
|
|
270
273
|
issues.push(
|
|
271
|
-
`${installation.path} resolves ${installation.packageId}@${installation.version}; expected ${expectedVersion}
|
|
274
|
+
`${installation.path} resolves ${installation.packageId}@${installation.version}; expected ${expectedVersion}. ${UPDATE_FIX}`
|
|
272
275
|
);
|
|
273
276
|
}
|
|
274
277
|
const entries = byPackageId.get(installation.packageId) || [];
|
package/scripts/test-command.mjs
CHANGED
|
@@ -239,7 +239,9 @@ async function runTests(args) {
|
|
|
239
239
|
if (times) process.stderr.write(times.report);
|
|
240
240
|
if (times?.overruns.length > 0 && exitCode === 0) exitCode = 1;
|
|
241
241
|
} finally {
|
|
242
|
-
databases
|
|
242
|
+
// However the run ended, it drops its numbered test databases, and says what it dropped.
|
|
243
|
+
const ended = await databases?.cleanup();
|
|
244
|
+
if (ended) process.stderr.write(`jskit test: ${ended}.\n`);
|
|
243
245
|
rmSync(timesDirectory, { recursive: true, force: true });
|
|
244
246
|
}
|
|
245
247
|
return exitCode;
|
|
@@ -9,7 +9,8 @@ import { readTableResourceSources } from "./data-access.mjs";
|
|
|
9
9
|
// from a schema snapshot, from the application's installed @jskit-ai/database-runtime and its knexfile.js, which loads
|
|
10
10
|
// .env and fixes the dialect. JSKIT's catalog itself depends on no database package. What the knexfile loads into the
|
|
11
11
|
// environment is read for the databases only: the test files get the environment `jskit test` was given, plus their
|
|
12
|
-
// own database and its connection (DB_NAME, TEST_DB_NAME, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD)
|
|
12
|
+
// own database and its connection (DB_NAME, TEST_DB_NAME, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD), and the designated
|
|
13
|
+
// database it copies (JSKIT_DESIGNATED_TEST_DB_NAME, see testDatabaseFile.js). A knexfile whose
|
|
13
14
|
// schema the migrations alone do not build also exports `testDatabaseSchema` ({ files, build }, see testDatabases.js).
|
|
14
15
|
const OPTION = "--databases";
|
|
15
16
|
const KNEXFILES = Object.freeze(["knexfile.js", "knexfile.mjs", "knexfile.cjs"]);
|
|
@@ -101,10 +102,13 @@ function foreignKeyCheckFor(cwd) {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
/**
|
|
104
|
-
* The run's databases for `count` files at once, or one file at a time on the connected database.
|
|
105
|
+
* The run's databases for `count` files at once, or one file at a time on the connected database. Its `cleanup()` ends
|
|
106
|
+
* the run: it removes the run's settings and drops its numbered copies of TEST_DB_NAME, answering what it dropped (an
|
|
107
|
+
* installed @jskit-ai/database-runtime from before that answers nothing and leaves the copies).
|
|
105
108
|
* @param {number} count at most the run's test budget, and no more than its test files
|
|
106
109
|
* @param {string} [cwd]
|
|
107
|
-
* @returns {Promise<{ concurrency: number, env: Record<string, string>, preload: string, summary: string,
|
|
110
|
+
* @returns {Promise<{ concurrency: number, env: Record<string, string>, preload: string, summary: string,
|
|
111
|
+
* cleanup(): Promise<string> | void }>}
|
|
108
112
|
*/
|
|
109
113
|
async function testDatabaseRunFor(count, cwd = process.cwd()) {
|
|
110
114
|
const knexfile = KNEXFILES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));
|