fix(test): add missing test for making sure chrome is closed (#2109)

This commit is contained in:
JoelEinbinder 2018-03-06 22:01:43 -08:00 committed by Andrey Lushnikov
parent 44d8000de1
commit 0defecf197
2 changed files with 26 additions and 0 deletions

5
test/fixtures/closeme.js vendored Normal file
View File

@ -0,0 +1,5 @@
(async() => {
const [, , puppeteerRoot, options] = process.argv;
const browser = await require(puppeteerRoot).launch(JSON.parse(options));
console.log(browser.wsEndpoint());
})();

View File

@ -283,6 +283,27 @@ describe('Puppeteer', function() {
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() {
it('should be able to connect multiple times to the same browser', async({server}) => {