@elench/testkit 0.1.33 → 0.1.34

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.
@@ -5,7 +5,9 @@ import { normalizePathSeparators } from "./state.mjs";
5
5
 
6
6
  export function ensurePlaywrightTestConfig(targetConfig, cwd, requestedFiles) {
7
7
  const stateDir = targetConfig.stateDir || path.join(targetConfig.productDir, ".testkit");
8
+ const outputDir = resolvePlaywrightOutputDir(stateDir);
8
9
  fs.mkdirSync(stateDir, { recursive: true });
10
+ fs.mkdirSync(outputDir, { recursive: true });
9
11
  const configPath = path.join(stateDir, "playwright.testkit.config.mjs");
10
12
  const baseConfigPath = findPlaywrightConfig(cwd);
11
13
  const normalizedFiles = requestedFiles.map(normalizePathSeparators);
@@ -19,12 +21,14 @@ export function ensurePlaywrightTestConfig(targetConfig, cwd, requestedFiles) {
19
21
  ` ...(resolvedBase || {}),\n` +
20
22
  ` testDir: ${JSON.stringify(cwd)},\n` +
21
23
  ` testMatch: ${JSON.stringify(normalizedFiles)},\n` +
24
+ ` outputDir: ${JSON.stringify(outputDir)},\n` +
22
25
  `};\n`;
23
26
  } else {
24
27
  source =
25
28
  `export default {\n` +
26
29
  ` testDir: ${JSON.stringify(cwd)},\n` +
27
30
  ` testMatch: ${JSON.stringify(normalizedFiles)},\n` +
31
+ ` outputDir: ${JSON.stringify(outputDir)},\n` +
28
32
  `};\n`;
29
33
  }
30
34
 
@@ -32,6 +36,10 @@ export function ensurePlaywrightTestConfig(targetConfig, cwd, requestedFiles) {
32
36
  return configPath;
33
37
  }
34
38
 
39
+ export function resolvePlaywrightOutputDir(stateDir) {
40
+ return path.join(stateDir, "playwright-output");
41
+ }
42
+
35
43
  export function findPlaywrightConfig(cwd) {
36
44
  const candidates = [
37
45
  "playwright.config.ts",
@@ -0,0 +1,58 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { pathToFileURL } from "url";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import {
7
+ ensurePlaywrightTestConfig,
8
+ findPlaywrightConfig,
9
+ resolvePlaywrightOutputDir,
10
+ } from "./playwright-config.mjs";
11
+
12
+ const cleanups = [];
13
+
14
+ afterEach(() => {
15
+ while (cleanups.length > 0) {
16
+ cleanups.pop()();
17
+ }
18
+ });
19
+
20
+ function makeTempDir(prefix) {
21
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
22
+ cleanups.push(() => fs.rmSync(dir, { recursive: true, force: true }));
23
+ return dir;
24
+ }
25
+
26
+ describe("runner-playwright-config", () => {
27
+ it("uses a shard-local output directory under the state dir", async () => {
28
+ const productDir = makeTempDir("testkit-playwright-product-");
29
+ const stateDir = path.join(productDir, ".testkit", "worker-3");
30
+ const cwd = path.join(productDir, "frontend");
31
+ fs.mkdirSync(cwd, { recursive: true });
32
+ fs.writeFileSync(
33
+ path.join(cwd, "playwright.config.mjs"),
34
+ "export default { outputDir: 'shared-test-results' };\n"
35
+ );
36
+
37
+ const configPath = ensurePlaywrightTestConfig(
38
+ { productDir, stateDir },
39
+ cwd,
40
+ ["frontend/__testkit__/homepage/homepage.pw.testkit.ts"]
41
+ );
42
+ const generated = await import(pathToFileURL(configPath).href + `?t=${Date.now()}`);
43
+
44
+ const expectedOutputDir = resolvePlaywrightOutputDir(stateDir);
45
+ expect(generated.default.outputDir).toBe(expectedOutputDir);
46
+ expect(fs.existsSync(expectedOutputDir)).toBe(true);
47
+ expect(fs.readFileSync(configPath, "utf8")).toContain(
48
+ `outputDir: ${JSON.stringify(expectedOutputDir)}`
49
+ );
50
+ });
51
+
52
+ it("finds a supported playwright config file", () => {
53
+ const cwd = makeTempDir("testkit-playwright-cwd-");
54
+ fs.writeFileSync(path.join(cwd, "playwright.config.ts"), "export default {};\n");
55
+
56
+ expect(findPlaywrightConfig(cwd)).toBe(path.join(cwd, "playwright.config.ts"));
57
+ });
58
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "CLI for discovering and running local HTTP, DAL, and Playwright test suites",
5
5
  "type": "module",
6
6
  "types": "./lib/index.d.ts",