Skip to content

Commit f72b6b4

Browse files
authored
test: try to unflake fixtures tests (#1574)
1 parent b4a2014 commit f72b6b4

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

test/fixtures.spec.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
2626
const {it, fit, xit, dit} = testRunner;
2727
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
2828

29-
async function testSignal(action) {
29+
async function testSignal(action, exitOnClose) {
3030
const options = Object.assign({}, defaultBrowserOptions, {
3131
// Disable DUMPIO to cleanly read stdout.
3232
dumpio: false,
3333
handleSIGINT: true,
3434
handleSIGTERM: true,
3535
handleSIGHUP: true,
3636
});
37-
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
37+
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options), exitOnClose ? 'true' : '']);
3838
let wsEndPointCallback;
3939
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
4040
let output = '';
4141
let browserExitCode = 'none';
4242
let browserSignal = 'none';
4343
let browserPid;
4444
res.stdout.on('data', data => {
45-
output += data;
45+
output += data.toString();
4646
// Uncomment to debug these tests.
4747
// console.log(data.toString());
4848
let match = output.match(/browserWS:(.+):browserWS/);
@@ -94,23 +94,18 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
9494
// We might not get browser exitCode in time when killing the parent node process,
9595
// so we don't check it here.
9696
});
97-
if (!WIN) {
97+
98+
describe.skip(WIN)('signals', () => {
9899
// Cannot reliably send signals on Windows.
99100
it.slow()('should report browser close signal', async () => {
100-
const result = await testSignal((child, browserPid) => {
101-
process.kill(browserPid);
102-
process.kill(child.pid, 'SIGINT');
103-
});
104-
expect(result.exitCode).toBe(130);
101+
const result = await testSignal((child, browserPid) => process.kill(browserPid), true);
102+
expect(result.exitCode).toBe(0);
105103
expect(result.browserExitCode).toBe('null');
106104
expect(result.browserSignal).toBe('SIGTERM');
107105
});
108-
it.slow()('should report browser close signal 2', async () => {
109-
const result = await testSignal((child, browserPid) => {
110-
process.kill(browserPid, 'SIGKILL');
111-
process.kill(child.pid, 'SIGINT');
112-
});
113-
expect(result.exitCode).toBe(130);
106+
it.slow()('should report browser close signal 2', async (state, test) => {
107+
const result = await testSignal((child, browserPid) => process.kill(browserPid, 'SIGKILL'), true);
108+
expect(result.exitCode).toBe(0);
114109
expect(result.browserExitCode).toBe('null');
115110
expect(result.browserSignal).toBe('SIGKILL');
116111
});
@@ -159,6 +154,6 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
159154
// TODO: ideally, we would expect the SIGKILL on the browser from
160155
// force kill, but that's racy with sending two signals.
161156
});
162-
}
157+
});
163158
});
164159
};

test/fixtures/closeme.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(async() => {
2-
const [, , playwrightRoot, product, options] = process.argv;
2+
const [, , playwrightRoot, product, options, exitOnClose] = process.argv;
33
const browserServer = await require(playwrightRoot)[product.toLowerCase()].launchServer(JSON.parse(options));
44
browserServer.on('close', (exitCode, signal) => {
55
console.log(`browserClose:${exitCode}:${signal}:browserClose`);
6+
if (exitOnClose)
7+
process.exit(0);
68
});
79
console.log(`browserPid:${browserServer.process().pid}:browserPid`);
810
console.log(`browserWS:${browserServer.wsEndpoint()}:browserWS`);

0 commit comments

Comments
 (0)