Skip to content

Commit

Permalink
move to minimum node 12; remove rimraf (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Apr 15, 2021
1 parent 673da08 commit ac1f4af
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
# awaiting support for 'latest'/'lts'. https://github.com/actions/setup-node/issues/26
node: [ '10', '12', '14' ]
node: [ '12', '14', '15' ]
name: basics (node ${{ matrix.node }})

steps:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Chrome Launcher [![Linux Build Status](https://img.shields.io/travis/GoogleChrome/chrome-launcher/master.svg)](https://travis-ci.org/GoogleChrome/chrome-launcher) [![Windows Build Status](https://img.shields.io/appveyor/ci/paulirish/chrome-launcher/master.svg)](https://ci.appveyor.com/project/paulirish/chrome-launcher/branch/master) [![NPM chrome-launcher package](https://img.shields.io/npm/v/chrome-launcher.svg)](https://npmjs.org/package/chrome-launcher)

# Chrome Launcher [![GitHub Actions Status Badge](https://github.com/GoogleChrome/chrome-launcher/workflows/🛠/badge.svg)](https://github.com/GoogleChrome/chrome-launcher/actions) [![NPM chrome-launcher package](https://img.shields.io/npm/v/chrome-launcher.svg)](https://npmjs.org/package/chrome-launcher)

<img src="https://user-images.githubusercontent.com/39191/29847271-a7ba82f8-8ccf-11e7-8d54-eb88fdf0b6d0.png" align=right height=200>

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "chrome-launcher",
"main": "./dist/index.js",
"engines": {
"node": ">=12.13.0"
},
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"test": "mocha --require ts-node/register --reporter=dot test/**/*-test.ts --timeout=10000",
"test-formatting": "test/check-formatting.sh",
"format": "scripts/format.sh",
"type-check": "tsc --allowJs --checkJs --noEmit --target es2016 *.js",
"type-check": "tsc --allowJs --checkJs --noEmit --target es2019 *.js",
"prepublishOnly": "npm run build && npm run test"
},
"devDependencies": {
"@types/mocha": "^8.0.4",
"@types/rimraf": "^3.0.0",
"@types/sinon": "^9.0.1",
"clang-format": "^1.0.50",
"mocha": "^8.2.1",
Expand All @@ -24,8 +26,7 @@
"@types/node": "*",
"escape-string-regexp": "^4.0.0",
"is-wsl": "^2.2.0",
"lighthouse-logger": "^1.0.0",
"rimraf": "^3.0.2"
"lighthouse-logger": "^1.0.0"
},
"version": "0.13.4",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 1 addition & 7 deletions src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as childProcess from 'child_process';
import * as fs from 'fs';
import * as net from 'net';
import * as rimraf from 'rimraf';
import * as chromeFinder from './chrome-finder';
import {getRandomPort} from './random-port';
import {DEFAULT_FLAGS} from './flags';
Expand All @@ -27,8 +26,6 @@ type SupportedPlatforms = 'darwin'|'linux'|'win32'|'wsl';

const instances = new Set<Launcher>();

export type RimrafModule = (path: string, callback: (error: Error) => void) => void;

export interface Options {
startingUrl?: string;
chromeFlags?: Array<string>;
Expand All @@ -52,7 +49,6 @@ export interface LaunchedChrome {

export interface ModuleOverrides {
fs?: typeof fs;
rimraf?: RimrafModule;
spawn?: typeof childProcess.spawn;
}

Expand Down Expand Up @@ -113,7 +109,6 @@ class Launcher {
private connectionPollInterval: number;
private maxConnectionRetries: number;
private fs: typeof fs;
private rimraf: RimrafModule;
private spawn: typeof childProcess.spawn;
private useDefaultProfile: boolean;
private envVars: {[key: string]: string|undefined};
Expand All @@ -125,7 +120,6 @@ class Launcher {

constructor(private opts: Options = {}, moduleOverrides: ModuleOverrides = {}) {
this.fs = moduleOverrides.fs || fs;
this.rimraf = moduleOverrides.rimraf || rimraf;
this.spawn = moduleOverrides.spawn || spawn;

log.setLevel(defaults(this.opts.logLevel, 'silent'));
Expand Down Expand Up @@ -384,7 +378,7 @@ class Launcher {
delete this.errFile;
}

this.rimraf(this.userDataDir, () => resolve());
this.fs.rmdir(this.userDataDir, {recursive: true}, () => resolve());
});
}
};
Expand Down
18 changes: 10 additions & 8 deletions test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ const log = require('lighthouse-logger');
const fsMock = {
openSync: () => {},
closeSync: () => {},
writeFileSync: () => {}
writeFileSync: () => {},
rmdir: () => {},
};

const launchChromeWithOpts = async (opts: Options = {}) => {
const spawnStub = stub().returns({pid: 'some_pid'});

const chromeInstance =
new Launcher(opts, {fs: fsMock as any, rimraf: spy() as any, spawn: spawnStub as any});
new Launcher(opts, {fs: fsMock as any, spawn: spawnStub as any});
stub(chromeInstance, 'waitUntilReady').returns(Promise.resolve());

chromeInstance.prepare();
Expand Down Expand Up @@ -53,24 +54,25 @@ describe('Launcher', () => {
});

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

chromeInstance.prepare();

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

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

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

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

it('does not delete created directory when custom path passed', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"target": "es2016",
"target": "es2019",
"declaration": true,
"noImplicitAny": true,
"inlineSourceMap": true,
Expand Down
30 changes: 1 addition & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@
resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5"
integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==

"@types/glob@*":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/mocha@^8.0.4":
version "8.0.4"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.0.4.tgz#b840c2dce46bacf286e237bfb59a29e843399148"
Expand All @@ -61,14 +48,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.10.tgz#5958a82e41863cfc71f2307b3748e3491ba03785"
integrity sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==

"@types/rimraf@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-3.0.0.tgz#b9d03f090ece263671898d57bb7bb007023ac19f"
integrity sha512-7WhJ0MdpFgYQPXlF4Dx+DhgvlPCfz/x5mHaeDQAKhcenvQP1KCpLQ18JklAqeGMYSAT2PxLpzd0g2/HE7fj7hQ==
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/sinon@^9.0.1":
version "9.0.9"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-9.0.9.tgz#115843b491583f924080f684b6d0d7438344f73c"
Expand Down Expand Up @@ -358,7 +337,7 @@ glob-parent@~5.1.0:
dependencies:
is-glob "^4.0.1"

[email protected], glob@^7.0.0, glob@^7.1.3:
[email protected], glob@^7.0.0:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
Expand Down Expand Up @@ -699,13 +678,6 @@ resolve@^1.1.6:
is-core-module "^2.1.0"
path-parse "^1.0.6"

rimraf@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
dependencies:
glob "^7.1.3"

safe-buffer@^5.1.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
Expand Down

0 comments on commit ac1f4af

Please sign in to comment.