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

fix: forwards support for fs.rm in node 14.14+ #242

Merged
merged 1 commit into from
Nov 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: forwards support for fs.rm in node 14.14+
  • Loading branch information
Lukasz Brodowski authored and Lukasz Brodowski committed Jun 14, 2021
commit 870d1f2acb85e3e04e43a5c013d457812995a7fd
7 changes: 5 additions & 2 deletions src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ class Launcher {
this.fs.closeSync(this.errFile);
delete this.errFile;
}

this.fs.rmdir(this.userDataDir, {recursive: true}, () => resolve());

// backwards support for node v12 + v14.14+
// https://nodejs.org/api/deprecations.html#DEP0147
const rm = this.fs.rm || this.fs.rmdir;
rm(this.userDataDir, {recursive: true}, () => resolve());
});
}
};
Expand Down
9 changes: 5 additions & 4 deletions test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@ describe('Launcher', () => {
});

it('accepts and uses a custom path', async () => {
const fs = {...fsMock, rmdir: spy()};
const fs = {...fsMock, rmdir: spy(), rm: spy()};
const chromeInstance =
new Launcher({userDataDir: 'some_path'}, {fs: fs as any});

chromeInstance.prepare();

await chromeInstance.destroyTmp();
assert.strictEqual(fs.rmdir.callCount, 0);
assert.strictEqual(fs.rm.callCount, 0);
});

it('cleans up the tmp dir after closing', async () => {
const rmdirMock = stub().callsFake((_path, _options, done) => done());
const fs = {...fsMock, rmdir: rmdirMock};
const rmMock = stub().callsFake((_path, _options, done) => done());
const fs = {...fsMock, rmdir: rmMock, rm: rmMock};

const chromeInstance = new Launcher({}, {fs: fs as any});

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

it('does not delete created directory when custom path passed', () => {
Expand Down