@seedmancer/playwright 0.1.0 → 0.2.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 +41 -0
- package/dist/global-setup.d.ts +8 -0
- package/dist/global-setup.d.ts.map +1 -0
- package/dist/global-setup.js +44 -0
- package/dist/global-setup.js.map +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -72,3 +72,44 @@ test.describe("admin flows", () => {
|
|
|
72
72
|
| CLI not found | `Seedmancer CLI not found. Make sure it is installed and available in PATH.` |
|
|
73
73
|
| Non-zero exit | `Seedmancer exited with status <N>: <stderr/stdout>` |
|
|
74
74
|
| Killed by signal | `Seedmancer was terminated by signal: <signal>` |
|
|
75
|
+
|
|
76
|
+
## Global setup — pull scenarios before the suite
|
|
77
|
+
|
|
78
|
+
Use `@seedmancer/playwright/global-setup` to pull seed data from Seedmancer Cloud once before the test suite starts. This is separate from the per-test seeding fixture.
|
|
79
|
+
|
|
80
|
+
### 1. Create a global setup file
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// playwright.global-setup.ts
|
|
84
|
+
import { createSeedmancerGlobalSetup } from "@seedmancer/playwright/global-setup"
|
|
85
|
+
|
|
86
|
+
export default createSeedmancerGlobalSetup({
|
|
87
|
+
scenarios: ["api-test"],
|
|
88
|
+
// tokenEnv defaults to "SEEDMANCER_API_TOKEN"
|
|
89
|
+
tokenEnv: "SEEDMANCER_API_TOKEN",
|
|
90
|
+
// cwd defaults to process.cwd()
|
|
91
|
+
cwd: "../",
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 2. Reference it from your Playwright config
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// playwright.config.ts
|
|
99
|
+
import { defineConfig } from "@playwright/test"
|
|
100
|
+
|
|
101
|
+
export default defineConfig({
|
|
102
|
+
globalSetup: "./playwright.global-setup.ts",
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Options
|
|
107
|
+
|
|
108
|
+
| Option | Type | Default | Description |
|
|
109
|
+
|---|---|---|---|
|
|
110
|
+
| `scenarios` | `string[]` | required | Scenarios to pull from Seedmancer Cloud. |
|
|
111
|
+
| `token` | `string` | — | API token. Takes precedence over `tokenEnv`. |
|
|
112
|
+
| `tokenEnv` | `string` | `"SEEDMANCER_API_TOKEN"` | Environment variable name to read the token from. |
|
|
113
|
+
| `cwd` | `string` | `process.cwd()` | Working directory for the CLI (directory containing `seedmancer.yaml`). |
|
|
114
|
+
|
|
115
|
+
The token is never logged or included in error messages.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type SeedmancerGlobalSetupOptions = {
|
|
2
|
+
scenarios: string[];
|
|
3
|
+
token?: string;
|
|
4
|
+
tokenEnv?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function createSeedmancerGlobalSetup(options: SeedmancerGlobalSetupOptions): () => Promise<void>;
|
|
8
|
+
//# sourceMappingURL=global-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.d.ts","sourceRoot":"","sources":["../src/global-setup.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,4BAA4B,GAAG;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAmCF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,SAEU,OAAO,CAAC,IAAI,CAAC,CAgB7D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSeedmancerGlobalSetup = createSeedmancerGlobalSetup;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
function runSeedmancerPull(scenario, token, cwd) {
|
|
6
|
+
const result = (0, node_child_process_1.spawnSync)('seedmancer', ['pull', scenario, '--token', token], {
|
|
7
|
+
cwd,
|
|
8
|
+
stdio: 'pipe',
|
|
9
|
+
encoding: 'utf-8',
|
|
10
|
+
});
|
|
11
|
+
if (result.error !== undefined) {
|
|
12
|
+
const err = result.error;
|
|
13
|
+
if (err.code === 'ENOENT') {
|
|
14
|
+
throw new Error('Seedmancer CLI not found. Make sure it is installed and available in PATH.\n' +
|
|
15
|
+
'See https://seedmancer.dev/docs/install for installation instructions.');
|
|
16
|
+
}
|
|
17
|
+
throw result.error;
|
|
18
|
+
}
|
|
19
|
+
if (result.signal !== null) {
|
|
20
|
+
throw new Error(`Seedmancer was terminated by signal: ${result.signal}`);
|
|
21
|
+
}
|
|
22
|
+
if (result.status !== 0) {
|
|
23
|
+
const output = [result.stderr?.trim(), result.stdout?.trim()]
|
|
24
|
+
.filter(Boolean)
|
|
25
|
+
.join('\n');
|
|
26
|
+
throw new Error(`seedmancer pull failed for scenario "${scenario}" with status ${result.status}` +
|
|
27
|
+
(output.length > 0 ? `:\n${output}` : ''));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createSeedmancerGlobalSetup(options) {
|
|
31
|
+
return async function seedmancerGlobalSetup() {
|
|
32
|
+
const cwd = options.cwd ?? process.cwd();
|
|
33
|
+
const tokenEnv = options.tokenEnv ?? 'SEEDMANCER_API_TOKEN';
|
|
34
|
+
const token = options.token ?? process.env[tokenEnv];
|
|
35
|
+
if (token === undefined || token === '') {
|
|
36
|
+
throw new Error(`Seedmancer API token is missing. ` +
|
|
37
|
+
`Set the ${tokenEnv} environment variable or pass token directly.`);
|
|
38
|
+
}
|
|
39
|
+
for (const scenario of options.scenarios) {
|
|
40
|
+
runSeedmancerPull(scenario, token, cwd);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=global-setup.js.map
|
|
@@ -0,0 +1 @@
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CAAC;AACH,CAAC;AAED,SAAgB,2BAA2B,CACzC,OAAqC;IAErC,OAAO,KAAK,UAAU,qBAAqB;QACzC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,sBAAsB,CAAC;QAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAErD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,mCAAmC;gBACjC,WAAW,QAAQ,+CAA+C,CACrE,CAAC;QACJ,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACzC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seedmancer/playwright",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Playwright integration for Seedmancer – automatically seed your database before each test",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
".": {
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./global-setup": {
|
|
27
|
+
"types": "./dist/global-setup.d.ts",
|
|
28
|
+
"default": "./dist/global-setup.js"
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
"files": [
|