fix(test): add missing test for making sure chrome is closed (#2109)
This commit is contained in:
parent
44d8000de1
commit
0defecf197
5
test/fixtures/closeme.js
vendored
Normal file
5
test/fixtures/closeme.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(async() => {
|
||||||
|
const [, , puppeteerRoot, options] = process.argv;
|
||||||
|
const browser = await require(puppeteerRoot).launch(JSON.parse(options));
|
||||||
|
console.log(browser.wsEndpoint());
|
||||||
|
})();
|
21
test/test.js
21
test/test.js
@ -283,6 +283,27 @@ describe('Puppeteer', function() {
|
|||||||
|
|
||||||
expect(dumpioData).toContain(dumpioTextToLog);
|
expect(dumpioData).toContain(dumpioTextToLog);
|
||||||
});
|
});
|
||||||
|
it('should close the browser when the node process closes', async({ server }) => {
|
||||||
|
const {spawn, execSync} = require('child_process');
|
||||||
|
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), PROJECT_ROOT, JSON.stringify(defaultBrowserOptions)]);
|
||||||
|
let wsEndPointCallback;
|
||||||
|
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
||||||
|
let output = '';
|
||||||
|
res.stdout.on('data', data => {
|
||||||
|
output += data;
|
||||||
|
if (output.indexOf('\n'))
|
||||||
|
wsEndPointCallback(output.substring(0, output.indexOf('\n')));
|
||||||
|
});
|
||||||
|
const browser = await puppeteer.connect({ browserWSEndpoint: await wsEndPointPromise });
|
||||||
|
const promises = [
|
||||||
|
new Promise(resolve => browser.once('disconnected', resolve)),
|
||||||
|
new Promise(resolve => res.on('close', resolve))];
|
||||||
|
if (process.platform === 'win32')
|
||||||
|
execSync(`taskkill /pid ${res.pid} /T /F`);
|
||||||
|
else
|
||||||
|
process.kill(res.pid);
|
||||||
|
await Promise.all(promises);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('Puppeteer.connect', function() {
|
describe('Puppeteer.connect', function() {
|
||||||
it('should be able to connect multiple times to the same browser', async({server}) => {
|
it('should be able to connect multiple times to the same browser', async({server}) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user