@azimuth-sh/playwright 0.0.0-stage → 0.2.0-alpha.10
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 +22 -2
- package/components.js +84 -0
- package/evaluate-config.js +23 -0
- package/index.js +268 -0
- package/package.json +34 -4
- package/start-read.js +4 -0
- package/stop-read.js +4 -0
- package/wrap-config.js +36 -0
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Azimuth's Playwright adapter
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This adapter lists marked Playwright tests, runs the requested Checks and reports
|
|
4
|
+
their first attempts to Azimuth. It uses the application's own `@playwright/test`.
|
|
5
|
+
This version supports Playwright `>=1.61.1 <1.66.0`, verified with the adapter's
|
|
6
|
+
real-runner suite at 1.61.1 and 1.65.1. The resolved-config loader uses an
|
|
7
|
+
undocumented interface because the public reporter configuration does not expose
|
|
8
|
+
the entries of a `webServer` array.
|
|
9
|
+
|
|
10
|
+
Install it as a development dependency of the application:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install --save-dev --save-exact @azimuth-sh/playwright@<version>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`azimuth init` prints that line with the CLI's version filled in. The suite's
|
|
17
|
+
adapter command is `npx --no @azimuth-sh/playwright`.
|
|
18
|
+
|
|
19
|
+
Put a Playwright config in each suite's folder. Its `webServer` must start the
|
|
20
|
+
application, with `reuseExistingServer` false. Mark a test or a `describe` group
|
|
21
|
+
with a tag such as `@Check:loan-is-refused`; several tags may mark one test.
|
|
22
|
+
An annotation is not a marker. A suite with another `marker_key` uses that key
|
|
23
|
+
in place of `Check`.
|
package/components.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const http = require('node:http');
|
|
5
|
+
const https = require('node:https');
|
|
6
|
+
const net = require('node:net');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
const READ_LIMIT_MS = 10000;
|
|
10
|
+
const LOOK_LIMIT_MS = 3000;
|
|
11
|
+
const PLAN = Symbol.for('azimuth-playwright.plan');
|
|
12
|
+
|
|
13
|
+
// The address of an entry is its origin, so a path or a query in `url` never reaches a read.
|
|
14
|
+
function addressOf(entry) {
|
|
15
|
+
if (entry.url) return new URL(entry.url).origin;
|
|
16
|
+
if (entry.port) return `http://localhost:${entry.port}`;
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function acceptsConnection(host, port) {
|
|
21
|
+
return new Promise(resolve => {
|
|
22
|
+
const socket = net.connect({ host, port });
|
|
23
|
+
const finish = answered => {
|
|
24
|
+
socket.destroy();
|
|
25
|
+
resolve(answered);
|
|
26
|
+
};
|
|
27
|
+
socket.setTimeout(LOOK_LIMIT_MS, () => finish(false));
|
|
28
|
+
socket.on('connect', () => finish(true));
|
|
29
|
+
socket.on('error', () => finish(false));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// `localhost` names two addresses, and a server may hold only one of them.
|
|
34
|
+
async function answers(address) {
|
|
35
|
+
const url = new URL(address);
|
|
36
|
+
const port = Number(url.port) || (url.protocol === 'https:' ? 443 : 80);
|
|
37
|
+
const host = url.hostname.replace(/^\[|\]$/g, '');
|
|
38
|
+
const hosts = host === 'localhost' ? ['127.0.0.1', '::1'] : [host];
|
|
39
|
+
const results = await Promise.all(hosts.map(candidate => acceptsConnection(candidate, port)));
|
|
40
|
+
return results.includes(true);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function read(address, report, phase) {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
const failed = error => resolve({ phase, error });
|
|
46
|
+
const client = address.startsWith('https:') ? https : http;
|
|
47
|
+
const request = client.get(address + report, { agent: false }, response => {
|
|
48
|
+
if (response.statusCode !== 200) {
|
|
49
|
+
response.resume();
|
|
50
|
+
failed(`the response status was ${response.statusCode}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const chunks = [];
|
|
54
|
+
response.on('data', chunk => chunks.push(chunk));
|
|
55
|
+
response.on('error', error => failed(`the connection failed: ${error.message}`));
|
|
56
|
+
response.on('end', () => {
|
|
57
|
+
try {
|
|
58
|
+
resolve({ phase, report: JSON.parse(Buffer.concat(chunks).toString('utf8')) });
|
|
59
|
+
} catch {
|
|
60
|
+
failed('the body is not JSON');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
// The limit covers the whole read, so a body that never ends is as much a failure as no answer.
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
request.destroy();
|
|
67
|
+
failed('no response within 10 seconds');
|
|
68
|
+
}, READ_LIMIT_MS);
|
|
69
|
+
request.on('error', error => failed(`the connection failed: ${error.message}`));
|
|
70
|
+
request.on('close', () => clearTimeout(timer));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Runs inside the runner, as the first global setup and the last global teardown.
|
|
75
|
+
async function record(phase) {
|
|
76
|
+
const plan = globalThis[PLAN];
|
|
77
|
+
const reads = await Promise.all(plan.components.map(async component => ({
|
|
78
|
+
name: component.name,
|
|
79
|
+
read: await read(component.address, component.report, phase),
|
|
80
|
+
})));
|
|
81
|
+
fs.writeFileSync(path.join(plan.folder, `${phase}.json`), JSON.stringify(reads));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { PLAN, addressOf, answers, record };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Evaluates the resolved config in a process of its own and writes its `webServer` entries to the
|
|
3
|
+
// file named by the first argument. The second argument is the config path, empty when the runner
|
|
4
|
+
// is to find it.
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { createRequire } = require('node:module');
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const [output, configPath] = process.argv.slice(2);
|
|
11
|
+
const application = createRequire(path.join(process.cwd(), 'package.json'));
|
|
12
|
+
const runner = createRequire(application.resolve('@playwright/test/package.json'));
|
|
13
|
+
// The public FullConfig loses the individual entries when webServer is an array.
|
|
14
|
+
const { configLoader } = runner('playwright/lib/common');
|
|
15
|
+
const config = await configLoader.loadConfigFromFile(configPath || undefined, { retries: 0 });
|
|
16
|
+
fs.writeFileSync(output, JSON.stringify({
|
|
17
|
+
configFile: config.config.configFile,
|
|
18
|
+
webServers: config.webServers.map(({ name, url, port, reuseExistingServer }) => ({ name, url, port, reuseExistingServer })),
|
|
19
|
+
}));
|
|
20
|
+
})().catch(error => {
|
|
21
|
+
console.error(error);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawn, spawnSync, execFileSync } = require('node:child_process');
|
|
8
|
+
const { createRequire } = require('node:module');
|
|
9
|
+
const manifest = require('./package.json');
|
|
10
|
+
const { addressOf, answers } = require('./components');
|
|
11
|
+
|
|
12
|
+
// Standard output belongs exclusively to the adapter report, including when a config logs.
|
|
13
|
+
const writeReport = process.stdout.write.bind(process.stdout);
|
|
14
|
+
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
15
|
+
let temporary;
|
|
16
|
+
process.on('exit', () => {
|
|
17
|
+
if (temporary) fs.rmSync(temporary, { recursive: true, force: true });
|
|
18
|
+
});
|
|
19
|
+
// Every process in the launch group already receives the interrupt from the core.
|
|
20
|
+
process.on('SIGINT', () => process.exit(1));
|
|
21
|
+
|
|
22
|
+
function installedIn(folder) {
|
|
23
|
+
const ownFolder = fs.realpathSync(__dirname);
|
|
24
|
+
for (let current = fs.realpathSync(folder); ; current = path.dirname(current)) {
|
|
25
|
+
const installation = path.join(current, 'node_modules', '@azimuth-sh', 'playwright');
|
|
26
|
+
if (fs.existsSync(installation) && ownFolder === fs.realpathSync(installation)) return;
|
|
27
|
+
if (path.dirname(current) === current) break;
|
|
28
|
+
}
|
|
29
|
+
throw new Error('the package is not installed in this application');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function discover(folder, root) {
|
|
33
|
+
const projects = [];
|
|
34
|
+
function visit(current) {
|
|
35
|
+
const entries = fs.readdirSync(current, { withFileTypes: true });
|
|
36
|
+
if (entries.some(entry => entry.isFile() && /^playwright\.config\.(?:[cm]?[jt]s)$/.test(entry.name))) {
|
|
37
|
+
projects.push({ path: path.relative(root, current).split(path.sep).join('/') || '.' });
|
|
38
|
+
}
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
if (entry.isDirectory() && entry.name !== '.git' && entry.name !== 'node_modules') {
|
|
41
|
+
visit(path.join(current, entry.name));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
visit(folder);
|
|
46
|
+
projects.sort((a, b) => a.path.localeCompare(b.path));
|
|
47
|
+
return { projects };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function specs(document) {
|
|
51
|
+
if (!document || !Array.isArray(document.suites) || !Array.isArray(document.errors)) {
|
|
52
|
+
throw new Error('the runner wrote a report without suites and errors');
|
|
53
|
+
}
|
|
54
|
+
const entries = new Map();
|
|
55
|
+
function visit(suite, parents) {
|
|
56
|
+
if (typeof suite.title !== 'string' || !Array.isArray(suite.specs)) throw new Error('the runner wrote an invalid suite');
|
|
57
|
+
const titles = [...parents, suite.title];
|
|
58
|
+
for (const spec of suite.specs) {
|
|
59
|
+
if (typeof spec.title !== 'string' || typeof spec.file !== 'string' || !Number.isInteger(spec.line) || !Number.isInteger(spec.column) || !Array.isArray(spec.tags)
|
|
60
|
+
|| !spec.tags.every(tag => typeof tag === 'string') || !Array.isArray(spec.tests) || !spec.tests.length) {
|
|
61
|
+
throw new Error('the runner wrote an invalid test listing');
|
|
62
|
+
}
|
|
63
|
+
for (const test of spec.tests) {
|
|
64
|
+
if (!Array.isArray(test.results) || typeof test.expectedStatus !== 'string') throw new Error('the runner wrote an invalid test result');
|
|
65
|
+
for (const result of test.results) {
|
|
66
|
+
if (!['passed', 'failed', 'timedOut', 'skipped', 'interrupted'].includes(result.status)
|
|
67
|
+
|| !Number.isInteger(result.duration) || result.duration < 0) throw new Error('the runner wrote an invalid attempt');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const name = [...titles, spec.title].join(' › ');
|
|
71
|
+
const identity = JSON.stringify([spec.file, spec.line, spec.column, name]);
|
|
72
|
+
entries.set(identity, { ...spec, name });
|
|
73
|
+
}
|
|
74
|
+
for (const child of suite.suites || []) visit(child, titles);
|
|
75
|
+
}
|
|
76
|
+
for (const suite of document.suites) visit(suite, []);
|
|
77
|
+
return entries;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function outcome(rows, expectedCount) {
|
|
81
|
+
const verdicts = rows.map(row => {
|
|
82
|
+
const result = row.results[0];
|
|
83
|
+
if (!result || result.status === 'interrupted') return 'not_run';
|
|
84
|
+
if (result.status === 'skipped') return 'skipped';
|
|
85
|
+
return result.status === row.expectedStatus ? 'passed' : 'failed';
|
|
86
|
+
});
|
|
87
|
+
if (verdicts.includes('failed')) return 'failed';
|
|
88
|
+
if (rows.length !== expectedCount || verdicts.includes('not_run')) return 'not_run';
|
|
89
|
+
return verdicts.every(verdict => verdict === 'passed') ? 'passed' : 'skipped';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function escapeRegex(text) {
|
|
93
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function applicationRunner() {
|
|
97
|
+
const application = createRequire(path.join(process.cwd(), 'package.json'));
|
|
98
|
+
const version = application('@playwright/test/package.json').version;
|
|
99
|
+
const supported = manifest.peerDependencies['@playwright/test'];
|
|
100
|
+
const bounds = /^>=(\d+)\.(\d+)\.(\d+) <(\d+)\.(\d+)\.(\d+)$/.exec(supported);
|
|
101
|
+
const installed = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
102
|
+
const compare = (left, right) => {
|
|
103
|
+
for (let index = 0; index < 3; index++) {
|
|
104
|
+
const difference = Number(left[index]) - Number(right[index]);
|
|
105
|
+
if (difference) return difference;
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
};
|
|
109
|
+
if (!bounds || !installed || compare(installed.slice(1), bounds.slice(1, 4)) < 0 || compare(installed.slice(1), bounds.slice(4)) >= 0) {
|
|
110
|
+
throw new Error(`installed Playwright ${version} is outside the supported range ${supported}`);
|
|
111
|
+
}
|
|
112
|
+
return application;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const NO_ADDRESS = 'no address in the runner configuration';
|
|
116
|
+
const ANSWERS = 'something else answers there';
|
|
117
|
+
const NOT_MADE = { start: 'the start read was not made', stop: 'the stop read was not made' };
|
|
118
|
+
|
|
119
|
+
function evaluateConfig(configPath, folder, index) {
|
|
120
|
+
const output = path.join(folder, `evaluation-${index}.json`);
|
|
121
|
+
const status = spawnSync(process.execPath, [path.join(__dirname, 'evaluate-config.js'), output, configPath || ''], { stdio: ['ignore', 2, 2] });
|
|
122
|
+
if (status.status !== 0) return undefined;
|
|
123
|
+
return JSON.parse(fs.readFileSync(output, 'utf8'));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// What the config says about each component the request lists: one address, none, or a refusal.
|
|
127
|
+
function addressesIn(evaluation, components) {
|
|
128
|
+
return components.map(component => {
|
|
129
|
+
const entries = evaluation.webServers.filter(server => server.name === component.name);
|
|
130
|
+
if (entries.length > 1) throw new Error(`the config has ${entries.length} webServer entries named "${component.name}", and a component's entry must be one`);
|
|
131
|
+
return entries.length ? addressOf(entries[0]) : undefined;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function readsOf(folder, phase) {
|
|
136
|
+
const file = path.join(folder, `${phase}.json`);
|
|
137
|
+
return fs.existsSync(file) ? new Map(JSON.parse(fs.readFileSync(file, 'utf8')).map(({ name, read }) => [name, read])) : new Map();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function run(request, application) {
|
|
141
|
+
const components = request.components || [];
|
|
142
|
+
const args = process.argv.slice(2);
|
|
143
|
+
const configIndex = args.findIndex(arg => arg === '--config' || arg === '-c');
|
|
144
|
+
const configPath = configIndex >= 0 ? args[configIndex + 1] : args.find(arg => arg.startsWith('--config='))?.slice(9);
|
|
145
|
+
temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'azimuth-playwright-'));
|
|
146
|
+
|
|
147
|
+
const evaluation = evaluateConfig(configPath, temporary, 1);
|
|
148
|
+
if (!evaluation) return { build: 'failed', tests: [] };
|
|
149
|
+
if (!evaluation.webServers.length) throw new Error('the resolved config has no webServer entry');
|
|
150
|
+
if (evaluation.webServers.some(server => server.reuseExistingServer)) {
|
|
151
|
+
throw new Error('the resolved config sets reuseExistingServer to true');
|
|
152
|
+
}
|
|
153
|
+
const addresses = addressesIn(evaluation, components);
|
|
154
|
+
const second = evaluateConfig(configPath, temporary, 2);
|
|
155
|
+
if (!second) throw new Error('the resolved config could not be evaluated a second time');
|
|
156
|
+
const later = addressesIn(second, components);
|
|
157
|
+
components.forEach((component, index) => {
|
|
158
|
+
if (addresses[index] !== later[index]) {
|
|
159
|
+
throw new Error(`the address of "${component.name}" is ${addresses[index] ?? 'missing'} at one evaluation of the config and ${later[index] ?? 'missing'} at the next`);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const looked = await Promise.all(addresses.map(address => address && answers(address)));
|
|
164
|
+
const occupied = looked.some(Boolean);
|
|
165
|
+
|
|
166
|
+
const output = path.join(temporary, 'report.json');
|
|
167
|
+
const cli = application.resolve('@playwright/test/cli');
|
|
168
|
+
async function launch(extra, wrap) {
|
|
169
|
+
fs.rmSync(output, { force: true });
|
|
170
|
+
const loader = wrap ? ['--require', path.join(__dirname, 'wrap-config.js')] : [];
|
|
171
|
+
const { status, signal } = await new Promise((resolve, reject) => {
|
|
172
|
+
const child = spawn(process.execPath, [...loader, cli, 'test', ...args, ...extra, '--retries=0', '--reporter=line,json'], {
|
|
173
|
+
stdio: ['ignore', 2, 2],
|
|
174
|
+
env: { ...process.env, ...(wrap ? { AZIMUTH_PLAYWRIGHT_PLAN: wrap } : {}), PLAYWRIGHT_JSON_OUTPUT_FILE: output, PLAYWRIGHT_JSON_OUTPUT_NAME: output, PLAYWRIGHT_JSON_ONLY_FAILURES: '0' },
|
|
175
|
+
});
|
|
176
|
+
child.on('error', reject);
|
|
177
|
+
child.on('exit', (code, signal) => resolve({ status: code, signal }));
|
|
178
|
+
});
|
|
179
|
+
const report = fs.existsSync(output) ? JSON.parse(fs.readFileSync(output, 'utf8')) : null;
|
|
180
|
+
return { status, signal, report };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const listed = await launch(['--list']);
|
|
184
|
+
if (listed.signal) throw new Error(`the runner ended with ${listed.signal}`);
|
|
185
|
+
const listing = specs(listed.report);
|
|
186
|
+
if (listed.status !== 0) return { build: 'failed', tests: [] };
|
|
187
|
+
const marked = [...listing].map(([identity, spec]) => {
|
|
188
|
+
const prefix = `${request.marker_key}:`;
|
|
189
|
+
const checks = [...new Set(spec.tags.filter(tag => tag.startsWith(prefix) && /^[A-Za-z0-9-]+$/.test(tag.slice(prefix.length))).map(tag => tag.slice(prefix.length)))];
|
|
190
|
+
return { identity, spec, checks };
|
|
191
|
+
}).filter(test => test.checks.length);
|
|
192
|
+
const asked = new Set(request.checks);
|
|
193
|
+
const selected = [...new Set(marked.flatMap(test => test.checks).filter(check => asked.has(check)))];
|
|
194
|
+
let ran = new Map();
|
|
195
|
+
let started = false;
|
|
196
|
+
const readable = components.filter((component, index) => addresses[index]);
|
|
197
|
+
if (selected.length && !occupied) {
|
|
198
|
+
const filter = `(?:^|\\s)@${escapeRegex(request.marker_key)}:(?:${selected.map(escapeRegex).join('|')})(?=\\s|$)`;
|
|
199
|
+
let plan;
|
|
200
|
+
if (readable.length) {
|
|
201
|
+
const file = path.join(temporary, 'plan.json');
|
|
202
|
+
fs.writeFileSync(file, JSON.stringify({
|
|
203
|
+
config: fs.realpathSync(evaluation.configFile),
|
|
204
|
+
folder: temporary,
|
|
205
|
+
components: readable.map(component => ({ name: component.name, address: addresses[components.indexOf(component)], report: component.report })),
|
|
206
|
+
}));
|
|
207
|
+
plan = file;
|
|
208
|
+
}
|
|
209
|
+
const executed = await launch(['--grep', filter], plan);
|
|
210
|
+
started = true;
|
|
211
|
+
// A runner that is killed writes no report, and nothing it reports is then a failure of the suite.
|
|
212
|
+
if (!executed.signal) {
|
|
213
|
+
ran = specs(executed.report);
|
|
214
|
+
if (executed.report.errors.length || (executed.status !== 0 && ![...ran.values()].some(spec => outcome(spec.tests, spec.tests.length) === 'failed'))) {
|
|
215
|
+
throw new Error('the runner failed outside a test');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (plan && !executed.signal && !fs.existsSync(path.join(temporary, 'wrapped'))) {
|
|
219
|
+
throw new Error('the global setup of this config could not be wrapped; a config that the runner loads as an ES module is not supported');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const starts = readsOf(temporary, 'start');
|
|
223
|
+
const stops = readsOf(temporary, 'stop');
|
|
224
|
+
return {
|
|
225
|
+
build: 'ok',
|
|
226
|
+
tests: marked.map(({ identity, spec, checks }) => {
|
|
227
|
+
const rows = ran.get(identity)?.tests || [];
|
|
228
|
+
return {
|
|
229
|
+
name: spec.name,
|
|
230
|
+
checks,
|
|
231
|
+
outcome: rows.length ? outcome(rows, spec.tests.length) : 'not_run',
|
|
232
|
+
duration_ms: rows.reduce((sum, row) => sum + (row.results[0]?.duration || 0), 0),
|
|
233
|
+
};
|
|
234
|
+
}),
|
|
235
|
+
components: components.map((component, index) => {
|
|
236
|
+
if (!addresses[index]) return { name: component.name, error: NO_ADDRESS, reads: [] };
|
|
237
|
+
if (looked[index]) return { name: component.name, error: ANSWERS, reads: [] };
|
|
238
|
+
if (!started) return { name: component.name, reads: [] };
|
|
239
|
+
return {
|
|
240
|
+
name: component.name,
|
|
241
|
+
reads: ['start', 'stop'].map(phase => (phase === 'start' ? starts : stops).get(component.name) || { phase, error: NOT_MADE[phase] }),
|
|
242
|
+
};
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function main() {
|
|
248
|
+
let input = '';
|
|
249
|
+
process.stdin.setEncoding('utf8');
|
|
250
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
251
|
+
const request = JSON.parse(input);
|
|
252
|
+
if (request.format !== 'adapter-request-1') throw new Error('the request is not an adapter-request-1');
|
|
253
|
+
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim();
|
|
254
|
+
const folder = path.resolve(root, request.verb === 'discover' ? request.folder : request.suite);
|
|
255
|
+
if (fs.realpathSync(folder) !== fs.realpathSync(process.cwd())) throw new Error('the request folder is not the folder where the adapter was started');
|
|
256
|
+
installedIn(folder);
|
|
257
|
+
const application = applicationRunner();
|
|
258
|
+
let report;
|
|
259
|
+
if (request.verb === 'discover') report = discover(folder, root);
|
|
260
|
+
else if (request.verb === 'run') report = await run(request, application);
|
|
261
|
+
else throw new Error(`the verb ${request.verb} is not known; this adapter knows discover and run`);
|
|
262
|
+
writeReport(JSON.stringify({ format: 'adapter-report-1', adapter: { name: manifest.name, version: manifest.version }, ...report }));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
main().catch(error => {
|
|
266
|
+
console.error(`azimuth-playwright: ${error.message}`);
|
|
267
|
+
process.exitCode = 1;
|
|
268
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azimuth-sh/playwright",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0-alpha.10",
|
|
4
|
+
"description": "The Azimuth test adapter for Playwright",
|
|
5
|
+
"bin": {
|
|
6
|
+
"azimuth-playwright": "index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"components.js",
|
|
11
|
+
"evaluate-config.js",
|
|
12
|
+
"wrap-config.js",
|
|
13
|
+
"start-read.js",
|
|
14
|
+
"stop-read.js",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"homepage": "https://azimuth.sh",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/azimuth-sh/azimuth.git",
|
|
22
|
+
"directory": "adapters/playwright"
|
|
23
|
+
},
|
|
24
|
+
"author": "Azimuth",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@playwright/test": ">=1.61.1 <1.66.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"@playwright/test": {
|
|
30
|
+
"optional": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/start-read.js
ADDED
package/stop-read.js
ADDED
package/wrap-config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Preloaded into the runner only. The runner offers no option to add a global setup, so the
|
|
3
|
+
// config's exports are changed as the runner loads them, and the suite's own entries stay between
|
|
4
|
+
// the two reads.
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const Module = require('node:module');
|
|
8
|
+
const { PLAN } = require('./components');
|
|
9
|
+
|
|
10
|
+
// The runner starts its workers with the same options, and a worker has no plan to wrap anything
|
|
11
|
+
// with: the variable is gone from its environment.
|
|
12
|
+
if (process.env.AZIMUTH_PLAYWRIGHT_PLAN) {
|
|
13
|
+
const plan = JSON.parse(fs.readFileSync(process.env.AZIMUTH_PLAYWRIGHT_PLAN, 'utf8'));
|
|
14
|
+
// The suite's servers and tests inherit the environment, and none of this is theirs.
|
|
15
|
+
delete process.env.AZIMUTH_PLAYWRIGHT_PLAN;
|
|
16
|
+
globalThis[PLAN] = plan;
|
|
17
|
+
wrap(plan);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function wrap(plan) {
|
|
21
|
+
const wrapped = new WeakSet();
|
|
22
|
+
const entries = value => (value === undefined || value === null ? [] : Array.isArray(value) ? value : [value]);
|
|
23
|
+
const load = Module._load;
|
|
24
|
+
Module._load = function (request, parent, isMain) {
|
|
25
|
+
const exported = load.apply(this, arguments);
|
|
26
|
+
if (typeof request !== 'string' || path.basename(request) !== path.basename(plan.config)) return exported;
|
|
27
|
+
if (!exported || typeof exported !== 'object' || wrapped.has(exported)) return exported;
|
|
28
|
+
if (Module._resolveFilename(request, parent, isMain) !== plan.config) return exported;
|
|
29
|
+
const config = exported.default && typeof exported.default === 'object' ? exported.default : exported;
|
|
30
|
+
config.globalSetup = [path.join(__dirname, 'start-read.js'), ...entries(config.globalSetup)];
|
|
31
|
+
config.globalTeardown = [...entries(config.globalTeardown), path.join(__dirname, 'stop-read.js')];
|
|
32
|
+
wrapped.add(exported);
|
|
33
|
+
fs.writeFileSync(path.join(plan.folder, 'wrapped'), '');
|
|
34
|
+
return exported;
|
|
35
|
+
};
|
|
36
|
+
}
|