Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LaunchedChrome.kill sync #269

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});