@elench/testkit 0.1.66 → 0.1.68

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.
@@ -0,0 +1,57 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { writeNextRuntimeTsconfig } from "./next-runtime-tsconfig.mjs";
6
+
7
+ const cleanups = [];
8
+
9
+ afterEach(() => {
10
+ while (cleanups.length > 0) {
11
+ cleanups.pop()();
12
+ }
13
+ });
14
+
15
+ describe("next runtime tsconfig helper", () => {
16
+ it("writes a runtime-specific tsconfig for next builds", async () => {
17
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "testkit-next-tsconfig-"));
18
+ cleanups.push(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
19
+
20
+ const serviceDir = path.join(tempRoot, "frontend");
21
+ const prepareDir = path.join(tempRoot, ".testkit", "prepared");
22
+ fs.mkdirSync(path.join(serviceDir, "src"), { recursive: true });
23
+ fs.writeFileSync(path.join(serviceDir, "tsconfig.json"), "{}\n");
24
+ fs.writeFileSync(path.join(serviceDir, "next-env.d.ts"), "// next\n");
25
+
26
+ await writeNextRuntimeTsconfig({
27
+ cwd: serviceDir,
28
+ prepareDir,
29
+ productDir: tempRoot,
30
+ });
31
+
32
+ const generated = JSON.parse(fs.readFileSync(path.join(prepareDir, "tsconfig.json"), "utf8"));
33
+ expect(generated).toEqual({
34
+ extends: "../../frontend/tsconfig.json",
35
+ compilerOptions: {
36
+ paths: {
37
+ "@/*": ["../../frontend/src/*"],
38
+ },
39
+ },
40
+ include: [
41
+ "../../frontend/next-env.d.ts",
42
+ "../../frontend/src/**/*.ts",
43
+ "../../frontend/src/**/*.tsx",
44
+ "../../frontend/src/**/*.mts",
45
+ "dist/types/**/*.ts",
46
+ "dist/dev/types/**/*.ts",
47
+ ],
48
+ exclude: [
49
+ "node_modules",
50
+ "../../frontend/src/**/__testkit__/**",
51
+ "../../frontend/tests/**",
52
+ ".next/cache",
53
+ ".next/dev",
54
+ ],
55
+ });
56
+ });
57
+ });
@@ -0,0 +1,208 @@
1
+ import path from "path";
2
+ import { normalizeConfiguredInputs, normalizeConfiguredSteps, normalizeOptionalString } from "./configured-steps.mjs";
3
+
4
+ export function normalizeBuildConfig(value, label) {
5
+ if (value == null) return null;
6
+ if (!value || typeof value !== "object") {
7
+ throw new Error(`${label} must be an object`);
8
+ }
9
+
10
+ const kind = normalizeOptionalString(value.kind);
11
+ if (kind === "tsc") {
12
+ return {
13
+ kind,
14
+ cwd: normalizeOptionalString(value.cwd),
15
+ entry: normalizeOptionalString(value.entry) || "src/index.ts",
16
+ tsconfig: normalizeOptionalString(value.tsconfig) || "tsconfig.json",
17
+ outDir: normalizeOptionalString(value.outDir) || "dist",
18
+ inputs: normalizeConfiguredInputs(value.inputs, `${label}.inputs`),
19
+ };
20
+ }
21
+
22
+ if (kind === "script") {
23
+ const script = normalizeOptionalString(value.script);
24
+ if (!script) throw new Error(`${label}.script must be a non-empty string`);
25
+ return {
26
+ kind,
27
+ cwd: normalizeOptionalString(value.cwd),
28
+ script,
29
+ inputs: normalizeConfiguredInputs(value.inputs, `${label}.inputs`),
30
+ };
31
+ }
32
+
33
+ if (kind === "next") {
34
+ return {
35
+ kind,
36
+ cwd: normalizeOptionalString(value.cwd),
37
+ distDir: normalizeOptionalString(value.distDir) || "dist",
38
+ tsconfig: normalizeOptionalString(value.tsconfig) || "tsconfig.json",
39
+ inputs: normalizeConfiguredInputs(value.inputs, `${label}.inputs`),
40
+ };
41
+ }
42
+
43
+ if (kind === "steps") {
44
+ return {
45
+ kind,
46
+ inputs: normalizeConfiguredInputs(value.inputs, `${label}.inputs`),
47
+ steps: normalizeConfiguredSteps(value.steps, `${label}.steps`),
48
+ };
49
+ }
50
+
51
+ throw new Error(`${label}.kind must be one of: tsc, script, next, steps`);
52
+ }
53
+
54
+ export function finalizeBuildConfig(build, transform) {
55
+ if (!build) return null;
56
+ if (build.kind === "tsc") {
57
+ return {
58
+ ...build,
59
+ cwd: build.cwd ? transform(build.cwd) : build.cwd,
60
+ entry: transform(build.entry),
61
+ tsconfig: transform(build.tsconfig),
62
+ outDir: transform(build.outDir),
63
+ inputs: build.inputs.map((input) => transform(input)),
64
+ };
65
+ }
66
+ if (build.kind === "script") {
67
+ return {
68
+ ...build,
69
+ cwd: build.cwd ? transform(build.cwd) : build.cwd,
70
+ script: transform(build.script),
71
+ inputs: build.inputs.map((input) => transform(input)),
72
+ };
73
+ }
74
+ if (build.kind === "next") {
75
+ return {
76
+ ...build,
77
+ cwd: build.cwd ? transform(build.cwd) : build.cwd,
78
+ distDir: transform(build.distDir),
79
+ tsconfig: transform(build.tsconfig),
80
+ inputs: build.inputs.map((input) => transform(input)),
81
+ };
82
+ }
83
+ return {
84
+ ...build,
85
+ inputs: build.inputs.map((input) => transform(input)),
86
+ steps: build.steps.map((step) => ({
87
+ ...step,
88
+ ...(typeof step.cmd === "string" ? { cmd: transform(step.cmd) } : {}),
89
+ ...(typeof step.cwd === "string" ? { cwd: transform(step.cwd) } : {}),
90
+ ...(typeof step.path === "string" ? { path: transform(step.path) } : {}),
91
+ ...(typeof step.specifier === "string" ? { specifier: transform(step.specifier) } : {}),
92
+ inputs: (step.inputs || []).map((input) => transform(input)),
93
+ })),
94
+ };
95
+ }
96
+
97
+ export function buildConfigToPrepare(build) {
98
+ if (!build) {
99
+ return {
100
+ inputs: [],
101
+ steps: [],
102
+ };
103
+ }
104
+
105
+ if (build.kind === "steps") {
106
+ return {
107
+ inputs: [...build.inputs],
108
+ steps: [...build.steps],
109
+ };
110
+ }
111
+
112
+ if (build.kind === "script") {
113
+ return {
114
+ inputs: [...build.inputs],
115
+ steps: [
116
+ {
117
+ kind: "command",
118
+ cmd: build.script,
119
+ cwd: build.cwd || undefined,
120
+ inputs: [...build.inputs],
121
+ },
122
+ ],
123
+ };
124
+ }
125
+
126
+ if (build.kind === "next") {
127
+ const inputs = build.inputs.length > 0 ? [...build.inputs] : defaultNextInputs(build);
128
+ return {
129
+ inputs,
130
+ steps: [
131
+ {
132
+ kind: "module",
133
+ specifier: "@elench/testkit/setup/next-runtime-tsconfig#writeNextRuntimeTsconfig",
134
+ cwd: build.cwd || undefined,
135
+ inputs,
136
+ },
137
+ {
138
+ kind: "command",
139
+ cmd: "./node_modules/.bin/next build",
140
+ cwd: build.cwd || undefined,
141
+ inputs,
142
+ },
143
+ ],
144
+ };
145
+ }
146
+
147
+ const inputs = build.inputs.length > 0 ? [...build.inputs] : defaultTscInputs(build);
148
+ const cmd = `./node_modules/.bin/tsc -p ${build.tsconfig} --outDir "{prepareDir}/${build.outDir}"`;
149
+ return {
150
+ inputs,
151
+ steps: [
152
+ {
153
+ kind: "command",
154
+ cmd,
155
+ cwd: build.cwd || undefined,
156
+ inputs,
157
+ },
158
+ ],
159
+ };
160
+ }
161
+
162
+ export function compiledEntryFromBuild(build) {
163
+ if (!build || build.kind !== "tsc") return null;
164
+ return path.posix.join(build.outDir, sourceEntryToOutputPath(build.entry));
165
+ }
166
+
167
+ function sourceEntryToOutputPath(entry) {
168
+ const normalized = String(entry).split(path.sep).join("/");
169
+ const withoutExtension = normalized.replace(/\.[cm]?[jt]sx?$/i, ".js");
170
+ if (withoutExtension.startsWith("src/")) {
171
+ return withoutExtension.slice(4);
172
+ }
173
+ return withoutExtension;
174
+ }
175
+
176
+ function defaultTscInputs(build) {
177
+ const inputs = new Set([
178
+ prefixConfiguredPath(build.cwd, build.tsconfig),
179
+ prefixConfiguredPath(build.cwd, "package.json"),
180
+ ]);
181
+ const normalizedEntry = prefixConfiguredPath(build.cwd, String(build.entry).split(path.sep).join("/"));
182
+ const topLevelDir = normalizedEntry.includes("/") ? normalizedEntry.slice(0, normalizedEntry.indexOf("/")) : normalizedEntry;
183
+ if (topLevelDir) {
184
+ inputs.add(topLevelDir);
185
+ }
186
+ return [...inputs];
187
+ }
188
+
189
+ function defaultNextInputs(build) {
190
+ const inputs = new Set([
191
+ prefixConfiguredPath(build.cwd, build.tsconfig),
192
+ prefixConfiguredPath(build.cwd, "package.json"),
193
+ prefixConfiguredPath(build.cwd, "src"),
194
+ prefixConfiguredPath(build.cwd, "app"),
195
+ prefixConfiguredPath(build.cwd, "public"),
196
+ prefixConfiguredPath(build.cwd, "next.config.js"),
197
+ prefixConfiguredPath(build.cwd, "next.config.mjs"),
198
+ prefixConfiguredPath(build.cwd, "next.config.ts"),
199
+ ]);
200
+ return [...inputs];
201
+ }
202
+
203
+ function prefixConfiguredPath(cwd, value) {
204
+ const normalizedCwd = String(cwd || "").split(path.sep).join("/").replace(/^\.\/+/, "").replace(/\/+$/g, "");
205
+ const normalizedValue = String(value).split(path.sep).join("/").replace(/^\.\/+/, "");
206
+ if (!normalizedCwd || normalizedCwd === ".") return normalizedValue;
207
+ return `${normalizedCwd}/${normalizedValue}`.replace(/\/+/g, "/");
208
+ }
@@ -0,0 +1,150 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ buildConfigToPrepare,
4
+ compiledEntryFromBuild,
5
+ normalizeBuildConfig,
6
+ } from "./build-config.mjs";
7
+
8
+ describe("shared build config helpers", () => {
9
+ it("normalizes tsc build config and derives prepare steps", () => {
10
+ const build = normalizeBuildConfig(
11
+ {
12
+ kind: "tsc",
13
+ entry: "src/server.ts",
14
+ outDir: "dist",
15
+ },
16
+ "runtime.build"
17
+ );
18
+
19
+ expect(build).toEqual({
20
+ kind: "tsc",
21
+ cwd: null,
22
+ entry: "src/server.ts",
23
+ tsconfig: "tsconfig.json",
24
+ outDir: "dist",
25
+ inputs: [],
26
+ });
27
+ expect(compiledEntryFromBuild(build)).toBe("dist/server.js");
28
+ expect(buildConfigToPrepare(build)).toEqual({
29
+ inputs: ["tsconfig.json", "package.json", "src"],
30
+ steps: [
31
+ {
32
+ kind: "command",
33
+ cmd: './node_modules/.bin/tsc -p tsconfig.json --outDir "{prepareDir}/dist"',
34
+ cwd: undefined,
35
+ inputs: ["tsconfig.json", "package.json", "src"],
36
+ },
37
+ ],
38
+ });
39
+ });
40
+
41
+ it("normalizes script and steps builds", () => {
42
+ expect(
43
+ normalizeBuildConfig(
44
+ {
45
+ kind: "script",
46
+ script: "npm run build",
47
+ cwd: "frontend",
48
+ inputs: ["frontend/package.json"],
49
+ },
50
+ "runtime.build"
51
+ )
52
+ ).toEqual({
53
+ kind: "script",
54
+ script: "npm run build",
55
+ cwd: "frontend",
56
+ inputs: ["frontend/package.json"],
57
+ });
58
+
59
+ expect(
60
+ normalizeBuildConfig(
61
+ {
62
+ kind: "next",
63
+ cwd: "frontend",
64
+ },
65
+ "runtime.build"
66
+ )
67
+ ).toEqual({
68
+ kind: "next",
69
+ cwd: "frontend",
70
+ distDir: "dist",
71
+ tsconfig: "tsconfig.json",
72
+ inputs: [],
73
+ });
74
+
75
+ expect(
76
+ normalizeBuildConfig(
77
+ {
78
+ kind: "steps",
79
+ inputs: ["scripts/prepare.mjs"],
80
+ steps: [{ kind: "command", cmd: "node scripts/prepare.mjs" }],
81
+ },
82
+ "runtime.build"
83
+ )
84
+ ).toEqual({
85
+ kind: "steps",
86
+ inputs: ["scripts/prepare.mjs"],
87
+ steps: [
88
+ {
89
+ kind: "command",
90
+ cmd: "node scripts/prepare.mjs",
91
+ cwd: null,
92
+ inputs: [],
93
+ },
94
+ ],
95
+ });
96
+
97
+ expect(
98
+ buildConfigToPrepare({
99
+ kind: "next",
100
+ cwd: "frontend",
101
+ distDir: "dist",
102
+ tsconfig: "tsconfig.json",
103
+ inputs: [],
104
+ })
105
+ ).toEqual({
106
+ inputs: [
107
+ "frontend/tsconfig.json",
108
+ "frontend/package.json",
109
+ "frontend/src",
110
+ "frontend/app",
111
+ "frontend/public",
112
+ "frontend/next.config.js",
113
+ "frontend/next.config.mjs",
114
+ "frontend/next.config.ts",
115
+ ],
116
+ steps: [
117
+ {
118
+ kind: "module",
119
+ specifier: "@elench/testkit/setup/next-runtime-tsconfig#writeNextRuntimeTsconfig",
120
+ cwd: "frontend",
121
+ inputs: [
122
+ "frontend/tsconfig.json",
123
+ "frontend/package.json",
124
+ "frontend/src",
125
+ "frontend/app",
126
+ "frontend/public",
127
+ "frontend/next.config.js",
128
+ "frontend/next.config.mjs",
129
+ "frontend/next.config.ts",
130
+ ],
131
+ },
132
+ {
133
+ kind: "command",
134
+ cmd: "./node_modules/.bin/next build",
135
+ cwd: "frontend",
136
+ inputs: [
137
+ "frontend/tsconfig.json",
138
+ "frontend/package.json",
139
+ "frontend/src",
140
+ "frontend/app",
141
+ "frontend/public",
142
+ "frontend/next.config.js",
143
+ "frontend/next.config.mjs",
144
+ "frontend/next.config.ts",
145
+ ],
146
+ },
147
+ ],
148
+ });
149
+ });
150
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/next-analysis",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "SWC-backed Next.js source analysis primitives for Erench tools",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit-bridge",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "Browser bridge helpers for testkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "typecheck": "tsc -p tsconfig.json --noEmit"
23
23
  },
24
24
  "dependencies": {
25
- "@elench/testkit-protocol": "0.1.66"
25
+ "@elench/testkit-protocol": "0.1.68"
26
26
  },
27
27
  "private": false
28
28
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit-protocol",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "Shared browser protocol for testkit bridge and extension consumers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/ts-analysis",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "TypeScript compiler-backed source analysis primitives for Erench tools",
5
5
  "type": "module",
6
6
  "exports": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "CLI for discovering and running local HTTP, DAL, and Playwright test suites",
5
5
  "type": "module",
6
6
  "workspaces": [
@@ -64,10 +64,10 @@
64
64
  "vitest": "^3.2.4"
65
65
  },
66
66
  "dependencies": {
67
- "@elench/next-analysis": "0.1.66",
68
- "@elench/ts-analysis": "0.1.66",
69
- "@elench/testkit-bridge": "0.1.66",
70
- "@elench/testkit-protocol": "0.1.66",
67
+ "@elench/next-analysis": "0.1.68",
68
+ "@elench/ts-analysis": "0.1.68",
69
+ "@elench/testkit-bridge": "0.1.68",
70
+ "@elench/testkit-protocol": "0.1.68",
71
71
  "@babel/code-frame": "^7.29.0",
72
72
  "@oclif/core": "^4.10.6",
73
73
  "esbuild": "^0.25.11",