openspec-playwright 0.1.23 → 0.1.25

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openspec-playwright",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "OpenSpec + Playwright E2E verification setup tool for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
package/release-notes.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## What's Changed
2
2
 
3
- - fix: ensure schema dest directory exists before writing schema.yaml
3
+ - fix: playwright.config.ts searches subdirs for package.json
4
4
 
5
- **Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.23
5
+ **Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.25
@@ -1,9 +1,51 @@
1
1
  import { defineConfig, devices } from '@playwright/test';
2
- import { readFileSync, existsSync } from 'fs';
2
+ import { readFileSync, existsSync, readdirSync } from 'fs';
3
3
  import { join } from 'path';
4
4
 
5
+ // ─── Detect project root (where openspec/ lives) ───
6
+ function findProjectRoot(start: string): string {
7
+ let dir = start;
8
+ for (let i = 0; i < 10; i++) {
9
+ if (existsSync(join(dir, 'package.json'))) return dir;
10
+ const parent = join(dir, '..');
11
+ if (parent === dir) break;
12
+ dir = parent;
13
+ }
14
+ return start;
15
+ }
16
+
17
+ // ─── Find the npm project root (where package.json with scripts lives) ───
18
+ // Checks project root first, then immediate subdirectories
19
+ function findNpmRoot(projectRoot: string): string {
20
+ const pkgAtRoot = join(projectRoot, 'package.json');
21
+ if (existsSync(pkgAtRoot)) {
22
+ const pkg = JSON.parse(readFileSync(pkgAtRoot, 'utf-8'));
23
+ if (pkg.scripts?.dev || pkg.scripts?.start || pkg.scripts?.serve || pkg.scripts?.preview) {
24
+ return projectRoot;
25
+ }
26
+ }
27
+ // Check immediate subdirectories (e.g., openspec/ and imap/ are siblings)
28
+ try {
29
+ const entries = readdirSync(projectRoot, { withFileTypes: true });
30
+ for (const entry of entries) {
31
+ if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;
32
+ const subPkg = join(projectRoot, entry.name, 'package.json');
33
+ if (existsSync(subPkg)) {
34
+ const sub = JSON.parse(readFileSync(subPkg, 'utf-8'));
35
+ if (sub.scripts?.dev || sub.scripts?.start) {
36
+ return join(projectRoot, entry.name);
37
+ }
38
+ }
39
+ }
40
+ } catch {}
41
+ return projectRoot;
42
+ }
43
+
44
+ const projectRoot = findProjectRoot(__dirname);
45
+ const npmRoot = findNpmRoot(projectRoot);
46
+
5
47
  // ─── BASE_URL: prefer env, then seed.spec.ts, then default ───
6
- const seedSpec = join(__dirname, '../tests/playwright/seed.spec.ts');
48
+ const seedSpec = join(projectRoot, 'tests', 'playwright', 'seed.spec.ts');
7
49
  let baseUrl = process.env.BASE_URL || 'http://localhost:3000';
8
50
  if (existsSync(seedSpec)) {
9
51
  const content = readFileSync(seedSpec, 'utf-8');
@@ -11,20 +53,22 @@ if (existsSync(seedSpec)) {
11
53
  if (m) baseUrl = m[1];
12
54
  }
13
55
 
14
- // ─── Dev command: detect from package.json scripts ───
15
- const pkgPath = join(__dirname, '../package.json');
56
+ // ─── Dev command: detect from the npm project ───
16
57
  let devCmd = 'npm run dev';
17
- if (existsSync(pkgPath)) {
18
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
58
+ const npmPkg = join(npmRoot, 'package.json');
59
+ if (existsSync(npmPkg)) {
60
+ const pkg = JSON.parse(readFileSync(npmPkg, 'utf-8'));
19
61
  const scripts = pkg.scripts ?? {};
20
- // Prefer in order: dev, start, serve, preview
21
62
  devCmd = scripts.dev ?? scripts.start ?? scripts.serve ?? scripts.preview ?? devCmd;
63
+ // Prefix with cd if npmRoot differs from projectRoot
64
+ if (npmRoot !== projectRoot) {
65
+ devCmd = `cd ${npmRoot} && ${devCmd}`;
66
+ }
22
67
  }
23
68
 
24
69
  export default defineConfig({
25
- testDir: '../tests/playwright',
26
- // Keep test artifacts inside tests/playwright/ instead of project root
27
- outputDir: '../tests/playwright/test-results',
70
+ testDir: join(projectRoot, 'tests', 'playwright'),
71
+ outputDir: join(projectRoot, 'tests', 'playwright', 'test-results'),
28
72
  fullyParallel: true,
29
73
  forbidOnly: !!process.env.CI,
30
74
  retries: process.env.CI ? 2 : 0,
Binary file