From dbdf9e24598cf2879f817f8a2245c9e860d57977 Mon Sep 17 00:00:00 2001 From: Aniket Kudale Date: Fri, 23 Dec 2016 00:31:00 +0530 Subject: [PATCH] chore: Added prefer-const to eslint and related changes (#700) --- .eslintrc | 1 + src/cmd/build.js | 12 +++--- src/cmd/run.js | 16 ++++---- src/cmd/sign.js | 6 +-- src/firefox/index.js | 6 +-- src/firefox/preferences.js | 9 +++-- src/firefox/remote.js | 2 +- src/program.js | 6 +-- src/util/logger.js | 2 +- src/util/manifest.js | 4 +- src/util/temp-dir.js | 6 +-- tests/functional/test.cli.lint.js | 2 +- tests/unit/helpers.js | 4 +- tests/unit/test-cmd/test.build.js | 6 +-- tests/unit/test-cmd/test.run.js | 10 ++--- tests/unit/test-cmd/test.sign.js | 8 ++-- tests/unit/test-firefox/test.firefox.js | 44 ++++++++++----------- tests/unit/test-firefox/test.preferences.js | 6 +-- tests/unit/test-util/test.artifacts.js | 4 +- tests/unit/test-util/test.is-directory.js | 2 +- tests/unit/test-util/test.logger.js | 2 +- tests/unit/test-util/test.manifest.js | 16 ++++---- tests/unit/test-util/test.temp-dir.js | 2 +- tests/unit/test.program.js | 42 ++++++++++---------- 24 files changed, 110 insertions(+), 108 deletions(-) diff --git a/.eslintrc b/.eslintrc index 586906716a..3edf4e00d0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -103,6 +103,7 @@ }], "object-shorthand": 2, "one-var": [2, "never"], + "prefer-const": 2, "prefer-template": 2, "quote-props": [1, "consistent-as-needed"], "quotes": [2, "single", "avoid-escape"], diff --git a/src/cmd/build.js b/src/cmd/build.js index ebb8747623..79096bab1b 100644 --- a/src/cmd/build.js +++ b/src/cmd/build.js @@ -104,23 +104,23 @@ async function defaultPackageCreator({ manifestData = await getValidatedManifest(sourceDir); } - let buffer = await zipDir(sourceDir, { + const buffer = await zipDir(sourceDir, { filter: (...args) => fileFilter.wantFile(...args), }); let extensionName: string = manifestData.name; if (manifestData.default_locale) { - let messageFile = path.join(sourceDir, '_locales', + const messageFile = path.join(sourceDir, '_locales', manifestData.default_locale, 'messages.json'); log.debug('Manifest declared default_locale, localizing extension name'); extensionName = await getDefaultLocalizedName( {messageFile, manifestData}); } - let packageName = safeFileName( + const packageName = safeFileName( `${extensionName}-${manifestData.version}.zip`); - let extensionPath = path.join(artifactsDir, packageName); - let stream = createWriteStream(extensionPath); + const extensionPath = path.join(artifactsDir, packageName); + const stream = createWriteStream(extensionPath); stream.write(buffer, () => stream.end()); @@ -166,7 +166,7 @@ export default async function build( }); await prepareArtifactsDir(artifactsDir); - let result = await createPackage(); + const result = await createPackage(); if (rebuildAsNeeded) { log.info('Rebuilding when files change...'); diff --git a/src/cmd/run.js b/src/cmd/run.js index 4e335ca39e..6f9ed7c6cb 100644 --- a/src/cmd/run.js +++ b/src/cmd/run.js @@ -82,14 +82,15 @@ export function defaultReloadStrategy( createWatcher = defaultWatcherCreator, }: ReloadStrategyOptions = {} ): void { - let watcher: Watchpack; + const watcher: Watchpack = ( + createWatcher({addonId, client, sourceDir, artifactsDir}) + ); firefoxProcess.on('close', () => { client.disconnect(); watcher.close(); }); - watcher = createWatcher({addonId, client, sourceDir, artifactsDir}); } @@ -181,15 +182,12 @@ export default async function run( const requiresRemote = !preInstall; let installed = false; - let runner; - let profile; let client; - let runningFirefox; let addonId; - let manifestData = await getValidatedManifest(sourceDir); + const manifestData = await getValidatedManifest(sourceDir); - runner = new ExtensionRunner({ + const runner = new ExtensionRunner({ sourceDir, firefoxApp, firefox, @@ -198,7 +196,7 @@ export default async function run( customPrefs, }); - profile = await runner.getProfile(); + const profile = await runner.getProfile(); if (!preInstall) { log.debug('Deferring extension installation until after ' + @@ -209,7 +207,7 @@ export default async function run( installed = true; } - runningFirefox = await runner.run(profile); + const runningFirefox = await runner.run(profile); if (installed) { log.debug('Not installing as temporary add-on because the ' + diff --git a/src/cmd/sign.js b/src/cmd/sign.js index ed226d54b9..d25a9e0570 100644 --- a/src/cmd/sign.js +++ b/src/cmd/sign.js @@ -65,7 +65,7 @@ export default function sign( manifestData = await getValidatedManifest(sourceDir); } - let [buildResult, idFromSourceDir] = await Promise.all([ + const [buildResult, idFromSourceDir] = await Promise.all([ build({sourceDir, artifactsDir: tmpDir.path()}, {manifestData, showReadyMessage: false}), getIdFromSourceDir(sourceDir), @@ -93,7 +93,7 @@ export default function sign( log.warn('No extension ID specified (it will be auto-generated)'); } - let signingResult = await signAddon({ + const signingResult = await signAddon({ apiKey, apiSecret, apiUrlPrefix, @@ -152,7 +152,7 @@ export async function getIdFromSourceDir( } }); - let id = lines[0]; + const id = lines[0]; log.debug(`Found extension ID ${id} in ${filePath}`); if (!id) { diff --git a/src/firefox/index.js b/src/firefox/index.js index 401970fe72..5278e58fe0 100644 --- a/src/firefox/index.js +++ b/src/firefox/index.js @@ -211,7 +211,7 @@ export function configureProfile( ): Promise { // Set default preferences. Some of these are required for the add-on to // operate, such as disabling signatures. - let prefs = getPrefs(app); + const prefs = getPrefs(app); Object.keys(prefs).forEach((pref) => { profile.setPreference(pref, prefs[pref]); }); @@ -283,8 +283,8 @@ export async function copyProfile( }: CopyProfileOptions = {}, ): Promise { - let copy = promisify(FirefoxProfile.copy); - let copyByName = promisify(copyFromUserProfile); + const copy = promisify(FirefoxProfile.copy); + const copyByName = promisify(copyFromUserProfile); try { const dirExists = await isDirectory(profileDirectory); diff --git a/src/firefox/preferences.js b/src/firefox/preferences.js index bf0309c0a7..3a5bfe49e4 100644 --- a/src/firefox/preferences.js +++ b/src/firefox/preferences.js @@ -127,14 +127,17 @@ export function getPrefs( export function coerceCLICustomPreference( cliPrefs: string | Array ): FirefoxPreferences { - let customPrefs = {}; + const customPrefs = {}; if (!Array.isArray(cliPrefs)) { cliPrefs = [cliPrefs]; } - for (let pref of cliPrefs) { - let [key, value] = pref.split('='); + + for (const pref of cliPrefs) { + const prefsAry = pref.split('='); + const key = prefsAry[0]; + let value = prefsAry[1]; if (/[^\w{@}.-]/.test(key)) { throw new UsageError(`Invalid custom preference name: ${key}`); diff --git a/src/firefox/remote.js b/src/firefox/remote.js index 4e8d105139..a2a703342d 100644 --- a/src/firefox/remote.js +++ b/src/firefox/remote.js @@ -154,7 +154,7 @@ export class RemoteFirefox { const response = await this.addonRequest(addon, 'requestTypes'); if (response.requestTypes.indexOf('reload') === -1) { - let supportedRequestTypes = JSON.stringify(response.requestTypes); + const supportedRequestTypes = JSON.stringify(response.requestTypes); log.debug( `Remote Firefox only supports: ${supportedRequestTypes}`); throw new UsageError( diff --git a/src/program.js b/src/program.js index 9a1795f3f5..18fcdfefdc 100644 --- a/src/program.js +++ b/src/program.js @@ -98,7 +98,7 @@ export class Program { // Command line option (pref) renamed for internal use (customPref). argv.customPrefs = argv.pref; - let runCommand = this.commands[cmd]; + const runCommand = this.commands[cmd]; if (argv.verbose) { logStream.makeVerbose(); @@ -147,7 +147,7 @@ export function defaultVersionGetter( ): string { if (localEnv === 'production') { log.debug('Getting the version from package.json'); - let packageData: any = readFileSync( + const packageData: any = readFileSync( path.join(absolutePackageDir, 'package.json')); return JSON.parse(packageData).version; } else { @@ -164,7 +164,7 @@ export function main( runOptions = {}, }: Object = {} ): Promise { - let program = new Program(argv, {absolutePackageDir}); + const program = new Program(argv, {absolutePackageDir}); // yargs uses magic camel case expansion to expose options on the // final argv object. For example, the 'artifacts-dir' option is alternatively // available as argv.artifactsDir. diff --git a/src/util/logger.js b/src/util/logger.js index 1fe6b8e474..5206b90794 100644 --- a/src/util/logger.js +++ b/src/util/logger.js @@ -84,7 +84,7 @@ export class ConsoleStream { } flushCapturedLogs({localProcess = process}: ConsoleOptions = {}) { - for (let msg of this.capturedMessages) { + for (const msg of this.capturedMessages) { localProcess.stdout.write(msg); } this.capturedMessages = []; diff --git a/src/util/manifest.js b/src/util/manifest.js index 8da616f9ad..6c694a996b 100644 --- a/src/util/manifest.js +++ b/src/util/manifest.js @@ -31,7 +31,7 @@ export type ExtensionManifest = {| export default async function getValidatedManifest( sourceDir: string ): Promise { - let manifestFile = path.join(sourceDir, 'manifest.json'); + const manifestFile = path.join(sourceDir, 'manifest.json'); log.debug(`Validating manifest at ${manifestFile}`); let manifestContents; @@ -52,7 +52,7 @@ export default async function getValidatedManifest( `Error parsing manifest.json at ${manifestFile}: ${error}`); } - let errors = []; + const errors = []; // This is just some basic validation of what web-ext needs, not // what Firefox will need to run the extension. // TODO: integrate with the addons-linter for actual validation. diff --git a/src/util/temp-dir.js b/src/util/temp-dir.js index ec0c6c560b..7c154354df 100644 --- a/src/util/temp-dir.js +++ b/src/util/temp-dir.js @@ -23,7 +23,7 @@ const log = createLogger(__filename); * */ export function withTempDir(makePromise: Function): Promise { - let tmpDir = new TempDir(); + const tmpDir = new TempDir(); return tmpDir.create() .then(() => { return makePromise(tmpDir); @@ -62,7 +62,7 @@ export class TempDir { * been created. */ create(): Promise { - let createTempDir = promisify(tmp.dir, {multiArgs: true}); + const createTempDir = promisify(tmp.dir, {multiArgs: true}); return createTempDir( { prefix: 'tmp-web-ext-', @@ -70,7 +70,7 @@ export class TempDir { unsafeCleanup: true, }) .then((args) => { - let [tmpPath, removeTempDir] = args; + const [tmpPath, removeTempDir] = args; this._path = tmpPath; this._removeTempDir = removeTempDir; log.debug(`Created temporary directory: ${this.path()}`); diff --git a/tests/functional/test.cli.lint.js b/tests/functional/test.cli.lint.js index 44b65b9582..491f7ab5f6 100644 --- a/tests/functional/test.cli.lint.js +++ b/tests/functional/test.cli.lint.js @@ -10,7 +10,7 @@ describe('web-ext lint', () => { it('should accept: --source-dir SRCDIR', () => withTempAddonDir({addonPath}, (srcDir, tmpDir) => { const argv = ['lint', '--source-dir', srcDir, '--verbose']; - let cmd = execCommand(webExt, argv, {cwd: tmpDir}); + const cmd = execCommand(webExt, argv, {cwd: tmpDir}); return cmd.waitForExit.then(({exitCode, stdout, stderr}) => { if (exitCode !== 0) { diff --git a/tests/unit/helpers.js b/tests/unit/helpers.js index 84b4720c92..e7cecbd69a 100644 --- a/tests/unit/helpers.js +++ b/tests/unit/helpers.js @@ -148,11 +148,11 @@ export function fake(original: Object, methods: Object = {}): T { } var proto = Object.getPrototypeOf(original); - for (let key of props) { + for (const key of props) { if (!original.hasOwnProperty(key) && !proto.hasOwnProperty(key)) { continue; } - let definition = original[key] || proto[key]; + const definition = original[key] || proto[key]; if (typeof definition === 'function') { stub[key] = () => { log.warn(`Running stubbed function ${key} (default implementation)`); diff --git a/tests/unit/test-cmd/test.build.js b/tests/unit/test-cmd/test.build.js index 56e2817392..9d7be1c7e2 100644 --- a/tests/unit/test-cmd/test.build.js +++ b/tests/unit/test-cmd/test.build.js @@ -25,7 +25,7 @@ const log = createLogger(__filename); describe('build', () => { it('zips a package', () => { - let zipFile = new ZipFile(); + const zipFile = new ZipFile(); return withTempDir( (tmpDir) => @@ -201,8 +201,8 @@ describe('build', () => { )); it('asks FileFilter what files to include in the ZIP', () => { - let zipFile = new ZipFile(); - let fileFilter = new FileFilter({ + const zipFile = new ZipFile(); + const fileFilter = new FileFilter({ filesToIgnore: ['**/background-script.js'], }); diff --git a/tests/unit/test-cmd/test.run.js b/tests/unit/test-cmd/test.run.js index 08d860d380..13835ae414 100644 --- a/tests/unit/test-cmd/test.run.js +++ b/tests/unit/test-cmd/test.run.js @@ -32,12 +32,12 @@ describe('run', () => { function prepareRun(fakeInstallResult) { const sourceDir = fixturePath('minimal-web-ext'); - let argv = { + const argv = { artifactsDir: path.join(sourceDir, 'web-ext-artifacts'), sourceDir, noReload: true, }; - let options = { + const options = { firefoxApp: getFakeFirefox(), firefoxClient: sinon.spy(() => { return Promise.resolve(fake(RemoteFirefox.prototype, { @@ -63,8 +63,8 @@ describe('run', () => { } function getFakeFirefox(implementations = {}) { - let profile = {}; // empty object just to avoid errors. - let allImplementations = { + const profile = {}; // empty object just to avoid errors. + const allImplementations = { createProfile: () => Promise.resolve(profile), copyProfile: () => Promise.resolve(profile), installExtension: () => Promise.resolve(), @@ -76,7 +76,7 @@ describe('run', () => { it('installs and runs the extension', () => { - let profile = {}; + const profile = {}; const cmd = prepareRun(); const {firefoxApp} = cmd.options; diff --git a/tests/unit/test-cmd/test.sign.js b/tests/unit/test-cmd/test.sign.js index 6b4b49213d..6d06e3c34e 100644 --- a/tests/unit/test-cmd/test.sign.js +++ b/tests/unit/test-cmd/test.sign.js @@ -234,7 +234,7 @@ describe('sign', () => { it('returns a signing result', () => withTempDir( (tmpDir) => { - let stubs = getStubs(); + const stubs = getStubs(); return sign(tmpDir, stubs) .then((realResult) => { assert.deepEqual(realResult, stubs.signingResult); @@ -267,7 +267,7 @@ describe('sign', () => { return sign(tmpDir, stubs, {extraArgs: {artifactsDir}}) .then(() => { assert.equal(stubs.signAddon.called, true); - let signedAddonCall = stubs.signAddon.firstCall.args[0]; + const signedAddonCall = stubs.signAddon.firstCall.args[0]; assert.equal(signedAddonCall.apiKey, stubs.signingConfig.apiKey); assert.equal(signedAddonCall.apiSecret, @@ -294,7 +294,7 @@ describe('sign', () => { it('passes the verbose flag to the signer', () => withTempDir( (tmpDir) => { - let stubs = getStubs(); + const stubs = getStubs(); return sign(tmpDir, stubs, {extraArgs: {verbose: true}}) .then(() => { assert.equal(stubs.signAddon.called, true); @@ -305,7 +305,7 @@ describe('sign', () => { it('passes through a signing exception', () => withTempDir( (tmpDir) => { - let stubs = getStubs(); + const stubs = getStubs(); stubs.signAddon = () => Promise.reject(new Error('some signing error')); return sign(tmpDir, stubs) diff --git a/tests/unit/test-firefox/test.firefox.js b/tests/unit/test-firefox/test.firefox.js index 78b6beb20f..73c55e8879 100644 --- a/tests/unit/test-firefox/test.firefox.js +++ b/tests/unit/test-firefox/test.firefox.js @@ -37,7 +37,7 @@ describe('firefox', () => { }; function createFakeFxRunner(firefoxOverrides = {}) { - let firefox = { + const firefox = { ...deepcopy(fakeFirefoxProcess), ...firefoxOverrides, }; @@ -89,13 +89,13 @@ describe('firefox', () => { }); it('sets up a Firefox process environment', () => { - let runner = createFakeFxRunner(); + const runner = createFakeFxRunner(); // Make sure it passes through process environment variables. process.env._WEB_EXT_FIREFOX_ENV_TEST = 'thing'; return runFirefox({fxRunner: runner}) .then(() => { - let declaredEnv = runner.firstCall.args[0].env; - for (let key in defaultFirefoxEnv) { + const declaredEnv = runner.firstCall.args[0].env; + for (const key in defaultFirefoxEnv) { assert.equal(declaredEnv[key], defaultFirefoxEnv[key]); } assert.equal(declaredEnv._WEB_EXT_FIREFOX_ENV_TEST, 'thing'); @@ -103,8 +103,8 @@ describe('firefox', () => { }); it('fails on a firefox error', () => { - let someError = new Error('some internal firefox error'); - let runner = createFakeFxRunner({ + const someError = new Error('some internal firefox error'); + const runner = createFakeFxRunner({ on: (eventName, callback) => { if (eventName === 'error') { // Immediately "emit" an error event. @@ -121,8 +121,8 @@ describe('firefox', () => { }); it('passes a custom Firefox binary when specified', () => { - let runner = createFakeFxRunner(); - let firefoxBinary = '/pretend/path/to/firefox-bin'; + const runner = createFakeFxRunner(); + const firefoxBinary = '/pretend/path/to/firefox-bin'; return runFirefox({fxRunner: runner, firefoxBinary}) .then(() => { assert.equal(runner.called, true); @@ -163,7 +163,7 @@ describe('firefox', () => { function withBaseProfile(callback) { return withTempDir( (tmpDir) => { - let baseProfile = new FirefoxProfile({ + const baseProfile = new FirefoxProfile({ destinationDirectory: tmpDir.path(), }); return callback(baseProfile); @@ -189,7 +189,7 @@ describe('firefox', () => { // This stubs out the code that looks for a named // profile because on Travis CI there will not be a Firefox // user directory. - let copyFromUserProfile = sinon.spy( + const copyFromUserProfile = sinon.spy( (config, cb) => cb(new Error('simulated: could not find profile'))); return firefox.copyProfile('/dev/null/non_existent_path', @@ -207,14 +207,14 @@ describe('firefox', () => { }); it('can copy a profile by name', () => { - let name = 'some-fake-firefox-profile-name'; + const name = 'some-fake-firefox-profile-name'; // Fake profile object: - let profileToCopy = { + const profileToCopy = { defaultPreferences: { thing: 'value', }, }; - let copyFromUserProfile = sinon.spy( + const copyFromUserProfile = sinon.spy( (config, callback) => callback(null, profileToCopy)); return firefox.copyProfile(name, @@ -232,8 +232,8 @@ describe('firefox', () => { it('configures the copied profile', () => withBaseProfile( (baseProfile) => { - let app = 'fennec'; - let configureThisProfile = + const app = 'fennec'; + const configureThisProfile = sinon.spy((profile) => Promise.resolve(profile)); return firefox.copyProfile(baseProfile.path(), @@ -275,9 +275,9 @@ describe('firefox', () => { }); it('configures a profile', () => { - let configureThisProfile = + const configureThisProfile = sinon.spy((profile) => Promise.resolve(profile)); - let app = 'fennec'; + const app = 'fennec'; return firefox.createProfile({app, configureThisProfile}) .then((profile) => { assert.equal(configureThisProfile.called, true); @@ -292,7 +292,7 @@ describe('firefox', () => { function withTempProfile(callback) { return withTempDir((tmpDir) => { - let profile = new FirefoxProfile({ + const profile = new FirefoxProfile({ destinationDirectory: tmpDir.path(), }); return callback(profile); @@ -301,7 +301,7 @@ describe('firefox', () => { it('resolves with a profile', () => withTempProfile( (profile) => { - let fakePrefGetter = sinon.stub().returns({}); + const fakePrefGetter = sinon.stub().returns({}); return firefox.configureProfile(profile, {getPrefs: fakePrefGetter}) .then((profile) => { assert.instanceOf(profile, FirefoxProfile); @@ -311,7 +311,7 @@ describe('firefox', () => { it('sets Firefox preferences', () => withTempProfile( (profile) => { - let fakePrefGetter = sinon.stub().returns({}); + const fakePrefGetter = sinon.stub().returns({}); return firefox.configureProfile(profile, {getPrefs: fakePrefGetter}) .then(() => { assert.equal(fakePrefGetter.firstCall.args[0], 'firefox'); @@ -321,7 +321,7 @@ describe('firefox', () => { it('sets Fennec preferences', () => withTempProfile( (profile) => { - let fakePrefGetter = sinon.stub().returns({}); + const fakePrefGetter = sinon.stub().returns({}); return firefox.configureProfile( profile, { getPrefs: fakePrefGetter, @@ -370,7 +370,7 @@ describe('firefox', () => { function setUp(testPromise: Function) { return withTempDir( (tmpDir) => { - let data = { + const data = { extensionPath: fixturePath('minimal_extension-1.0.zip'), profile: undefined, profileDir: path.join(tmpDir.path(), 'profile'), diff --git a/tests/unit/test-firefox/test.preferences.js b/tests/unit/test-firefox/test.preferences.js index 84e44fc402..356bac9256 100644 --- a/tests/unit/test-firefox/test.preferences.js +++ b/tests/unit/test-firefox/test.preferences.js @@ -13,7 +13,7 @@ describe('firefox/preferences', () => { describe('getPrefs', () => { it('gets Firefox prefs with some defaults', () => { - let prefs = getPrefs(); + const prefs = getPrefs(); // This is a commonly shared pref. assert.equal(prefs['devtools.debugger.remote-enabled'], true); // This is a Firefox only pref. @@ -21,7 +21,7 @@ describe('firefox/preferences', () => { }); it('gets Fennec prefs with some defaults', () => { - let prefs = getPrefs('fennec'); + const prefs = getPrefs('fennec'); // This is a commonly shared pref. assert.equal(prefs['devtools.debugger.remote-enabled'], true); // This is a Fennec only pref. @@ -73,7 +73,7 @@ describe('firefox/preferences', () => { return prop += '=true'; }); const prefs = coerceCLICustomPreference(nonChangeablePrefs); - for (let pref of nonChangeablePrefs) { + for (const pref of nonChangeablePrefs) { assert.isUndefined(prefs[pref], `${pref} should be undefined`); } }); diff --git a/tests/unit/test-util/test.artifacts.js b/tests/unit/test-util/test.artifacts.js index 9d10e4ae36..b0113aee85 100644 --- a/tests/unit/test-util/test.artifacts.js +++ b/tests/unit/test-util/test.artifacts.js @@ -15,7 +15,7 @@ describe('prepareArtifactsDir', () => { it('creates an artifacts dir if needed', () => withTempDir( (tmpDir) => { - let artifactsDir = path.join(tmpDir.path(), 'build'); + const artifactsDir = path.join(tmpDir.path(), 'build'); return prepareArtifactsDir(artifactsDir) .then(() => { // This should not throw an error if created properly. @@ -35,7 +35,7 @@ describe('prepareArtifactsDir', () => { it('ensures the path is really a directory', () => withTempDir( (tmpDir) => { - let someFile = path.join(tmpDir.path(), 'some-file.txt'); + const someFile = path.join(tmpDir.path(), 'some-file.txt'); return fs.writeFile(someFile, 'some content') .then(() => prepareArtifactsDir(someFile)) .then(makeSureItFails()) diff --git a/tests/unit/test-util/test.is-directory.js b/tests/unit/test-util/test.is-directory.js index e781341c46..1fc1f49395 100644 --- a/tests/unit/test-util/test.is-directory.js +++ b/tests/unit/test-util/test.is-directory.js @@ -29,7 +29,7 @@ describe('util.isDirectory', () => { it('resolves false for non-directory paths', () => withTempDir( (tmpDir) => { - let filePath = path.join(tmpDir.path(), 'some.txt'); + const filePath = path.join(tmpDir.path(), 'some.txt'); return fs.writeFile(filePath, 'some text') .then(() => isDirectory(filePath)) .then((dirExists) => { diff --git a/tests/unit/test-util/test.logger.js b/tests/unit/test-util/test.logger.js index 2f44affd99..f002c2282b 100644 --- a/tests/unit/test-util/test.logger.js +++ b/tests/unit/test-util/test.logger.js @@ -40,7 +40,7 @@ describe('logger', () => { } } - let fakeWritableStream = new FakeWritableStream(); + const fakeWritableStream = new FakeWritableStream(); sinon.spy(fakeWritableStream, 'write'); return { diff --git a/tests/unit/test-util/test.manifest.js b/tests/unit/test-util/test.manifest.js index 8b76683855..17a2d356de 100644 --- a/tests/unit/test-util/test.manifest.js +++ b/tests/unit/test-util/test.manifest.js @@ -49,7 +49,7 @@ describe('util/manifest', () => { )); it('reports an error for a missing manifest file', () => { - let nonExistentDir = '/dev/null/nowhere/'; + const nonExistentDir = '/dev/null/nowhere/'; return getValidatedManifest(nonExistentDir) .then(makeSureItFails()) .catch(onlyInstancesOf(InvalidManifest, (error) => { @@ -62,11 +62,11 @@ describe('util/manifest', () => { it('reports an error for invalid manifest JSON', () => withTempDir( (tmpDir) => { - let badManifest = `{ + const badManifest = `{ "name": "I'm an invalid JSON Manifest "version": "0.0.0" }`; - let manifestFile = path.join(tmpDir.path(), 'manifest.json'); + const manifestFile = path.join(tmpDir.path(), 'manifest.json'); return fs.writeFile(manifestFile, badManifest) .then(() => getValidatedManifest(tmpDir.path())) .then(makeSureItFails()) @@ -80,7 +80,7 @@ describe('util/manifest', () => { it('reports an error when missing a name', () => withTempDir( (tmpDir) => { - let noNameManifest = deepcopy(basicManifest); + const noNameManifest = deepcopy(basicManifest); delete noNameManifest.name; return writeManifest(tmpDir.path(), noNameManifest) @@ -99,7 +99,7 @@ describe('util/manifest', () => { it('reports an error when missing version', () => withTempDir( (tmpDir) => { - let noVersionManifest = deepcopy(basicManifest); + const noVersionManifest = deepcopy(basicManifest); delete noVersionManifest.version; return writeManifest(tmpDir.path(), noVersionManifest) @@ -118,7 +118,7 @@ describe('util/manifest', () => { it('reports an error when missing applications.gecko', () => withTempDir( (tmpDir) => { - let incompleteManifest = deepcopy(basicManifest); + const incompleteManifest = deepcopy(basicManifest); delete incompleteManifest.applications.gecko; return writeManifest(tmpDir.path(), incompleteManifest) @@ -150,7 +150,7 @@ describe('util/manifest', () => { it('concatenates errors in error message', () => withTempDir( (tmpDir) => { - let manifestWithErrors = deepcopy(basicManifest); + const manifestWithErrors = deepcopy(basicManifest); delete manifestWithErrors.name; delete manifestWithErrors.version; @@ -186,7 +186,7 @@ describe('util/manifest', () => { function writeManifest(destDir, manifestData) { - let manifestFile = path.join(destDir, 'manifest.json'); + const manifestFile = path.join(destDir, 'manifest.json'); return fs.writeFile(manifestFile, JSON.stringify(manifestData)) .then(() => manifestFile); } diff --git a/tests/unit/test-util/test.temp-dir.js b/tests/unit/test-util/test.temp-dir.js index 8f553e1cb4..4ddbd550de 100644 --- a/tests/unit/test-util/test.temp-dir.js +++ b/tests/unit/test-util/test.temp-dir.js @@ -54,7 +54,7 @@ describe('util.withTempDir', () => { describe('util.TempDir', () => { it('requires you to create the directory before accessing path()', () => { - let tmp = new TempDir(); + const tmp = new TempDir(); assert.throws(() => tmp.path(), /cannot access path.* before.* create/); }); diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index 2f08d89842..a728944caf 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -17,8 +17,8 @@ import {ConsoleStream} from '../../src/util/logger'; describe('program.Program', () => { function execProgram(program, options = {}) { - let fakeProcess = fake(process); - let absolutePackageDir = path.join(__dirname, '..', '..'); + const fakeProcess = fake(process); + const absolutePackageDir = path.join(__dirname, '..', '..'); return program.execute( absolutePackageDir, { systemProcess: fakeProcess, @@ -28,8 +28,8 @@ describe('program.Program', () => { } it('executes a command callback', () => { - let thing = spy(() => Promise.resolve()); - let program = new Program(['thing']) + const thing = spy(() => Promise.resolve()); + const program = new Program(['thing']) .command('thing', 'does a thing', thing); return execProgram(program) .then(() => { @@ -38,7 +38,7 @@ describe('program.Program', () => { }); it('reports unknown commands', () => { - let program = new Program(['thing']); + const program = new Program(['thing']); return execProgram(program) .then(makeSureItFails()) .catch(onlyInstancesOf(UsageError, (error) => { @@ -47,7 +47,7 @@ describe('program.Program', () => { }); it('reports missing command', () => { - let program = new Program([]); + const program = new Program([]); return execProgram(program) .then(makeSureItFails()) .catch(onlyInstancesOf(UsageError, (error) => { @@ -56,8 +56,8 @@ describe('program.Program', () => { }); it('exits 1 on a thrown error', () => { - let fakeProcess = fake(process); - let program = new Program(['cmd']) + const fakeProcess = fake(process); + const program = new Program(['cmd']) .command('cmd', 'some command', () => { throw new Error('this is an error from a command handler'); }); @@ -91,9 +91,9 @@ describe('program.Program', () => { } } - let program = new Program(['cmd']) + const program = new Program(['cmd']) .command('cmd', 'some command', () => { - let error = new ErrorWithCode(); + const error = new ErrorWithCode(); throw error; }); // This is just a smoke test to make sure the error code doesn't @@ -106,8 +106,8 @@ describe('program.Program', () => { }); it('lets commands define options', () => { - let handler = spy(() => Promise.resolve()); - let program = new Program(['cmd']) + const handler = spy(() => Promise.resolve()); + const program = new Program(['cmd']) .command('cmd', 'some command', handler, { 'some-option': { default: 'default value', @@ -123,8 +123,8 @@ describe('program.Program', () => { }); it('preserves global option configuration', () => { - let handler = spy(() => Promise.resolve()); - let program = new Program(['cmd']) + const handler = spy(() => Promise.resolve()); + const program = new Program(['cmd']) .setGlobalOptions({ 'global-option': { type: 'string', @@ -168,7 +168,7 @@ describe('program.Program', () => { it('configures the logger when verbose', () => { const logStream = fake(new ConsoleStream()); - let program = new Program(['--verbose', 'thing']); + const program = new Program(['--verbose', 'thing']); program.setGlobalOptions({ verbose: { type: 'boolean', @@ -183,8 +183,8 @@ describe('program.Program', () => { }); it('checks the version when verbose', () => { - let version = spy(); - let program = new Program(['--verbose', 'thing']); + const version = spy(); + const program = new Program(['--verbose', 'thing']); program.setGlobalOptions({ verbose: { type: 'boolean', @@ -200,7 +200,7 @@ describe('program.Program', () => { it('does not configure the logger unless verbose', () => { const logStream = fake(new ConsoleStream()); - let program = new Program(['thing']).command('thing', '', () => {}); + const program = new Program(['thing']).command('thing', '', () => {}); program.setGlobalOptions({ verbose: { type: 'boolean', @@ -252,7 +252,7 @@ describe('program.main', () => { } it('executes a command handler', () => { - let fakeCommands = fake(commands, { + const fakeCommands = fake(commands, { build: () => Promise.resolve(), }); return execProgram(['build'], {commands: fakeCommands}) @@ -345,10 +345,10 @@ describe('program.main', () => { describe('program.defaultVersionGetter', () => { - let root = path.join(__dirname, '..', '..'); + const root = path.join(__dirname, '..', '..'); it('returns the package version in production', () => { - let pkgFile = path.join(root, 'package.json'); + const pkgFile = path.join(root, 'package.json'); return fs.readFile(pkgFile) .then((pkgData) => { const testBuildEnv = {localEnv: 'production'};