Skip to content

Commit

Permalink
fix(workers): emit workerdestroyed event when clearing workers (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored and aslushnikov committed Jan 24, 2020
1 parent 056fbbd commit 060fbf7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ export class Page extends platform.EventEmitter {
}

_clearWorkers() {
this._workers.clear();
for (const [workerId, worker] of this._workers) {
this.emit(Events.Page.WorkerDestroyed, worker);
this._workers.delete(workerId);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/workers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,22 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(1)'], {type: 'application/javascript'}))));
await workerCreatedPromise;
expect(page.workers().length).toBe(1);
let destroyed = false;
page.once('workerdestroyed', () => destroyed = true);
await page.goto(server.PREFIX + '/one-style.html');
expect(destroyed).toBe(true);
expect(page.workers().length).toBe(0);
});
it('should clear upon cross-process navigation', async function({server, page}) {
await page.goto(server.EMPTY_PAGE);
const workerCreatedPromise = page.waitForEvent('workercreated');
page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log(1)'], {type: 'application/javascript'}))));
await workerCreatedPromise;
expect(page.workers().length).toBe(1);
let destroyed = false;
page.once('workerdestroyed', () => destroyed = true);
await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(destroyed).toBe(true);
expect(page.workers().length).toBe(0);
});
it('should report network activity', async function({page, server}) {
Expand Down

0 comments on commit 060fbf7

Please sign in to comment.