@dionlarson/playwright-orchestrator-core 1.3.1 → 1.3.2
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/dist/test-runner.js +47 -9
- package/package.json +1 -1
package/dist/test-runner.js
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import child_process from 'node:child_process';
|
|
2
|
+
import child_process, { spawn } from 'node:child_process';
|
|
3
3
|
import { promisify } from 'node:util';
|
|
4
4
|
import { rm, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { TestExecutionReporter } from './reporters/test-execution-reporter.js';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import * as uuid from 'uuid';
|
|
8
8
|
const exec = promisify(child_process.exec);
|
|
9
|
+
function spawnWithOutput(command, args, env) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const proc = spawn(command, args, {
|
|
12
|
+
env,
|
|
13
|
+
shell: true,
|
|
14
|
+
stdio: ['inherit', 'pipe', 'inherit'] // stdin inherit, stdout pipe, stderr inherit
|
|
15
|
+
});
|
|
16
|
+
let stdout = '';
|
|
17
|
+
proc.stdout?.on('data', (data) => {
|
|
18
|
+
const str = data.toString();
|
|
19
|
+
stdout += str;
|
|
20
|
+
// Stream output but filter out the JSON reporter output
|
|
21
|
+
if (!str.trim().startsWith('{')) {
|
|
22
|
+
process.stdout.write(data);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
proc.on('close', (code) => {
|
|
26
|
+
if (code === 0) {
|
|
27
|
+
resolve(stdout);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const error = new Error(`Process exited with code ${code}`);
|
|
31
|
+
error.stdout = stdout;
|
|
32
|
+
reject(error);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
proc.on('error', reject);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
9
38
|
export class TestRunner {
|
|
10
39
|
adapter;
|
|
11
40
|
runId;
|
|
@@ -17,11 +46,14 @@ export class TestRunner {
|
|
|
17
46
|
this.outputFolder = options.output;
|
|
18
47
|
}
|
|
19
48
|
async runTests() {
|
|
49
|
+
console.log(`[orchestrator] Starting shard for run ${this.runId}`);
|
|
20
50
|
await this.removePreviousReports();
|
|
21
51
|
const config = await this.adapter.startShard(this.runId);
|
|
52
|
+
console.log(`[orchestrator] Shard started. Workers: ${config.workers}, Config: ${config.configFile || 'default'}`);
|
|
22
53
|
config.configFile = await this.createTempConfig(config.configFile);
|
|
23
54
|
try {
|
|
24
55
|
await this.runTestsUntilAvailable(config);
|
|
56
|
+
console.log(`[orchestrator] All tests completed, finishing shard`);
|
|
25
57
|
await this.adapter.finishShard(this.runId);
|
|
26
58
|
await this.adapter.dispose();
|
|
27
59
|
this.reporter.printSummary();
|
|
@@ -33,9 +65,14 @@ export class TestRunner {
|
|
|
33
65
|
}
|
|
34
66
|
async runTestsUntilAvailable(config) {
|
|
35
67
|
const runningTests = new Set();
|
|
68
|
+
console.log(`[orchestrator] Fetching first test...`);
|
|
36
69
|
let next = await this.adapter.getNextTest(this.runId, config);
|
|
70
|
+
console.log(`[orchestrator] First test: ${next ? `[${next.project}] ${next.file}:${next.position}` : 'none available'}`);
|
|
71
|
+
let testCount = 0;
|
|
37
72
|
while (next || runningTests.size > 0) {
|
|
38
73
|
if (next && runningTests.size < config.workers) {
|
|
74
|
+
testCount++;
|
|
75
|
+
console.log(`[orchestrator] Running test #${testCount}: [${next.project}] ${next.file}:${next.position}`);
|
|
39
76
|
const testPromise = this.runTest(next, config).then(() => {
|
|
40
77
|
runningTests.delete(testPromise);
|
|
41
78
|
});
|
|
@@ -46,6 +83,7 @@ export class TestRunner {
|
|
|
46
83
|
await Promise.race(runningTests);
|
|
47
84
|
}
|
|
48
85
|
}
|
|
86
|
+
console.log(`[orchestrator] Finished ${testCount} tests`);
|
|
49
87
|
await Promise.all(runningTests);
|
|
50
88
|
}
|
|
51
89
|
async removePreviousReports() {
|
|
@@ -55,15 +93,14 @@ export class TestRunner {
|
|
|
55
93
|
const testPosition = `${test.file}:${test.position}`;
|
|
56
94
|
const testName = `[${test.project}] > ${testPosition}`;
|
|
57
95
|
const testHash = createHash('md5').update(testName).digest('hex');
|
|
96
|
+
const args = [testPosition, ...this.buildParams(test, config, testHash).split(' ')];
|
|
97
|
+
const env = {
|
|
98
|
+
...process.env,
|
|
99
|
+
PLAYWRIGHT_BLOB_OUTPUT_FILE: `${this.outputFolder}/${testHash}.zip`,
|
|
100
|
+
};
|
|
58
101
|
try {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
...process.env,
|
|
62
|
-
PLAYWRIGHT_BLOB_OUTPUT_FILE: `${this.outputFolder}/${testHash}.zip`,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
this.reporter.addTest(test, run);
|
|
66
|
-
const { stdout } = await run;
|
|
102
|
+
const stdout = await spawnWithOutput('npx', ['playwright', 'test', ...args], env);
|
|
103
|
+
this.reporter.finishTest(test);
|
|
67
104
|
await this.adapter.finishTest({
|
|
68
105
|
runId: this.runId,
|
|
69
106
|
test,
|
|
@@ -74,6 +111,7 @@ export class TestRunner {
|
|
|
74
111
|
catch (error) {
|
|
75
112
|
if (!error.stdout)
|
|
76
113
|
throw error;
|
|
114
|
+
this.reporter.failTest(test);
|
|
77
115
|
await this.adapter.failTest({
|
|
78
116
|
runId: this.runId,
|
|
79
117
|
test,
|