@lowdefy/block-dev-e2e 6.1.0 → 7.0.0

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/README.md CHANGED
@@ -152,6 +152,12 @@ pnpm e2e --headed # Run with visible browser
152
152
  pnpm e2e --debug # Debug mode
153
153
  ```
154
154
 
155
+ The test app is built and served with the Lowdefy CLI from `packages/cli/dist`, in
156
+ `_server/e2e/<package>` at the monorepo root: an untracked copy of `packages/servers/server`
157
+ that `scripts/prepare-e2e-server.mjs` prepares on each run. Build the monorepo first
158
+ (`pnpm build`). A run leaves tracked files unchanged, and different packages can run at the
159
+ same time.
160
+
155
161
  ## Port Assignments
156
162
 
157
163
  Use unique ports to allow parallel test runs:
@@ -14,23 +14,36 @@
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
16
  import { defineConfig, devices } from '@playwright/test';
17
- function createPlaywrightConfig({ packageDir, port = 3001 }) {
17
+ // A package's block e2e suite builds and serves `e2e/app`. A package can also run a second
18
+ // suite against an app of its own (`appDir`, `name`, `testMatch`), with services such as a
19
+ // database or mock APIs started before the app (`services`, Playwright webServer entries) and
20
+ // environment variables for the app server (`env`).
21
+ function createPlaywrightConfig({ packageDir, port: defaultPort = 3001, appDir: appDirOption, name, testMatch = [
22
+ 'src/**/tests/*.e2e.spec.js',
23
+ 'e2e/tests/*.e2e.spec.js'
24
+ ], services = [], env, fullyParallel = true, workers }) {
25
+ // Worktrees share the machine, so a fixed port could reach another checkout's server.
26
+ // LOWDEFY_E2E_PORT moves the run, and an existing server is only reused on request.
27
+ const port = Number(process.env.LOWDEFY_E2E_PORT ?? defaultPort);
18
28
  const e2eDir = path.join(packageDir, 'e2e');
19
- const appDir = path.join(e2eDir, 'app');
29
+ const appDir = appDirOption ?? path.join(e2eDir, 'app');
30
+ const suiteName = name ?? path.basename(packageDir);
20
31
  // Calculate paths relative to monorepo root
21
32
  // packageDir is like: /path/to/lowdefy/packages/plugins/blocks/blocks-basic
22
33
  const monorepoRoot = path.resolve(packageDir, '../../../../');
23
34
  const cliPath = path.join(monorepoRoot, 'packages/cli/dist/index.js');
24
- const serverDir = path.join(monorepoRoot, 'packages/servers/server');
35
+ const prepareServerPath = path.join(monorepoRoot, 'scripts/prepare-e2e-server.mjs');
36
+ // Each suite builds into its own untracked copy of the server, so a run leaves the
37
+ // worktree clean and different suites can run at the same time.
38
+ const serverDir = path.join(monorepoRoot, '_server/e2e', suiteName);
39
+ const reuseExistingServer = process.env.LOWDEFY_E2E_REUSE_SERVER === 'true';
25
40
  return defineConfig({
26
41
  testDir: packageDir,
27
- testMatch: [
28
- 'src/**/tests/*.e2e.spec.js',
29
- 'e2e/tests/*.e2e.spec.js'
30
- ],
31
- fullyParallel: true,
42
+ testMatch,
43
+ fullyParallel,
44
+ workers,
32
45
  reporter: 'list',
33
- outputDir: path.join(e2eDir, 'test-results'),
46
+ outputDir: path.join(path.dirname(appDir), 'test-results'),
34
47
  use: {
35
48
  baseURL: `http://localhost:${port}`,
36
49
  trace: 'on-first-retry'
@@ -43,12 +56,40 @@ function createPlaywrightConfig({ packageDir, port = 3001 }) {
43
56
  }
44
57
  }
45
58
  ],
46
- webServer: {
47
- command: `node ${cliPath} build --config-directory ${appDir} --server-directory ${serverDir} && node ${cliPath} start --config-directory ${appDir} --server-directory ${serverDir} --port ${port} --log-level warn`,
48
- url: `http://localhost:${port}`,
49
- reuseExistingServer: true,
50
- timeout: 180000
51
- }
59
+ webServer: [
60
+ ...services.map((service)=>({
61
+ reuseExistingServer,
62
+ ...service
63
+ })),
64
+ {
65
+ command: [
66
+ `node ${prepareServerPath} --config-directory ${appDir} --server-directory ${serverDir} --log-level warn`,
67
+ `node ${cliPath} build --config-directory ${appDir} --server-directory ${serverDir}`,
68
+ `node ${cliPath} start --config-directory ${appDir} --server-directory ${serverDir} --port ${port} --log-level warn`
69
+ ].join(' && '),
70
+ url: `http://localhost:${port}`,
71
+ reuseExistingServer,
72
+ timeout: 180000,
73
+ // The server stops when this runner does, however it ends (Playwright cleans up its
74
+ // web servers only on a normal exit or SIGINT). Workers evaluate this config too, but
75
+ // only the runner launches webServer.
76
+ env: {
77
+ ...process.env,
78
+ ...env,
79
+ LOWDEFY_EXIT_WITH_PID: String(process.pid)
80
+ },
81
+ // Playwright stops the web servers in reverse order, the app first. Killed outright, the
82
+ // server that `lowdefy start` runs outlives its shell, so it was still connected when the
83
+ // services (a database) stopped under it. A SIGTERM to the app's process group, waited
84
+ // for, stops it before the services.
85
+ ...services.length > 0 ? {
86
+ gracefulShutdown: {
87
+ signal: 'SIGTERM',
88
+ timeout: 15000
89
+ }
90
+ } : {}
91
+ }
92
+ ]
52
93
  });
53
94
  }
54
95
  export default createPlaywrightConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/block-dev-e2e",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Block E2E Testing Tools",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,7 +29,7 @@
29
29
  "dist/*"
30
30
  ],
31
31
  "dependencies": {
32
- "@lowdefy/e2e-utils": "6.1.0",
32
+ "@lowdefy/e2e-utils": "7.0.0",
33
33
  "@playwright/test": "1.59.1"
34
34
  },
35
35
  "devDependencies": {