Skip to content

Commit

Permalink
Make LaunchedChrome.kill sync (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebeby committed Jun 9, 2022
1 parent 0bd5a5d commit 1cbf8b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface LaunchedChrome {
pid: number;
port: number;
process: ChildProcess;
kill: () => Promise<void>;
kill: () => void;
}

export interface ModuleOverrides {
Expand All @@ -72,12 +72,12 @@ async function launch(opts: Options = {}): Promise<LaunchedChrome> {

await instance.launch();

const kill = async () => {
const kill = () => {
instances.delete(instance);
if (instances.size === 0) {
process.removeListener(_SIGINT, sigintListener);
}
return instance.kill();
instance.kill();
};

return {pid: instance.pid!, port: instance.port!, kill, process: instance.chromeProcess!};
Expand Down
12 changes: 6 additions & 6 deletions test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Launcher', () => {

chromeInstance.prepare();

await chromeInstance.destroyTmp();
chromeInstance.destroyTmp();
assert.strictEqual(fs.rmdirSync.callCount, 0);
assert.strictEqual(fs.rmSync.callCount, 0);
});
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Launcher', () => {
const chromeInstance = new Launcher({}, {fs: fs as any});

chromeInstance.prepare();
await chromeInstance.destroyTmp();
chromeInstance.destroyTmp();
assert.strictEqual(rmMock.callCount, 1);
});

Expand Down Expand Up @@ -149,14 +149,14 @@ describe('Launcher', () => {
it('doesn\'t fail when killed twice', async () => {
const chromeInstance = new Launcher();
await chromeInstance.launch();
await chromeInstance.kill();
await chromeInstance.kill();
chromeInstance.kill();
chromeInstance.kill();
}).timeout(30 * 1000);

it('doesn\'t fail when killing all instances', async () => {
await launch();
await launch();
const errors = await killAll();
const errors = killAll();
assert.strictEqual(errors.length, 0);
});

Expand All @@ -166,7 +166,7 @@ describe('Launcher', () => {
let pid = chromeInstance.pid!;
await chromeInstance.launch();
assert.strictEqual(pid, chromeInstance.pid);
await chromeInstance.kill();
chromeInstance.kill();
});

it('gets all default flags', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/launch-signature-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ describe('Launcher', () => {
assert.notStrictEqual(chrome.pid, undefined);
assert.notStrictEqual(chrome.port, undefined);
assert.notStrictEqual(chrome.kill, undefined);
await chrome.kill();
chrome.kill();
});
});

0 comments on commit 1cbf8b9

Please sign in to comment.