@elench/testkit 0.1.57 → 0.1.58
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/lib/cli/commands/browser/serve.mjs +112 -0
- package/lib/cli/entrypoint.mjs +4 -0
- package/lib/config/discovery.test.mjs +3 -2
- package/lib/config/index.mjs +29 -0
- package/lib/coverage/index.mjs +774 -0
- package/lib/coverage/index.test.mjs +220 -0
- package/lib/discovery/index.d.ts +3 -0
- package/lib/discovery/index.mjs +14 -2
- package/lib/setup/index.d.ts +5 -0
- package/node_modules/@elench/testkit-bridge/package.json +17 -0
- package/node_modules/@elench/testkit-bridge/src/index.mjs +391 -0
- package/node_modules/@elench/testkit-bridge/src/index.test.mjs +183 -0
- package/node_modules/@elench/testkit-protocol/package.json +18 -0
- package/node_modules/@elench/testkit-protocol/src/index.d.ts +204 -0
- package/node_modules/@elench/testkit-protocol/src/index.mjs +245 -0
- package/node_modules/@elench/testkit-protocol/src/index.test.mjs +154 -0
- package/package.json +11 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import { startBrowserBridgeServer } from "@elench/testkit-bridge";
|
|
3
|
+
import { loadConfigContext, resolveProductDir } from "../../../config/index.mjs";
|
|
4
|
+
import { discoverTests } from "../../../discovery/index.mjs";
|
|
5
|
+
import { loadCurrentRunArtifact } from "../../viewer.mjs";
|
|
6
|
+
|
|
7
|
+
export default class BrowserServeCommand extends Command {
|
|
8
|
+
static summary = "Serve the local browser bridge for the current testkit product";
|
|
9
|
+
|
|
10
|
+
static enableJsonFlag = true;
|
|
11
|
+
|
|
12
|
+
static flags = {
|
|
13
|
+
dir: Flags.string({
|
|
14
|
+
description: "Product directory",
|
|
15
|
+
}),
|
|
16
|
+
host: Flags.string({
|
|
17
|
+
description: "Host to bind the browser bridge server",
|
|
18
|
+
default: "127.0.0.1",
|
|
19
|
+
}),
|
|
20
|
+
port: Flags.integer({
|
|
21
|
+
description: "Port to bind the browser bridge server",
|
|
22
|
+
default: 3847,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(BrowserServeCommand);
|
|
28
|
+
const productDir = resolveProductDir(process.cwd(), flags.dir);
|
|
29
|
+
|
|
30
|
+
const adapter = {
|
|
31
|
+
loadProductContext: async () => {
|
|
32
|
+
const [configContext, discovery] = await Promise.all([
|
|
33
|
+
loadConfigContext({
|
|
34
|
+
dir: productDir,
|
|
35
|
+
discoveryOptions: { strict: false },
|
|
36
|
+
}),
|
|
37
|
+
discoverTests({
|
|
38
|
+
dir: productDir,
|
|
39
|
+
diagnostics: "report",
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
product: {
|
|
45
|
+
name: discovery.product.name,
|
|
46
|
+
directory: discovery.product.directory,
|
|
47
|
+
},
|
|
48
|
+
services: configContext.configs
|
|
49
|
+
.map((config) => {
|
|
50
|
+
const baseUrl = config.testkit.local?.baseUrl || null;
|
|
51
|
+
const browserOrigins = config.testkit.browser?.origins || [];
|
|
52
|
+
if (!baseUrl && browserOrigins.length === 0) return null;
|
|
53
|
+
const serviceEntries = [];
|
|
54
|
+
if (baseUrl && !baseUrl.includes("{port}")) {
|
|
55
|
+
try {
|
|
56
|
+
const parsed = new URL(baseUrl);
|
|
57
|
+
serviceEntries.push({
|
|
58
|
+
name: config.name,
|
|
59
|
+
baseUrl,
|
|
60
|
+
origin: parsed.origin,
|
|
61
|
+
});
|
|
62
|
+
} catch {
|
|
63
|
+
// Ignore invalid local.baseUrl templates here; explicit browser origins still work.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const origin of browserOrigins) {
|
|
67
|
+
serviceEntries.push({
|
|
68
|
+
name: config.name,
|
|
69
|
+
baseUrl: origin,
|
|
70
|
+
origin,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return serviceEntries;
|
|
74
|
+
})
|
|
75
|
+
.flat()
|
|
76
|
+
.filter(Boolean),
|
|
77
|
+
discovery,
|
|
78
|
+
runArtifact: loadRunArtifactIfPresent(productDir),
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const serverRef = await startBrowserBridgeServer(adapter, {
|
|
84
|
+
host: flags.host,
|
|
85
|
+
port: flags.port,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const payload = {
|
|
89
|
+
ok: true,
|
|
90
|
+
productDir,
|
|
91
|
+
host: serverRef.host,
|
|
92
|
+
port: serverRef.port,
|
|
93
|
+
url: serverRef.url,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (!this.jsonEnabled()) {
|
|
97
|
+
this.log(`testkit browser bridge serving ${productDir}`);
|
|
98
|
+
this.log(`Listening on ${serverRef.url}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await new Promise(() => {});
|
|
102
|
+
return payload;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function loadRunArtifactIfPresent(productDir) {
|
|
107
|
+
try {
|
|
108
|
+
return loadCurrentRunArtifact(productDir);
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/lib/cli/entrypoint.mjs
CHANGED
|
@@ -9,6 +9,7 @@ export function normalizeCliArgs(argv) {
|
|
|
9
9
|
"artifacts",
|
|
10
10
|
"watch",
|
|
11
11
|
"discover",
|
|
12
|
+
"browser",
|
|
12
13
|
"known-failures",
|
|
13
14
|
"db",
|
|
14
15
|
"help",
|
|
@@ -77,6 +78,9 @@ function reorderCommandArgs(args, positionals) {
|
|
|
77
78
|
if (positionals[0]?.value === "db" && positionals[1] && positionals[2]) {
|
|
78
79
|
commandTokens.push(positionals[1], positionals[2]);
|
|
79
80
|
}
|
|
81
|
+
if (positionals[0]?.value === "browser" && positionals[1]) {
|
|
82
|
+
commandTokens.push(positionals[1]);
|
|
83
|
+
}
|
|
80
84
|
const commandIndexes = new Set(commandTokens.map((token) => token.index));
|
|
81
85
|
return [
|
|
82
86
|
...commandTokens.map((token) => token.value),
|
|
@@ -204,10 +204,11 @@ describe("filesystem-discovery", () => {
|
|
|
204
204
|
},
|
|
205
205
|
]);
|
|
206
206
|
});
|
|
207
|
+
|
|
207
208
|
});
|
|
208
209
|
|
|
209
|
-
function writeFile(productDir, relativePath) {
|
|
210
|
+
function writeFile(productDir, relativePath, content = "export {};\n") {
|
|
210
211
|
const absolutePath = path.join(productDir, relativePath);
|
|
211
212
|
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
212
|
-
fs.writeFileSync(absolutePath,
|
|
213
|
+
fs.writeFileSync(absolutePath, content);
|
|
213
214
|
}
|
package/lib/config/index.mjs
CHANGED
|
@@ -144,6 +144,7 @@ function normalizeServiceConfig({
|
|
|
144
144
|
...loadServiceEnv(productDir, envFiles),
|
|
145
145
|
...(explicitService.env || {}),
|
|
146
146
|
};
|
|
147
|
+
const browser = normalizeBrowserServiceConfig(explicitService.browser, name);
|
|
147
148
|
if (explicitService.migrate || explicitService.seed) {
|
|
148
149
|
throw new Error(
|
|
149
150
|
`Service "${name}" uses removed migrate/seed hooks. Move template lifecycle to database.template.{migrate,seed,verify}.`
|
|
@@ -190,6 +191,7 @@ function normalizeServiceConfig({
|
|
|
190
191
|
serviceEnv,
|
|
191
192
|
skip,
|
|
192
193
|
runtime,
|
|
194
|
+
browser,
|
|
193
195
|
local,
|
|
194
196
|
},
|
|
195
197
|
};
|
|
@@ -702,6 +704,33 @@ function normalizeSkipReason(reason, label) {
|
|
|
702
704
|
return normalized;
|
|
703
705
|
}
|
|
704
706
|
|
|
707
|
+
function normalizeBrowserServiceConfig(value, serviceName) {
|
|
708
|
+
if (!value) return undefined;
|
|
709
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
710
|
+
throw new Error(`Service "${serviceName}" browser config must be an object`);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
const origins = Array.isArray(value.origins)
|
|
714
|
+
? value.origins
|
|
715
|
+
.map((origin) => normalizeOptionalString(origin))
|
|
716
|
+
.filter(Boolean)
|
|
717
|
+
: [];
|
|
718
|
+
|
|
719
|
+
for (const origin of origins) {
|
|
720
|
+
try {
|
|
721
|
+
const parsed = new URL(origin);
|
|
722
|
+
if (!parsed.origin) {
|
|
723
|
+
throw new Error("missing origin");
|
|
724
|
+
}
|
|
725
|
+
} catch {
|
|
726
|
+
throw new Error(`Service "${serviceName}" browser.origins contains an invalid URL: ${origin}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if (origins.length === 0) return undefined;
|
|
731
|
+
return { origins };
|
|
732
|
+
}
|
|
733
|
+
|
|
705
734
|
function loadServiceEnv(productDir, envFiles) {
|
|
706
735
|
const env = {};
|
|
707
736
|
for (const envFile of envFiles) {
|