diff --git a/.eslintrc b/.eslintrc index 5f4b8d3804ad..ce4603af8ba6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,8 @@ "array-bracket-spacing": [2, "never"], "arrow-spacing": [2], "babel/arrow-parens": [2, "as-needed"], + "babel/flow-object-type": [2, "comma"], + "babel/func-params-comma-dangle": [2, "always-multiline"], "brace-style": [2, "1tbs", {"allowSingleLine": true}], "comma-dangle": [2, "always-multiline"], "comma-spacing": [2], diff --git a/examples/.eslintrc b/examples/.eslintrc new file mode 100644 index 000000000000..70b458fe5e7a --- /dev/null +++ b/examples/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "babel/func-params-comma-dangle": 0 + } +} diff --git a/integration_tests/.eslintrc b/integration_tests/.eslintrc new file mode 100644 index 000000000000..70b458fe5e7a --- /dev/null +++ b/integration_tests/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "babel/func-params-comma-dangle": 0 + } +} diff --git a/lerna.json b/lerna.json index e8e7c665d475..d85c4eeae154 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "lerna": "2.0.0-beta.20", - "version": "12.1.2", + "version": "12.1.3", "linkedFiles": { "prefix": "/**\n * @flow\n */\n" } diff --git a/package.json b/package.json index d438f3917f1c..89aea2844f60 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "babel-plugin-transform-flow-strip-types": "^6.8.0", "chalk": "^1.1.3", "eslint": "^2.13.1", - "eslint-plugin-babel": "^3.2.0", + "eslint-plugin-babel": "^3.3.0", "fbjs-scripts": "^0.7.1", "flow-bin": "^0.27.0", "glob": "^7.0.4", diff --git a/packages/babel-plugin-jest-hoist/src/index.js b/packages/babel-plugin-jest-hoist/src/index.js index ba817947cace..f7e1c54809a7 100644 --- a/packages/babel-plugin-jest-hoist/src/index.js +++ b/packages/babel-plugin-jest-hoist/src/index.js @@ -81,7 +81,7 @@ FUNCTIONS.mock = args => { const moduleFactory = args[1]; invariant( moduleFactory.isFunction(), - 'The second argument of `jest.mock` must be a function.' + 'The second argument of `jest.mock` must be a function.', ); const ids = new Set(); @@ -108,7 +108,7 @@ FUNCTIONS.mock = args => { 'reference any outside variables.\n' + 'Invalid variable access: ' + name + '\n' + 'Whitelisted objects: ' + - Object.keys(WHITELISTED_IDENTIFIERS).join(', ') + '.' + Object.keys(WHITELISTED_IDENTIFIERS).join(', ') + '.', ); } } diff --git a/packages/jest-changed-files/src/__tests__/hg-test.js b/packages/jest-changed-files/src/__tests__/hg-test.js index 6b4f8b348368..def474e29171 100644 --- a/packages/jest-changed-files/src/__tests__/hg-test.js +++ b/packages/jest-changed-files/src/__tests__/hg-test.js @@ -35,7 +35,7 @@ describe('hgChecker', () => { it('returns null for non hg repo folder', () => hg.isHGRepository(tmpdir).then(res => { expect(res).toBeNull(); - }) + }), ); it('returns dirname for hg repo folder', () => { @@ -56,7 +56,7 @@ describe('hgChecker', () => { it('returns an empty array for hg repo folder without modified files', () => hg.findChangedFiles(tmpdir).then(res => { expect(res).toEqual([]); - }) + }), ); it('returns an array of modified files for hg repo folder', () => { diff --git a/packages/jest-changed-files/src/git.js b/packages/jest-changed-files/src/git.js index 77d40392b333..8f0c43c319a9 100644 --- a/packages/jest-changed-files/src/git.js +++ b/packages/jest-changed-files/src/git.js @@ -32,7 +32,7 @@ function findChangedFiles(cwd: string): Promise> { resolve([]); } else { resolve(stdout.split('\n').map( - changedPath => path.resolve(cwd, changedPath) + changedPath => path.resolve(cwd, changedPath), )); } } else { diff --git a/packages/jest-changed-files/src/hg.js b/packages/jest-changed-files/src/hg.js index 6f2a996c715d..44571ede79f2 100644 --- a/packages/jest-changed-files/src/hg.js +++ b/packages/jest-changed-files/src/hg.js @@ -42,7 +42,7 @@ function findChangedFiles(cwd: string, options: Options): Promise> { resolve([]); } else { resolve(stdout.split('\n').map( - changedPath => path.resolve(cwd, changedPath) + changedPath => path.resolve(cwd, changedPath), )); } } else { diff --git a/packages/jest-cli/src/CoverageCollector.js b/packages/jest-cli/src/CoverageCollector.js index 92a23df4fffc..ceabb3ada254 100644 --- a/packages/jest-cli/src/CoverageCollector.js +++ b/packages/jest-cli/src/CoverageCollector.js @@ -18,7 +18,7 @@ let _memoizedCoverageTemplate = null; function _getCoverageTemplate() { if (_memoizedCoverageTemplate === null) { _memoizedCoverageTemplate = require('lodash.template')( - fs.readFileSync(COVERAGE_TEMPLATE_PATH, 'utf8') + fs.readFileSync(COVERAGE_TEMPLATE_PATH, 'utf8'), ); } return _memoizedCoverageTemplate; @@ -67,7 +67,7 @@ class CoverageCollector { for (nodeIndex in instrumentationInfo.nodes) { if (!this._coverageDataStore.nodes.hasOwnProperty(nodeIndex)) { coverageInfo.uncoveredSpans.push( - instrumentationInfo.nodes[nodeIndex].loc + instrumentationInfo.nodes[nodeIndex].loc, ); } } diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index bc0301e9f041..4e3e7cb8c0e5 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -125,12 +125,12 @@ class SearchSource { } _getAllTestPaths( - testPathPattern: StrOrRegExpPattern + testPathPattern: StrOrRegExpPattern, ): Promise { return this._hasteMap.then(data => ( this._filterTestPathsWithStats( Object.keys(data.moduleMap.files), - testPathPattern + testPathPattern, ) )); } @@ -142,13 +142,13 @@ class SearchSource { } findMatchingTests( - testPathPattern: StrOrRegExpPattern + testPathPattern: StrOrRegExpPattern, ): Promise { if (testPathPattern && !(testPathPattern instanceof RegExp)) { const maybeFile = path.resolve(process.cwd(), testPathPattern); if (Resolver.fileExists(maybeFile)) { return Promise.resolve( - this._filterTestPathsWithStats([maybeFile]) + this._filterTestPathsWithStats([maybeFile]), ); } } @@ -164,7 +164,7 @@ class SearchSource { this.isTestFilePath.bind(this), { skipNodeResolution: this._options.skipNodeResolution, - } + }, ), })); } @@ -176,7 +176,7 @@ class SearchSource { throw new Error( 'It appears that one of your testPathDirs does not exist ' + 'within a git or hg repository. Currently `--onlyChanged` ' + - 'only works with git or hg projects.' + 'only works with git or hg projects.', ); } return Promise.all(Array.from(repos).map(repo => { @@ -186,7 +186,7 @@ class SearchSource { })); }) .then(changedPathSets => this.findRelatedTests( - new Set(Array.prototype.concat.apply([], changedPathSets)) + new Set(Array.prototype.concat.apply([], changedPathSets)), )); } diff --git a/packages/jest-cli/src/Test.js b/packages/jest-cli/src/Test.js index 35a1c245321e..34bb667b8911 100644 --- a/packages/jest-cli/src/Test.js +++ b/packages/jest-cli/src/Test.js @@ -42,7 +42,7 @@ class Test { const TestConsole = config.silent ? NullConsole : Console; env.global.console = new TestConsole( config.useStderr ? process.stderr : process.stdout, - process.stderr + process.stderr, ); env.testFilePath = path; const moduleLoader = new ModuleLoader(config, env, resolver); @@ -74,7 +74,7 @@ class Test { err => Promise.resolve().then(() => { env.dispose(); throw err; - }) + }), ); } diff --git a/packages/jest-cli/src/TestRunner.js b/packages/jest-cli/src/TestRunner.js index 17f0030b0420..938c4dc90b1c 100644 --- a/packages/jest-cli/src/TestRunner.js +++ b/packages/jest-cli/src/TestRunner.js @@ -59,7 +59,7 @@ class TestRunner { constructor( hasteMap: Promise, config: Config, - options: Options + options: Options, ) { this._hasteMap = hasteMap; this._config = config; @@ -86,7 +86,7 @@ class TestRunner { // fastest results. try { this._testPerformanceCache = JSON.parse(fs.readFileSync( - this._getTestPerformanceCachePath() + this._getTestPerformanceCachePath(), )); } catch (e) {} @@ -128,7 +128,7 @@ class TestRunner { if (config.useStderr) { maybeReporter = new TestReporter(Object.create( process, - {stdout: {value: process.stderr}} + {stdout: {value: process.stderr}}, )); } else { maybeReporter = new TestReporter(); @@ -179,7 +179,7 @@ class TestRunner { reporter.onTestResult && reporter.onTestResult( config, testResult, - aggregatedResults + aggregatedResults, ); }; @@ -247,7 +247,7 @@ class TestRunner { _createInBandTestRun( testPaths: Array, onTestResult: OnTestResult, - onRunFailure: OnRunFailure + onRunFailure: OnRunFailure, ) { return testPaths.reduce((promise, path) => promise @@ -255,7 +255,7 @@ class TestRunner { .then(data => new Test(path, this._config, data.resolver).run()) .then(result => onTestResult(path, result)) .catch(err => onRunFailure(path, err)), - Promise.resolve() + Promise.resolve(), ); } @@ -282,11 +282,11 @@ class TestRunner { if (err.type === 'ProcessTerminatedError') { console.error( 'A worker process has quit unexpectedly! ' + - 'Most likely this an initialization error.' + 'Most likely this an initialization error.', ); process.exit(1); } - })) + })), ) .then(() => workerFarm.end(farm)); }); diff --git a/packages/jest-cli/src/TestWorker.js b/packages/jest-cli/src/TestWorker.js index 9b68a16c9faf..1309d17396a0 100644 --- a/packages/jest-cli/src/TestWorker.js +++ b/packages/jest-cli/src/TestWorker.js @@ -54,7 +54,7 @@ module.exports = (data: WorkerData, callback: WorkerCallback) => { if (!resolvers[name]) { resolvers[name] = createResolver( data.config, - createHasteMap(data.config).read() + createHasteMap(data.config).read(), ); } @@ -62,7 +62,7 @@ module.exports = (data: WorkerData, callback: WorkerCallback) => { .run() .then( result => callback(null, result), - error => callback(formatError(error)) + error => callback(formatError(error)), ); } catch (error) { callback(formatError(error)); diff --git a/packages/jest-cli/src/__tests__/SearchSource-test.js b/packages/jest-cli/src/__tests__/SearchSource-test.js index 9f642beb2219..77f34e9e340a 100644 --- a/packages/jest-cli/src/__tests__/SearchSource-test.js +++ b/packages/jest-cli/src/__tests__/SearchSource-test.js @@ -252,7 +252,7 @@ describe('SearchSource', () => { 'jest-runtime', 'src', '__tests__', - 'test_root' + 'test_root', ); const rootPath = path.join(rootDir, 'root.js'); diff --git a/packages/jest-cli/src/__tests__/customMatchers-test.js b/packages/jest-cli/src/__tests__/customMatchers-test.js index f342d380fac1..640a2f7aa140 100644 --- a/packages/jest-cli/src/__tests__/customMatchers-test.js +++ b/packages/jest-cli/src/__tests__/customMatchers-test.js @@ -95,7 +95,7 @@ describe('jasmine', () => { (passed, result) => { expect(passed).toBe(true); expect(result.message).toBe(''); - } + }, ); expectation.toTestJasmine(); expect(actual).toBe(false); @@ -122,7 +122,7 @@ describe('jasmine', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(SHOULD_BE_CALLED); - } + }, ); expectation.toTestJasmine(); expect(actual).toBe(true); @@ -142,7 +142,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(CALLED_AT_LEAST_ONCE); - } + }, ); expectation.toBeCalled(); }); @@ -152,7 +152,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(SHOULD_NOT_BE_CALLED); - } + }, ); expectation.function(); expectation.not.toBeCalled(); @@ -163,7 +163,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(true); expect(result.message).toBe(''); - } + }, ); expectation.function(); expectation.toBeCalled(); @@ -178,7 +178,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(true); expect(result.message).toBe(''); - } + }, ); expectation.function(1, {}, ''); expectation.lastCalledWith(1, {}, ''); @@ -189,7 +189,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(SHOULD_NOT_HAVE_LAST_CALLED_WITH); - } + }, ); expectation.function(1, {}, ''); expectation.not.lastCalledWith(1, {}, ''); @@ -200,7 +200,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(NOT_EXPECTED_VALUES_LAST_TIME); - } + }, ); expectation.function(1, {}, ''); @@ -216,7 +216,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(true); expect(result.message).toBe(''); - } + }, ); expectation.function(1, {}, ''); expectation.toBeCalledWith(1, {}, ''); @@ -227,7 +227,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(SHOULD_NOT_HAVE_CALLED_WITH); - } + }, ); expectation.function(1, {}, ''); expectation.not.toBeCalledWith(1, {}, ''); @@ -238,7 +238,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(NOT_EXPECTED_VALUES); - } + }, ); expectation.function(1, {}, ''); @@ -250,7 +250,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(NOT_EXPECTED_VALUES_EXACTLY_FOUR); - } + }, ); expectation.function(1); @@ -265,7 +265,7 @@ describe('Jest custom matchers in Jasmine 2', () => { (passed, result) => { expect(passed).toBe(false); expect(result.message).toBe(NOT_EXPECTED_VALUES_MORE_THAN_FOUR); - } + }, ); expectation.function(1); diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.js index 800ab28acf12..49c007111aa8 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.js @@ -16,7 +16,7 @@ const check = (argv: Object) => { if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) { throw new Error( 'Both --runInBand and --maxWorkers were specified, but these two ' + - 'options do not make sense together. Which is it?' + 'options do not make sense together. Which is it?', ); } @@ -24,13 +24,13 @@ const check = (argv: Object) => { throw new Error( 'Both --onlyChanged and a path pattern were specified, but these ' + 'two options do not make sense together. Which is it? Do you want ' + - 'to run tests for changed files? Or for a specific set of files?' + 'to run tests for changed files? Or for a specific set of files?', ); } if (argv.watchExtensions && argv.watch === undefined) { throw new Error( - '--watchExtensions can only be specified together with --watch.' + '--watchExtensions can only be specified together with --watch.', ); } @@ -49,14 +49,14 @@ const options = { description: wrap( 'The path to a jest config file specifying how to find and execute ' + 'tests. If no rootDir is set in the config, the current directory ' + - 'is assumed to be the rootDir for the project.' + 'is assumed to be the rootDir for the project.', ), type: 'string', }, coverage: { description: wrap( 'Indicates that test coverage information should be collected and ' + - 'reported in the output.' + 'reported in the output.', ), type: 'boolean', }, @@ -66,7 +66,7 @@ const options = { 'Specifies the maximum number of workers the worker-pool will ' + 'spawn for running tests. This defaults to the number of the cores ' + 'available on your machine. (its usually best not to override this ' + - 'default)' + 'default)', ), type: 'string', // no, yargs -- its a number.. :( }, @@ -75,7 +75,7 @@ const options = { description: wrap( 'Attempts to identify which tests to run based on which files have ' + 'changed in the current repository. Only works if you\'re running ' + - 'tests in a git repository at the moment.' + 'tests in a git repository at the moment.', ), type: 'boolean', }, @@ -85,21 +85,21 @@ const options = { 'Run all tests serially in the current process (rather than ' + 'creating a worker pool of child processes that run tests). This ' + 'is sometimes useful for debugging, but such use cases are pretty ' + - 'rare.' + 'rare.', ), type: 'boolean', }, testEnvData: { description: wrap( 'A JSON object (string) that specifies data that will be made ' + - 'available in the test environment (via jest.getTestEnvData())' + 'available in the test environment (via jest.getTestEnvData())', ), type: 'string', }, testPathPattern: { description: wrap( 'A regexp pattern string that is matched against all tests ' + - 'paths before executing the test.' + 'paths before executing the test.', ), type: 'string', }, @@ -110,31 +110,31 @@ const options = { }, noHighlight: { description: wrap( - 'Disables test results output highlighting' + 'Disables test results output highlighting', ), type: 'boolean', }, colors: { description: wrap( - 'Forces test results output highlighting (even if stdout is not a TTY)' + 'Forces test results output highlighting (even if stdout is not a TTY)', ), type: 'boolean', }, noStackTrace: { description: wrap( - 'Disables stack trace in test results output' + 'Disables stack trace in test results output', ), type: 'boolean', }, verbose: { description: wrap( - 'Display individual test results with the test suite hierarchy.' + 'Display individual test results with the test suite hierarchy.', ), type: 'boolean', }, notify: { description: wrap( - 'Activates notifications for test results.' + 'Activates notifications for test results.', ), type: 'boolean', }, @@ -142,20 +142,20 @@ const options = { description: wrap( 'Watch files for changes and rerun tests related to changed files. ' + 'If you want to re-run all tests when a file has changed, you can ' + - 'call Jest using `--watch=all`.' + 'call Jest using `--watch=all`.', ), type: 'string', }, bail: { alias: 'b', description: wrap( - 'Exit the test suite immediately upon the first failing test.' + 'Exit the test suite immediately upon the first failing test.', ), type: 'boolean', }, useStderr: { description: wrap( - 'Divert all output to stderr.' + 'Divert all output to stderr.', ), type: 'boolean', }, @@ -163,21 +163,21 @@ const options = { default: true, description: wrap( 'Whether to use the preprocessor cache. Disable the cache using ' + - '--no-cache.' + '--no-cache.', ), type: 'boolean', }, json: { description: wrap( 'Prints the test results in JSON. This mode will send all ' + - 'other test output and user messages to stderr.' + 'other test output and user messages to stderr.', ), type: 'boolean', }, setupTestFrameworkScriptFile: { description: wrap( 'The path to a module that runs some code to configure or set up ' + - 'the testing framework before each test.' + 'the testing framework before each test.', ), type: 'string', }, @@ -187,14 +187,14 @@ const options = { '1 and 2 which can be enabled by setting this option to ' + '`jasmine1` or `jasmine2`. The default is `jasmine2`. A path to a ' + 'custom test runner can be provided: ' + - '`/path/to/testRunner.js`.' + '`/path/to/testRunner.js`.', ), type: 'string', }, logHeapUsage: { description: wrap( 'Logs the heap usage after every test. Useful to debug memory ' + - 'leaks. Use together with `--runInBand` and `--expose-gc` in node.' + 'leaks. Use together with `--runInBand` and `--expose-gc` in node.', ), type: 'boolean', }, @@ -202,14 +202,14 @@ const options = { default: true, description: wrap( 'Whether to use watchman for file crawling. Disable using ' + - '--no-watchman.' + '--no-watchman.', ), type: 'boolean', }, silent: { default: false, description: wrap( - 'Prevent tests from printing messages through the console.' + 'Prevent tests from printing messages through the console.', ), type: 'boolean', }, @@ -217,7 +217,7 @@ const options = { alias: 'u', default: false, description: wrap( - 'Use this flag to re-record snapshots.' + 'Use this flag to re-record snapshots.', ), type: 'boolean', }, @@ -226,7 +226,7 @@ const options = { description: wrap( 'The number of test cases to generate for each testcheck test. ' + 'May be overriden for individual test cases using the options ' + - 'argument of check.it.' + 'argument of check.it.', ), type: 'number', }, @@ -237,7 +237,7 @@ const options = { 'generated for testcheck tests. ' + 'May be overriden for individual test cases using the options ' + 'argument of check.it. ' + - 'Generators can also be sized using gen.resize(n, anotherGenerator).' + 'Generators can also be sized using gen.resize(n, anotherGenerator).', ), type: 'number', }, @@ -246,7 +246,7 @@ const options = { description: wrap( 'The seed for generating testcheck test cases. Defaults to random. ' + 'May be overriden for individual test cases using the options ' + - 'argument of check.it.' + 'argument of check.it.', ), type: 'number', }, diff --git a/packages/jest-cli/src/cli/getJest.js b/packages/jest-cli/src/cli/getJest.js index 9573d618a286..617479caeac4 100644 --- a/packages/jest-cli/src/cli/getJest.js +++ b/packages/jest-cli/src/cli/getJest.js @@ -35,7 +35,7 @@ function getJest(packageRoot: Path) { ) { console.error( 'Please run `npm install` to use the version of Jest intended for ' + - 'this project.' + 'this project.', ); process.on('exit', () => process.exit(1)); } diff --git a/packages/jest-cli/src/jest.js b/packages/jest-cli/src/jest.js index f83199b1760a..2af9b660d65c 100644 --- a/packages/jest-cli/src/jest.js +++ b/packages/jest-cli/src/jest.js @@ -91,13 +91,13 @@ function runJest(config, argv, pipe, onComplete) { .then(data => { if (!data.paths.length) { pipe.write( - source.getNoTestsFoundMessage(patternInfo, config, data) + '\n' + source.getNoTestsFoundMessage(patternInfo, config, data) + '\n', ); } return data.paths; }) .then(testPaths => - new TestRunner(hasteMap, config, {maxWorkers}).runTests(testPaths) + new TestRunner(hasteMap, config, {maxWorkers}).runTests(testPaths), ) .then(runResults => { if (config.testResultsProcessor) { @@ -107,7 +107,7 @@ function runJest(config, argv, pipe, onComplete) { } if (argv.json) { process.stdout.write( - JSON.stringify(formatTestResults(runResults, config)) + JSON.stringify(formatTestResults(runResults, config)), ); } return runResults; @@ -181,10 +181,10 @@ function runCLI(argv: Object, root: Path, onComplete: () => void) { runJest(config, argv, pipe, () => isRunning = false) .then( resolve, - error => console.error(chalk.red(error)) + error => console.error(chalk.red(error)), ); }, - WATCHER_DEBOUNCE + WATCHER_DEBOUNCE, ); } }); diff --git a/packages/jest-cli/src/lib/formatTestResults.js b/packages/jest-cli/src/lib/formatTestResults.js index 3b3b6492aac9..bf37f2dc6dab 100644 --- a/packages/jest-cli/src/lib/formatTestResults.js +++ b/packages/jest-cli/src/lib/formatTestResults.js @@ -70,7 +70,7 @@ function formatTestResults( testResult, config, formatter, - reporter + reporter, )); return { diff --git a/packages/jest-config/src/__tests__/normalize-test.js b/packages/jest-config/src/__tests__/normalize-test.js index 867a96187130..62fa07867f1b 100644 --- a/packages/jest-config/src/__tests__/normalize-test.js +++ b/packages/jest-config/src/__tests__/normalize-test.js @@ -28,7 +28,7 @@ describe('normalize', () => { function joinForPattern() { return Array.prototype.join.call( arguments, - utils.escapeStrForRegex(path.sep) + utils.escapeStrForRegex(path.sep), ); } @@ -60,7 +60,7 @@ describe('normalize', () => { expect(console.error).toBeCalledWith( 'Error: Unknown config option "thisIsAnInvalidConfigKey" with value ' + '"with a value even!". This is either a typing error or another user ' + - 'mistake and fixing it will remove this message.' + 'mistake and fixing it will remove this message.', ); console.error = error; @@ -412,7 +412,7 @@ describe('normalize', () => { }, { testRunner: 'jasmine1', - } + }, ); expect(config.testRunner).toMatch('jasmine1'); @@ -448,7 +448,7 @@ describe('normalize', () => { })).toThrow(new Error( `Jest: test environment "phantom" cannot be found. Make sure the ` + `"testEnvironment" configuration option points to an existing node ` + - `module.` + `module.`, )); }); }); diff --git a/packages/jest-config/src/loadFromPackage.js b/packages/jest-config/src/loadFromPackage.js index 8a5b36e12b6b..79315298611b 100644 --- a/packages/jest-config/src/loadFromPackage.js +++ b/packages/jest-config/src/loadFromPackage.js @@ -23,7 +23,7 @@ function loadFromPackage(filePath, argv) { config.rootDir ? path.resolve(root, config.rootDir) : root; return normalize(config, argv); }, - () => null + () => null, ); } diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index b8541b3078b3..d93f945ad005 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -44,7 +44,7 @@ function _replaceRootDirTags(rootDir, config) { return path.resolve( rootDir, - path.normalize('./' + config.substr(''.length)) + path.normalize('./' + config.substr(''.length)), ); } return config; @@ -74,7 +74,7 @@ function getTestEnvironment(config) { throw new Error( `Jest: test environment "${env}" cannot be found. Make sure the ` + - `"testEnvironment" configuration option points to an existing node module.` + `"testEnvironment" configuration option points to an existing node module.`, ); } @@ -115,7 +115,7 @@ function normalize(config, argv) { } const extensions = Array.from( new Set((config.testFileExtensions || []) - .concat(config.moduleFileExtensions) + .concat(config.moduleFileExtensions), )); config.moduleFileExtensions = extensions; @@ -138,11 +138,11 @@ function normalize(config, argv) { } else { try { config.testRunner = path.resolve( - config.testRunner.replace(//g, config.rootDir) + config.testRunner.replace(//g, config.rootDir), ); } catch (e) { throw new Error( - `Jest: Invalid testRunner path: ${config.testRunner}` + `Jest: Invalid testRunner path: ${config.testRunner}`, ); } } @@ -156,7 +156,7 @@ function normalize(config, argv) { config.scriptPreprocessor = _replaceRootDirTags(config.rootDir, config.scriptPreprocessor); if (config.scriptPreprocessor.includes( - constants.NODE_MODULES + 'babel-jest' + constants.NODE_MODULES + 'babel-jest', )) { babelJest = config.scriptPreprocessor; } @@ -198,7 +198,7 @@ function normalize(config, argv) { value = Object.keys(config[key]).reduce((normObj, filePath) => { filePath = path.resolve( config.rootDir, - _replaceRootDirTags(config.rootDir, filePath) + _replaceRootDirTags(config.rootDir, filePath), ); normObj[filePath] = true; return normObj; @@ -209,7 +209,7 @@ function normalize(config, argv) { case 'testPathDirs': value = config[key].map(filePath => path.resolve( config.rootDir, - _replaceRootDirTags(config.rootDir, filePath) + _replaceRootDirTags(config.rootDir, filePath), )); break; @@ -221,7 +221,7 @@ function normalize(config, argv) { case 'testRunner': value = path.resolve( config.rootDir, - _replaceRootDirTags(config.rootDir, config[key]) + _replaceRootDirTags(config.rootDir, config[key]), ); break; @@ -244,8 +244,8 @@ function normalize(config, argv) { // special case substitutions for patterns here. value = config[key].map(pattern => utils.replacePathSepForRegex( - pattern.replace(//g, config.rootDir) - ) + pattern.replace(//g, config.rootDir), + ), ); break; case 'automock': @@ -288,7 +288,7 @@ function normalize(config, argv) { console.error( `Error: Unknown config option "${key}" with value ` + `"${config[key]}". This is either a typing error or another user ` + - `mistake and fixing it will remove this message.` + `mistake and fixing it will remove this message.`, ); } newConfig[key] = value; diff --git a/packages/jest-config/src/reporters/DefaultTestReporter.js b/packages/jest-config/src/reporters/DefaultTestReporter.js index 382f2845a870..db086ff903b2 100644 --- a/packages/jest-config/src/reporters/DefaultTestReporter.js +++ b/packages/jest-config/src/reporters/DefaultTestReporter.js @@ -95,7 +95,7 @@ class DefaultTestReporter { const testDetail = []; if (runTime !== null) { testDetail.push( - runTime > 5 ? LONG_TEST_COLOR(runTime + 's') : runTime + 's' + runTime > 5 ? LONG_TEST_COLOR(runTime + 's') : runTime + 's', ); } @@ -111,7 +111,7 @@ class DefaultTestReporter { this.log(resultHeader); if (config.verbose && !testResult.testExecError) { this.verboseLogger.logTestResults( - testResult.testResults + testResult.testResults, ); } @@ -251,7 +251,7 @@ class DefaultTestReporter { this.log( '\u203A ' + SNAPSHOT_ADDED(pluralize('snapshot', snapshots.added)) + - ` written in ${pluralize('test file', snapshots.filesAdded)}.` + ` written in ${pluralize('test file', snapshots.filesAdded)}.`, ); } @@ -260,7 +260,7 @@ class DefaultTestReporter { '\u203A ' + FAIL_COLOR(pluralize('snapshot test', snapshots.unmatched)) + ` failed in ${pluralize('test file', snapshots.filesUnmatched)}. ` + - 'Inspect your code changes or re-run with `-u` to update them.' + 'Inspect your code changes or re-run with `-u` to update them.', ); } @@ -268,7 +268,7 @@ class DefaultTestReporter { this.log( '\u203A ' + SNAPSHOT_UPDATED(pluralize('snapshot', snapshots.updated)) + - ` updated in ${pluralize('test file', snapshots.filesUpdated)}.` + ` updated in ${pluralize('test file', snapshots.filesUpdated)}.`, ); } @@ -277,11 +277,11 @@ class DefaultTestReporter { '\u203A ' + SNAPSHOT_REMOVED(pluralize( 'snapshot file', - snapshots.filesRemoved + snapshots.filesRemoved, )) + (snapshots.didUpdate ? ' removed.' - : ' found, re-run with `-u` to remove them.') + : ' found, re-run with `-u` to remove them.'), ); } @@ -291,7 +291,7 @@ class DefaultTestReporter { FAIL_COLOR(pluralize('obsolete snapshot', snapshots.unchecked)) + (snapshots.didUpdate ? ' removed.' - : ' found, re-run with `-u` to remove them.') + : ' found, re-run with `-u` to remove them.'), ); } @@ -346,7 +346,7 @@ class DefaultTestReporter { results.numRuntimeErrorTestSuites; if (!this._config.noHighlight && remaining > 0) { this._process.stdout.write(RUNNING_TEST_COLOR( - `Running ${pluralize('test suite', remaining)}...` + `Running ${pluralize('test suite', remaining)}...`, )); } } diff --git a/packages/jest-config/src/reporters/IstanbulTestReporter.js b/packages/jest-config/src/reporters/IstanbulTestReporter.js index 952c2f718660..0143a2d741a5 100644 --- a/packages/jest-config/src/reporters/IstanbulTestReporter.js +++ b/packages/jest-config/src/reporters/IstanbulTestReporter.js @@ -69,13 +69,13 @@ class IstanbulTestReporter extends DefaultTestReporter { if (threshold * -1 < actualUncovered) { errors.push( `Jest: Uncovered count for ${key} (${actualUncovered})` + - `exceeds ${name} threshold (${-1 * threshold})` + `exceeds ${name} threshold (${-1 * threshold})`, ); } } else if (actual < threshold) { errors.push( `Jest: Coverage for ${key} (${actual}` + - `%) does not meet ${name} threshold (${threshold}%)` + `%) does not meet ${name} threshold (${threshold}%)`, ); } } @@ -85,7 +85,7 @@ class IstanbulTestReporter extends DefaultTestReporter { const errors = check( 'global', config.coverageThreshold.global, - globalResults + globalResults, ); if (errors.length > 0) { diff --git a/packages/jest-config/src/reporters/VerboseLogger.js b/packages/jest-config/src/reporters/VerboseLogger.js index 76d60fbe189c..f672481928af 100644 --- a/packages/jest-config/src/reporters/VerboseLogger.js +++ b/packages/jest-config/src/reporters/VerboseLogger.js @@ -53,7 +53,7 @@ class VerboseLogger { logTestResults(testResults: Array) { VerboseLogger.groupTestsBySuites(testResults).forEach(suite => - this._logSuite(suite, 0) + this._logSuite(suite, 0), ); this._logLine(); @@ -63,11 +63,11 @@ class VerboseLogger { this._logLine(suite.title, indentLevel); suite.tests.forEach(test => - this._logTest(test, indentLevel + 1) + this._logTest(test, indentLevel + 1), ); suite.suites.forEach(childSuite => - this._logSuite(childSuite, indentLevel + 1) + this._logSuite(childSuite, indentLevel + 1), ); } diff --git a/packages/jest-environment-jsdom/src/__mocks__/index.js b/packages/jest-environment-jsdom/src/__mocks__/index.js index e1189ef9829f..f4843d2f5e15 100644 --- a/packages/jest-environment-jsdom/src/__mocks__/index.js +++ b/packages/jest-environment-jsdom/src/__mocks__/index.js @@ -30,7 +30,7 @@ JSDOMEnvironment.prototype.runSourceText.mockImplementation( filename, displayErrors: false, }); - } + }, ); module.exports = JSDOMEnvironment; diff --git a/packages/jest-haste-map/src/__tests__/index-test.js b/packages/jest-haste-map/src/__tests__/index-test.js index 7c4253d8484e..eba227b2b332 100644 --- a/packages/jest-haste-map/src/__tests__/index-test.js +++ b/packages/jest-haste-map/src/__tests__/index-test.js @@ -25,8 +25,8 @@ jest.mock('child_process', () => ({ jest.mock('worker-farm', () => { const mock = jest.fn( (options, worker) => workerFarmMock = jest.fn( - (data, callback) => require(worker)(data, callback) - ) + (data, callback) => require(worker)(data, callback), + ), ); mock.end = jest.fn(); return mock; @@ -48,7 +48,7 @@ jest.mock('../crawlers/watchman', () => } return Promise.resolve(data); - }) + }), ); const cacheFilePath = '/cache-file'; @@ -172,9 +172,9 @@ describe('HasteMap', () => { .toMatch(/^\/-scoped-package-(.*)$/); expect( - HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value') + HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'), ).not.toEqual( - HasteMap.getCacheFilePath('/', '-scoped-package', 'random-value') + HasteMap.getCacheFilePath('/', '-scoped-package', 'random-value'), ); }); @@ -507,7 +507,7 @@ describe('HasteMap', () => { expect(console.warn).toBeCalledWith( 'jest-haste-map: Watchman crawl failed. Retrying once with node ' + - 'crawler.\n Error: watchman error' + 'crawler.\n Error: watchman error', ); }); }); @@ -555,9 +555,9 @@ describe('HasteMap', () => { expect(error.message).toEqual( 'Crawler retry failed:\n' + ' Original error: watchman error\n' + - ' Retry error: node error\n' + ' Retry error: node error\n', ); - } + }, ); }); diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node-test.js b/packages/jest-haste-map/src/crawlers/__tests__/node-test.js index 0fa2d454dc83..e4c7d226a2e7 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node-test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node-test.js @@ -98,7 +98,7 @@ describe('node crawler', () => { pearMatcher, { files: Object.create(null), - } + }, ).then(data => { expect(childProcess.spawn).lastCalledWith('find', [ '/fruits', diff --git a/packages/jest-haste-map/src/crawlers/__tests__/watchman-test.js b/packages/jest-haste-map/src/crawlers/__tests__/watchman-test.js index a4a14019431e..848879908fca 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/watchman-test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/watchman-test.js @@ -96,7 +96,7 @@ describe('watchman watch', () => { { clocks: Object.create(null), files: Object.create(null), - } + }, ).then(data => { const client = watchman.Client.mock.instances[0]; const calls = client.command.mock.calls; @@ -184,7 +184,7 @@ describe('watchman watch', () => { { clocks, files: mockFiles, - } + }, ).then(data => { // The object was reused. expect(data.files).toBe(mockFiles); @@ -249,7 +249,7 @@ describe('watchman watch', () => { { clocks, files: mockFiles, - } + }, ).then(data => { // The file object was *not* reused. expect(data.files).not.toBe(mockFiles); @@ -315,7 +315,7 @@ describe('watchman watch', () => { { clocks, files: mockFiles, - } + }, ).then(data => { expect(data.clocks).toEqual({ '/fruits': 'c:fake-clock:3', diff --git a/packages/jest-haste-map/src/crawlers/watchman.js b/packages/jest-haste-map/src/crawlers/watchman.js index c38e44934f61..67d7ac6da7ab 100644 --- a/packages/jest-haste-map/src/crawlers/watchman.js +++ b/packages/jest-haste-map/src/crawlers/watchman.js @@ -26,7 +26,7 @@ function isDescendant(root: string, child: string): boolean { function WatchmanError(error: Error): Error { return new Error( `Watchman error: ${error.message.trim()}. Make sure watchman ` + - `is running for this project. See ${watchmanURL}.` + `is running for this project. See ${watchmanURL}.`, ); } @@ -56,7 +56,7 @@ module.exports = function watchmanCrawl( return Promise.all(roots.map(root => cmd(['watch-project', root]))) .then(responses => { const watchmanRoots = Array.from( - new Set(responses.map(response => response.watch)) + new Set(responses.map(response => response.watch)), ); return Promise.all(watchmanRoots.map(root => { // Build up an expression to filter the output by the relevant roots. @@ -70,7 +70,7 @@ module.exports = function watchmanCrawl( 'allof', ['type', 'f'], ['anyof'].concat(extensions.map( - extension => ['suffix', extension] + extension => ['suffix', extension], )), dirExpr, ]; diff --git a/packages/jest-haste-map/src/fastpath.js b/packages/jest-haste-map/src/fastpath.js index de33fa62fdc4..104ffe796c95 100644 --- a/packages/jest-haste-map/src/fastpath.js +++ b/packages/jest-haste-map/src/fastpath.js @@ -232,7 +232,7 @@ if ( // Normalize the tail path resolvedTail = normalizeArray( resolvedTail.split(/[\\\/]+/), - !resolvedAbsolute + !resolvedAbsolute, ).join('\\'); return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) @@ -386,7 +386,7 @@ if ( // Normalize the path resolvedPath = normalizeArray( resolvedPath.split('/'), - !resolvedAbsolute + !resolvedAbsolute, ).join('/'); return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; @@ -471,12 +471,12 @@ if ( exports.exists = (util.deprecate( (path, callback) => fs.exists(path, callback), - 'path.exists is now called `fs.exists`.' + 'path.exists is now called `fs.exists`.', ): (path: string, callback: (exists: boolean) => void) => void); exports.existsSync = (util.deprecate( path => fs.existsSync(path), - 'path.existsSync is now called `fs.existsSync`.' + 'path.existsSync is now called `fs.existsSync`.', ): (path: string) => boolean); if (IS_WINDOWS) { diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 9cab22844731..5357fc55c28e 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -31,30 +31,30 @@ const worker = require('./worker'); const workerFarm = require('worker-farm'); type Options = { - cacheDirectory?: string; - extensions: Array; + cacheDirectory?: string, + extensions: Array, ignorePattern: RegExp, - maxWorkers: number; - mocksPattern?: string; - name: string; - platforms: Array; - providesModuleNodeModules?: Array; - resetCache?: boolean; - roots: Array; - useWatchman?: boolean; + maxWorkers: number, + mocksPattern?: string, + name: string, + platforms: Array, + providesModuleNodeModules?: Array, + resetCache?: boolean, + roots: Array, + useWatchman?: boolean, }; type InternalOptions = { - cacheDirectory: string; - extensions: Array; - ignorePattern: RegExp; - maxWorkers: number; - mocksPattern: ?RegExp; - name: string; - platforms: Array; - resetCache: ?boolean; - roots: Array; - useWatchman: boolean; + cacheDirectory: string, + extensions: Array, + ignorePattern: RegExp, + maxWorkers: number, + mocksPattern: ?RegExp, + name: string, + platforms: Array, + resetCache: ?boolean, + roots: Array, + useWatchman: boolean, }; type HasteMapOptions = { @@ -82,7 +82,7 @@ const getWhiteList = (list: ?Array): ?RegExp => { return new RegExp( '(' + escapePathSeparator(NODE_MODULES) + '(?:' + list.join('|') + ')(?=$|' + escapePathSeparator(path.sep) + '))', - 'g' + 'g', ); } return null; @@ -192,7 +192,7 @@ class HasteMap { this._options.roots.join(':'), this._options.extensions.join(':'), this._options.platforms.join(':'), - options.mocksPattern + options.mocksPattern, ); this._whitelist = getWhiteList(options.providesModuleNodeModules); this._buildPromise = null; @@ -205,7 +205,7 @@ class HasteMap { options?: HasteMapOptions, ): HasteMap { const ignorePattern = new RegExp( - [config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|') + [config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|'), ); return new HasteMap({ @@ -228,7 +228,7 @@ class HasteMap { Array.from(arguments).slice(1).forEach(arg => hash.update(arg)); return path.join( tmpdir, - name.replace(/\W/g, '-') + '-' + hash.digest('hex') + name.replace(/\W/g, '-') + '-' + hash.digest('hex'), ); } @@ -303,7 +303,7 @@ class HasteMap { ` Paths: ${module[H.PATH]} collides with ` + `${existingModule[H.PATH]}\n\n` + `This warning is caused by a @providesModule declaration ` + - `with the same name across two different files.` + `with the same name across two different files.`, ); return; } @@ -344,8 +344,8 @@ class HasteMap { // If a file cannot be read we remove it from the file list and // ignore the failure silently. delete hasteMap.files[filePath]; - } - ) + }, + ), ); } @@ -385,7 +385,7 @@ class HasteMap { { maxConcurrentWorkers: this._options.maxWorkers, }, - require.resolve('./worker') + require.resolve('./worker'), ); workerFn = this._workerFarm; } @@ -397,7 +397,7 @@ class HasteMap { } else { resolve(metadata); } - }) + }), ); } @@ -422,14 +422,14 @@ class HasteMap { if (crawl === watchmanCrawl) { console.warn( `jest-haste-map: Watchman crawl failed. Retrying once with node ` + - `crawler.\n ${error}` + `crawler.\n ${error}`, ); return nodeCrawl(options.roots, options.extensions, ignore, hasteMap) .catch(e => { throw new Error( `Crawler retry failed:\n` + ` Original error: ${error.message}\n` + - ` Retry error: ${e.message}\n` + ` Retry error: ${e.message}\n`, ); }); } diff --git a/packages/jest-haste-map/src/lib/__tests__/docblock-test.js b/packages/jest-haste-map/src/lib/__tests__/docblock-test.js index a18199ab41c7..82bb49585641 100644 --- a/packages/jest-haste-map/src/lib/__tests__/docblock-test.js +++ b/packages/jest-haste-map/src/lib/__tests__/docblock-test.js @@ -28,7 +28,7 @@ describe('docblock', () => { '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/' + os.EOL + 'const x = foo;'; expect(docblock.extract(code)).toBe( - '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/' + '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/', ); }); @@ -37,7 +37,7 @@ describe('docblock', () => { '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/' + os.EOL + 'const x = foo;' + os.EOL + '/**foo*/'; expect(docblock.extract(code)).toBe( - '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/' + '/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/', ); }); diff --git a/packages/jest-jasmine1/src/__tests__/reporter-test.js b/packages/jest-jasmine1/src/__tests__/reporter-test.js index 8ece3a485b8b..08fd16c223fb 100644 --- a/packages/jest-jasmine1/src/__tests__/reporter-test.js +++ b/packages/jest-jasmine1/src/__tests__/reporter-test.js @@ -82,7 +82,7 @@ describe('JasmineReporter', () => { const message = result.testResults[0].failureMessages[0]; expect(message).toBe( errorize('Expected:') + ' \'foo\' ' + - errorize('toBe:') + ' \'foo' + highlight('bar') + '\'' + errorize('toBe:') + ' \'foo' + highlight('bar') + '\'', ); }); }); @@ -95,7 +95,7 @@ describe('JasmineReporter', () => { const message = result.testResults[0].failureMessages[0]; expect(message).toBe( errorize('Expected:') + ' \'foo\n' + highlight('bar\n') + 'baz\' ' + - errorize('toBe:') + ' \'foo\n' + highlight('xxx\n') + 'baz\'' + errorize('toBe:') + ' \'foo\n' + highlight('xxx\n') + 'baz\'', ); }); }); diff --git a/packages/jest-jasmine1/src/index.js b/packages/jest-jasmine1/src/index.js index c55dbb7b91a9..6a1c5e9567bf 100644 --- a/packages/jest-jasmine1/src/index.js +++ b/packages/jest-jasmine1/src/index.js @@ -36,7 +36,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { if (!hasKey(expected, property) && hasKey(actual, property)) { mismatchKeys.push( 'expected missing key \'' + property + '\', but present in ' + - 'actual.' + 'actual.', ); } }; @@ -45,7 +45,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { (actual, expected, property, mismatchKeys) => { if (!hasKey(actual, property) && hasKey(expected, property)) { mismatchKeys.push( - 'expected has key \'' + property + '\', but missing from actual.' + 'expected has key \'' + property + '\', but missing from actual.', ); } }; @@ -55,14 +55,14 @@ function jasmine1(config, environment, moduleLoader, testPath) { b, property, mismatchKeys, - mismatchValues + mismatchValues, ) { // The only different implementation from the original jasmine const areEqual = this.equals_( a[property], b[property], mismatchKeys, - mismatchValues + mismatchValues, ); if (!areEqual) { let aprop; @@ -71,7 +71,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { aprop = a[property]; } else if (a[property].toString) { aprop = environment.global.jasmine.util.htmlEscape( - a[property].toString() + a[property].toString(), ); } else { aprop = Object.prototype.toString.call(a[property]); @@ -81,7 +81,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { bprop = b[property]; } else if (b[property].toString) { bprop = environment.global.jasmine.util.htmlEscape( - b[property].toString() + b[property].toString(), ); } else { bprop = Object.prototype.toString.call(b[property]); @@ -90,7 +90,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { mismatchValues.push( '\'' + property + '\' was \'' + bprop + '\' in expected, but was \'' + aprop + - '\' in actual.' + '\' in actual.', ); } }; @@ -140,7 +140,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { b, index, mismatchKeys, - mismatchValues + mismatchValues, ); } } @@ -156,7 +156,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { b, property, mismatchKeys, - mismatchValues + mismatchValues, ); } for (property in a) { @@ -188,14 +188,14 @@ function jasmine1(config, environment, moduleLoader, testPath) { if (arguments.length > 0) { throw Error( 'toBeCalled() does not accept parameters, ' + - 'use toBeCalledWith instead' + 'use toBeCalledWith instead', ); } const isSpy = isSpyLike(this.actual); if (!isSpy && !isMockLike(this.actual)) { throw Error( 'lastCalledWith() should be used on a mock function or ' + - 'a jasmine spy' + 'a jasmine spy', ); } const calls = isSpy @@ -209,7 +209,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { if (!isSpy && !isMockLike(this.actual)) { throw Error( 'lastCalledWith() should be used on a mock function or ' + - 'a jasmine spy' + 'a jasmine spy', ); } const calls = isSpy @@ -225,7 +225,7 @@ function jasmine1(config, environment, moduleLoader, testPath) { if (!isSpy && !isMockLike(this.actual)) { throw Error( 'toBeCalledWith() should be used on a mock function or ' + - 'a jasmine spy' + 'a jasmine spy', ); } const calls = isSpy diff --git a/packages/jest-jasmine1/src/reporter.js b/packages/jest-jasmine1/src/reporter.js index 212f42b09c9d..ab7969095a43 100644 --- a/packages/jest-jasmine1/src/reporter.js +++ b/packages/jest-jasmine1/src/reporter.js @@ -55,10 +55,10 @@ class JasmineReporter extends jasmine.Reporter { _extractSuiteResults(container, ancestorTitles, suite) { ancestorTitles = ancestorTitles.concat([suite.description]); suite.specs().forEach( - this._extractSpecResults.bind(this, container, ancestorTitles) + this._extractSpecResults.bind(this, container, ancestorTitles), ); suite.suites().forEach( - this._extractSuiteResults.bind(this, container, ancestorTitles) + this._extractSuiteResults.bind(this, container, ancestorTitles), ); } @@ -79,7 +79,7 @@ class JasmineReporter extends jasmine.Reporter { results.failureMessages.push(result.trace.stack); } else { results.failureMessages.push( - this._formatter.formatMatchFailure(result) + this._formatter.formatMatchFailure(result), ); } break; diff --git a/packages/jest-jasmine2/src/__tests__/reporter-test.js b/packages/jest-jasmine2/src/__tests__/reporter-test.js index edfc53b177ad..d81083e5fa3f 100644 --- a/packages/jest-jasmine2/src/__tests__/reporter-test.js +++ b/packages/jest-jasmine2/src/__tests__/reporter-test.js @@ -85,7 +85,7 @@ describe('Jasmine2Reporter', () => { const message = result.testResults[0].failureMessages[0]; expect(message).toBe( errorize('Expected:') + ' \'foo\' ' + - errorize('toBe:') + ' \'foo' + highlight('bar') + '\'' + errorize('toBe:') + ' \'foo' + highlight('bar') + '\'', ); }); }); @@ -99,7 +99,7 @@ describe('Jasmine2Reporter', () => { const message = result.testResults[0].failureMessages[0]; expect(message).toBe( errorize('Expected:') + ' \'foo\n' + highlight('bar\n') + 'baz\' ' + - errorize('toBe:') + ' \'foo\n' + highlight('xxx\n') + 'baz\'' + errorize('toBe:') + ' \'foo\n' + highlight('xxx\n') + 'baz\'', ); }); }); diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index 47dfa0fedbc0..56a6371af460 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -38,7 +38,7 @@ function getActualCalls(reporter, calls, limit) { return ( `\nActual call${calls.length === 1 ? '' : 's'}:\n` + calls.slice(-limit).map( - call => reporter.getFormatter().prettyPrint(call) + call => reporter.getFormatter().prettyPrint(call), ).reverse().join(',\n') + (count > 0 ? `\nand ${count} other call${count === 1 ? '' : 's'}.` : '' @@ -50,7 +50,7 @@ function jasmine2( config: Config, environment: Environment, moduleLoader: ModuleLoader, - testPath: string + testPath: string, ): Promise { let env; let jasmine; @@ -139,7 +139,7 @@ function jasmine2( !jasmine.matchersUtil.equals( aValue, nextB.value, - [iterableEquality] + [iterableEquality], ) ) { return false; @@ -158,8 +158,8 @@ function jasmine2( testPath, config, jasmine, - env.snapshotState - ) + env.snapshotState, + ), ); jasmine.addMatchers({ @@ -168,14 +168,14 @@ function jasmine2( if (expected) { throw Error( 'toBeCalled() does not accept parameters, use ' + - 'toBeCalledWith instead.' + 'toBeCalledWith instead.', ); } const isSpy = isSpyLike(actual); if (!isSpy && !isMockLike(actual)) { throw Error( 'toBeCalled() should be used on a mock function or ' + - 'a jasmine spy.' + 'a jasmine spy.', ); } const calls = isSpy @@ -200,7 +200,7 @@ function jasmine2( if (!isSpy && !isMockLike(actual)) { throw Error( 'lastCalledWith() should be used on a mock function or ' + - 'a jasmine spy.' + 'a jasmine spy.', ); } const calls = isSpy @@ -242,7 +242,7 @@ function jasmine2( if (!isMockLike(actual) && !isSpy) { throw Error( 'toBeCalledWith() should be used on a mock function or ' + - 'a jasmine spy.' + 'a jasmine spy.', ); } const calls = isSpy diff --git a/packages/jest-jasmine2/src/jasmine-pit.js b/packages/jest-jasmine2/src/jasmine-pit.js index 934f6e91d0d0..859784010365 100644 --- a/packages/jest-jasmine2/src/jasmine-pit.js +++ b/packages/jest-jasmine2/src/jasmine-pit.js @@ -45,7 +45,7 @@ function promisifyIt(originalFn, env) { done(); } else { done.fail(new Error( - 'Jest: `it` must return either a Promise or undefined.' + 'Jest: `it` must return either a Promise or undefined.', )); } }, timeout); diff --git a/packages/jest-jasmine2/src/reporter.js b/packages/jest-jasmine2/src/reporter.js index 1ebce8122cbe..2a164825df93 100644 --- a/packages/jest-jasmine2/src/reporter.js +++ b/packages/jest-jasmine2/src/reporter.js @@ -61,7 +61,7 @@ class Jasmine2Reporter { specDone(result: SpecResult): void { this._testResults.push( - this._extractSpecResults(result, this._currentSuites.slice(0)) + this._extractSpecResults(result, this._currentSuites.slice(0)), ); } diff --git a/packages/jest-mock/src/__tests__/jest-mock-test.js b/packages/jest-mock/src/__tests__/jest-mock-test.js index c62e4a60a7bb..c8c308013ddf 100644 --- a/packages/jest-mock/src/__tests__/jest-mock-test.js +++ b/packages/jest-mock/src/__tests__/jest-mock-test.js @@ -37,7 +37,7 @@ describe('moduleMocker', () => { it('forwards the function name property', () => { function foo() {} const fooMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(foo) + moduleMocker.getMetadata(foo), ); expect(fooMock.name).toBe('foo'); }); @@ -46,7 +46,7 @@ describe('moduleMocker', () => { const ClassFoo = function() {}; ClassFoo.prototype.x = () => {}; const ClassFooMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(ClassFoo) + moduleMocker.getMetadata(ClassFoo), ); const foo = new ClassFooMock(); const bar = new ClassFooMock(); @@ -72,7 +72,7 @@ describe('moduleMocker', () => { }, }); const fooMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(foo) + moduleMocker.getMetadata(foo), ); expect(typeof foo.nonEnumMethod).toBe('function'); @@ -90,13 +90,13 @@ describe('moduleMocker', () => { } const ClassFooMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(ClassFoo) + moduleMocker.getMetadata(ClassFoo), ); const foo = new ClassFooMock(); const instanceFoo = new ClassFoo(); const instanceFooMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(instanceFoo) + moduleMocker.getMetadata(instanceFoo), ); expect(typeof foo.foo).toBe('function'); @@ -111,7 +111,7 @@ describe('moduleMocker', () => { const multipleBoundFunc = func.bind(null).bind(null); const multipleBoundFuncMock = moduleMocker.generateFromMetadata( - moduleMocker.getMetadata(multipleBoundFunc) + moduleMocker.getMetadata(multipleBoundFunc), ); expect(typeof multipleBoundFuncMock).toBe('function'); @@ -119,7 +119,7 @@ describe('moduleMocker', () => { it('mocks regexp instances', () => { expect( - () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)) + () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)), ).not.toThrow(); }); }); diff --git a/packages/jest-mock/src/index.js b/packages/jest-mock/src/index.js index 740892a1d4e6..4ad4c2211034 100644 --- a/packages/jest-mock/src/index.js +++ b/packages/jest-mock/src/index.js @@ -150,7 +150,7 @@ function getSlots(object?: Object): Array { function createMockFunction( metadata: MockFunctionMetadata, - mockConstructor: () => any + mockConstructor: () => any, ): any { let name = metadata.name; if (!name) { @@ -180,7 +180,7 @@ function createMockFunction( 'mockConstructor', 'return function ' + name + '() {' + 'return mockConstructor.apply(this,arguments);' + - '}' + bindCall + '}' + bindCall, )(mockConstructor); /* eslint-enable no-new-func */ } @@ -327,7 +327,7 @@ function makeComponent(metadata: MockFunctionMetadata): Mock { function generateMock( metadata: MockFunctionMetadata, callbacks: Array<() => any>, - refs: Object + refs: Object, ): Mock { const mock = makeComponent(metadata); if (metadata.refID != null) { @@ -364,7 +364,7 @@ function generateFromMetadata(_metadata: MockFunctionMetadata): Mock { function getMetadata( component: any, - _refs?: Map + _refs?: Map, ): ?MockFunctionMetadata { const refs = _refs || new Map(); const ref = refs.get(component); diff --git a/packages/jest-repl/src/cli/args.js b/packages/jest-repl/src/cli/args.js index 210d8f178555..f15a37ba826d 100644 --- a/packages/jest-repl/src/cli/args.js +++ b/packages/jest-repl/src/cli/args.js @@ -24,7 +24,7 @@ const options = { alias: 'r', description: wrap( 'The "name" of the file given to preprocessors to be transpiled. ' + - 'For example, "repl.ts" if using a Typescript preprocessor.' + 'For example, "repl.ts" if using a Typescript preprocessor.', ), type: 'string', }, diff --git a/packages/jest-repl/src/cli/repl.js b/packages/jest-repl/src/cli/repl.js index ccc2d3ba0ed6..8d3e5a426017 100644 --- a/packages/jest-repl/src/cli/repl.js +++ b/packages/jest-repl/src/cli/repl.js @@ -30,7 +30,7 @@ const evalCommand = (cmd, context, filename, callback, config) => { cmd = preprocessor.process( cmd, jestConfig.replname || 'jest.js', - jestConfig + jestConfig, ); } result = vm.runInThisContext(cmd); @@ -58,7 +58,7 @@ if (jestConfig.scriptPreprocessor) { preprocessor = require(jestConfig.scriptPreprocessor); if (typeof preprocessor.process !== 'function') { throw new TypeError( - 'Jest: a preprocessor must export a `process` function.' + 'Jest: a preprocessor must export a `process` function.', ); } } diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 082753056dd5..92384bada5fb 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -66,7 +66,7 @@ const getModuleNameMapper = (config: Config) => { if (config.moduleNameMapper.length) { const moduleNameMapper = Object.create(null); config.moduleNameMapper.forEach( - map => moduleNameMapper[map[1]] = new RegExp(map[0]) + map => moduleNameMapper[map[1]] = new RegExp(map[0]), ); return moduleNameMapper; } @@ -126,7 +126,7 @@ class Resolver { extensions: options.extensions, moduleDirectory: options.moduleDirectory, paths: paths ? (nodePaths || []).concat(paths) : nodePaths, - } + }, ); } catch (e) {} return null; @@ -142,7 +142,7 @@ class Resolver { resolveModule( from: Path, moduleName: string, - options?: ResolveModuleConfig + options?: ResolveModuleConfig, ): Path { const dirname = path.dirname(from); const paths = this._options.modulePaths; @@ -185,7 +185,7 @@ class Resolver { if (module) { try { return this._moduleNameCache[key] = require.resolve( - path.join.apply(path, [path.dirname(module)].concat(parts)) + path.join.apply(path, [path.dirname(module)].concat(parts)), ); } catch (ignoredError) {} } @@ -195,7 +195,7 @@ class Resolver { // current module name available. const relativePath = path.relative(dirname, from); const err = new Error( - `Cannot find module '${moduleName}' from '${relativePath || '.'}'` + `Cannot find module '${moduleName}' from '${relativePath || '.'}'`, ); (err: any).code = 'MODULE_NOT_FOUND'; throw err; @@ -256,7 +256,7 @@ class Resolver { resolveDependencies( file: Path, - options?: ResolveModuleConfig + options?: ResolveModuleConfig, ): Array { if (!this._moduleMap.files[file]) { return []; @@ -277,7 +277,7 @@ class Resolver { resolveInverseDependencies( paths: Set, filter: (file: Path) => boolean, - options?: ResolveModuleConfig + options?: ResolveModuleConfig, ): Array { const collectModules = (relatedPaths, moduleMap, changed) => { const visitedModules = new Set(); diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index 35bb0c31b898..efdb26137aae 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -28,7 +28,7 @@ module.exports = function createRuntime(filename, config) { const runtime = new Runtime( config, environment, - createResolver(config, moduleMap) + createResolver(config, moduleMap), ); runtime.__mockRootPath = path.join(config.rootDir, 'root.js'); diff --git a/packages/jest-runtime/src/__mocks__/jest-environment-jsdom.js b/packages/jest-runtime/src/__mocks__/jest-environment-jsdom.js index c3ce3e10433c..7cf8b67e2632 100644 --- a/packages/jest-runtime/src/__mocks__/jest-environment-jsdom.js +++ b/packages/jest-runtime/src/__mocks__/jest-environment-jsdom.js @@ -30,7 +30,7 @@ JSDOMEnvironment.prototype.runSourceText.mockImplementation( filename, displayErrors: false, }); - } + }, ); module.exports = JSDOMEnvironment; diff --git a/packages/jest-runtime/src/__tests__/Resolve-browser-test.js b/packages/jest-runtime/src/__tests__/Resolve-browser-test.js index 62e3cb2ca5fb..6e0c9d1ba684 100644 --- a/packages/jest-runtime/src/__tests__/Resolve-browser-test.js +++ b/packages/jest-runtime/src/__tests__/Resolve-browser-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -28,10 +28,10 @@ describe('resolve', () => { }).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'jest-resolve-test' + 'jest-resolve-test', ); expect(exports.isBrowser).toBe(true); - }) + }), ); it(`doesn't resolve "browser" dependency by default`, () => @@ -40,9 +40,9 @@ describe('resolve', () => { }).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'jest-resolve-test' + 'jest-resolve-test', ); expect(exports.isBrowser).toBe(false); - }) + }), ); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-NODE_PATH-test.js b/packages/jest-runtime/src/__tests__/Runtime-NODE_PATH-test.js index d48fee896dc2..448dcd4e649d 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-NODE_PATH-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-NODE_PATH-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); const path = require('path'); @@ -36,7 +36,7 @@ describe('Runtime', () => { return createLocalRuntime(nodePath).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModuleInNodePath' + 'RegularModuleInNodePath', ); expect(exports).toBeDefined(); }); @@ -47,7 +47,7 @@ describe('Runtime', () => { return createLocalRuntime(null, {modulePaths: nodePath}).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModuleInNodePath' + 'RegularModuleInNodePath', ); expect(exports).toBeDefined(); }); @@ -59,7 +59,7 @@ describe('Runtime', () => { return createLocalRuntime(nodePath).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModuleInNodePath' + 'RegularModuleInNodePath', ); expect(exports).toBeDefined(); }); @@ -72,11 +72,11 @@ describe('Runtime', () => { expect(() => { runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModuleInNodePath' + 'RegularModuleInNodePath', ); - }).toThrow( - new Error(`Cannot find module 'RegularModuleInNodePath' from 'root.js'`) - ); + }).toThrow(new Error( + `Cannot find module 'RegularModuleInNodePath' from 'root.js'`, + )); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-genMockFromModule-test.js b/packages/jest-runtime/src/__tests__/Runtime-genMockFromModule-test.js index 3f7ad569429e..91260ff0e252 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-genMockFromModule-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-genMockFromModule-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -28,7 +28,7 @@ describe('Runtime', () => { createRuntime(__filename).then(runtime => { const testRequire = runtime.requireModule.bind( runtime, - runtime.__mockRootPath + runtime.__mockRootPath, ); const module = testRequire('RegularModule'); @@ -42,7 +42,7 @@ describe('Runtime', () => { // Make sure we get a mock. expect(mock.fn()).toBe(undefined); expect(module.getModuleStateValue()).toBe(origModuleStateValue); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-getTestEnvData-test.js b/packages/jest-runtime/src/__tests__/Runtime-getTestEnvData-test.js index b904ce526703..5d26b9317c58 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-getTestEnvData-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-getTestEnvData-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); const config = { @@ -34,7 +34,7 @@ describe('Runtime', () => { const root = runtime.requireModule(runtime.__mockRootPath); const envData = root.jest.getTestEnvData(); expect(envData).toEqual(config.testEnvData); - }) + }), ); it('freezes jest.envData object', () => @@ -42,6 +42,6 @@ describe('Runtime', () => { const root = runtime.requireModule(runtime.__mockRootPath); const envData = root.jest.getTestEnvData(); expect(Object.isFrozen(envData)).toBe(true); - }) + }), ); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-jest-fn.js b/packages/jest-runtime/src/__tests__/Runtime-jest-fn.js index ea2d06f481e1..f62fd37ccce2 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-jest-fn.js +++ b/packages/jest-runtime/src/__tests__/Runtime-jest-fn.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -31,7 +31,7 @@ describe('Runtime', () => { expect(mock._isMockFunction).toBe(true); mock(); expect(mock).toBeCalled(); - }) + }), ); it('creates mock functions with mock implementations', () => @@ -42,7 +42,7 @@ describe('Runtime', () => { const value = mock('mock'); expect(value).toEqual('mock implementation'); expect(mock).toBeCalled(); - }) + }), ); }); @@ -53,7 +53,7 @@ describe('Runtime', () => { const mock = root.jest.fn(); expect(root.jest.isMockFunction(() => {})).toBe(false); expect(root.jest.isMockFunction(mock)).toBe(true); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-jsdom-env-test.js b/packages/jest-runtime/src/__tests__/Runtime-jsdom-env-test.js index 4180200b49a9..efab916d496d 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-jsdom-env-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-jsdom-env-test.js @@ -31,7 +31,7 @@ describe('Runtime', () => { expect(err.stack).toMatch(/^Error: throwing\s+at Object./); } expect(hasThrown).toBe(true); - }) + }), ); it('emulates a node stack trace during function execution', () => @@ -39,7 +39,7 @@ describe('Runtime', () => { let hasThrown = false; const sum = runtime.requireModule( runtime.__mockRootPath, - './throwing-fn.js' + './throwing-fn.js', ); try { @@ -49,17 +49,17 @@ describe('Runtime', () => { /* eslint-disable max-len */ if (process.platform === 'win32') { expect(err.stack).toMatch( - /^Error: throwing fn\s+at sum.+\\__tests__\\test_root\\throwing-fn.js:12:9/ + /^Error: throwing fn\s+at sum.+\\__tests__\\test_root\\throwing-fn.js:12:9/, ); } else { expect(err.stack).toMatch( - /^Error: throwing fn\s+at sum.+\/__tests__\/test_root\/throwing-fn.js:12:9/ + /^Error: throwing fn\s+at sum.+\/__tests__\/test_root\/throwing-fn.js:12:9/, ); } /* eslint-enable max-len */ } expect(hasThrown).toBe(true); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-mock-test.js b/packages/jest-runtime/src/__tests__/Runtime-mock-test.js index 6536e79ebc57..30cb710f8e67 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-mock-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-mock-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -35,13 +35,13 @@ describe('Runtime', () => { root.jest.mock('ManuallyMocked', () => mockReference); expect( - runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule') + runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule'), ).toEqual(mockReference); expect( - runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule') + runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule'), ).toEqual(mockReference); - }) + }), ); it('sets virtual mock for non-existing module', () => @@ -58,17 +58,17 @@ describe('Runtime', () => { expect( runtime.requireModuleOrMock( runtime.__mockRootPath, - 'NotInstalledModule' - ) + 'NotInstalledModule', + ), ).toEqual(mockReference); expect( runtime.requireModuleOrMock( runtime.__mockRootPath, - '../ManuallyMocked' - ) + '../ManuallyMocked', + ), ).toEqual(mockReference); - }) + }), ); }); @@ -84,13 +84,13 @@ describe('Runtime', () => { root.jest.setMock('ManuallyMocked', mockReference); expect( - runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule') + runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule'), ).toBe(mockReference); expect( - runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule') + runtime.requireModuleOrMock(runtime.__mockRootPath, 'RegularModule'), ).toBe(mockReference); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-moduleDirectories-test.js b/packages/jest-runtime/src/__tests__/Runtime-moduleDirectories-test.js index 4622a9acbbe2..6eab7d286a9a 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-moduleDirectories-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-moduleDirectories-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); const path = require('path'); @@ -33,40 +33,40 @@ describe('Runtime', () => { createRuntime(__filename, {moduleDirectories}).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'moduleDirModule' + 'moduleDirModule', ); expect(exports).toBeDefined(); - }) + }), ); it('resolves packages', () => createRuntime(__filename, {moduleDirectories}).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'my-module' + 'my-module', ); expect(exports.isNodeModule).toEqual(true); - }) + }), ); it('finds closest module from moduleDirectories', () => createRuntime(__filename, {moduleDirectories}).then(runtime => { const exports = runtime.requireModule( path.join(rootDir, 'subdir2', 'MyModule.js'), - 'moduleDirModule' + 'moduleDirModule', ); expect(exports.modulePath) .toEqual('subdir2/module_dir/moduleDirModule.js'); - }) + }), ); it('only checks the configured directories', () => createRuntime(__filename, {moduleDirectories}).then(runtime => { expect(() => { runtime.requireModule(runtime.__mockRootPath, 'not-a-haste-package'); - }).toThrow( - new Error('Cannot find module \'not-a-haste-package\' from \'root.js\'') - ); - }) + }).toThrow(new Error( + 'Cannot find module \'not-a-haste-package\' from \'root.js\'', + )); + }), ); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-requireMock-test.js b/packages/jest-runtime/src/__tests__/Runtime-requireMock-test.js index cd54e6214d93..f9cb59100a0d 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-requireMock-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-requireMock-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -28,64 +28,64 @@ describe('Runtime', () => { createRuntime(__filename).then(runtime => { const exports = runtime.requireMock( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); expect(exports.isManualMockModule).toBe(true); - }) + }), ); it('can resolve modules that are only referenced from mocks', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireMock( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); expect( - exports.onlyRequiredFromMockModuleValue + exports.onlyRequiredFromMockModuleValue, ).toBe('banana banana banana'); - }) + }), ); it('stores and re-uses manual mock exports', () => createRuntime(__filename).then(runtime => { let exports = runtime.requireMock( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); exports.setModuleStateValue('test value'); exports = runtime.requireMock(runtime.__mockRootPath, 'ManuallyMocked'); expect(exports.getModuleStateValue()).toBe('test value'); - }) + }), ); it('automocks @providesModule modules without a manual mock', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.getModuleStateValue._isMockFunction).toBe(true); - }) + }), ); it('automocks relative-path modules without a file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireMock( __filename, - './test_root/RegularModule' + './test_root/RegularModule', ); expect(exports.getModuleStateValue._isMockFunction).toBe(true); - }) + }), ); it('automocks relative-path modules with a file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireMock( __filename, - './test_root/RegularModule.js' + './test_root/RegularModule.js', ); expect(exports.getModuleStateValue._isMockFunction).toBe(true); - }) + }), ); it('just falls back when loading a native module', () => @@ -99,52 +99,52 @@ describe('Runtime', () => { try { runtime.requireMock( __filename, - './test_root/NativeModule.node' + './test_root/NativeModule.node', ); } catch (e) { error = e; } finally { expect(error.message).toMatch( - /NativeModule.node\: file too short|not a valid Win\d+ application/ + /NativeModule.node\: file too short|not a valid Win\d+ application/, ); } - }) + }), ); it('stores and re-uses automocked @providesModule exports', () => createRuntime(__filename).then(runtime => { let exports = runtime.requireMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); exports.externalMutation = 'test value'; exports = runtime.requireMock(runtime.__mockRootPath, 'RegularModule'); expect(exports.externalMutation).toBe('test value'); - }) + }), ); it('stores and re-uses automocked relative-path modules', () => createRuntime(__filename).then(runtime => { let exports = runtime.requireMock( __filename, - './test_root/RegularModule' + './test_root/RegularModule', ); exports.externalMutation = 'test value'; exports = runtime.requireMock( __filename, - './test_root/RegularModule' + './test_root/RegularModule', ); expect(exports.externalMutation).toBe('test value'); - }) + }), ); it('multiple node core modules returns correct module', () => createRuntime(__filename).then(runtime => { runtime.requireMock(runtime.__mockRootPath, 'fs'); expect( - runtime.requireMock(runtime.__mockRootPath, 'events').EventEmitter + runtime.requireMock(runtime.__mockRootPath, 'events').EventEmitter, ).toBeDefined(); - }) + }), ); it('throws on non-existent @providesModule modules', () => @@ -152,27 +152,27 @@ describe('Runtime', () => { expect(() => { runtime.requireMock(runtime.__mockRootPath, 'DoesntExist'); }).toThrow(); - }) + }), ); it('uses the closest manual mock when duplicates exist', () => createRuntime(__filename).then(runtime => { const exports1 = runtime.requireMock( runtime.__mockRootPath, - './subdir1/MyModule' + './subdir1/MyModule', ); expect(exports1.modulePath).toEqual( - 'subdir1/__mocks__/MyModule.js' + 'subdir1/__mocks__/MyModule.js', ); const exports2 = runtime.requireMock( runtime.__mockRootPath, - './subdir2/MyModule' + './subdir2/MyModule', ); expect(exports2.modulePath).toEqual( - 'subdir2/__mocks__/MyModule.js' + 'subdir2/__mocks__/MyModule.js', ); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-requireModule-test.js b/packages/jest-runtime/src/__tests__/Runtime-requireModule-test.js index d596cba07de3..250db086ebeb 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-requireModule-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-requireModule-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); const path = require('path'); @@ -28,35 +28,35 @@ describe('Runtime requireModule', () => { createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it('provides `module.parent` to modules', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.parent).toEqual({ id: 'mockParent', exports: {}, }); - }) + }), ); it('provides `module.filename` to modules', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.filename.endsWith( - 'test_root' + path.sep + 'RegularModule.js' + 'test_root' + path.sep + 'RegularModule.js', )).toBe(true); - }) + }), ); it('provides `module.paths` to modules', () => { @@ -66,12 +66,12 @@ describe('Runtime requireModule', () => { return createRuntime(__filename, {moduleDirectories}).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.paths.length).toBeGreaterThan(0); exports.paths.forEach(path => { expect( - moduleDirectories.some(dir => path.endsWith(dir)) + moduleDirectories.some(dir => path.endsWith(dir)), ).toBe(true); }); }); @@ -82,29 +82,29 @@ describe('Runtime requireModule', () => { expect(() => { runtime.requireModule(runtime.__mockRootPath, 'DoesntExist'); }).toThrow( - new Error('Cannot find module \'DoesntExist\' from \'root.js\'') + new Error('Cannot find module \'DoesntExist\' from \'root.js\''), ); - }) + }), ); it('finds relative-path modules without file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - './RegularModule' + './RegularModule', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it('finds relative-path modules with file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - './RegularModule.js' + './RegularModule.js', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it('throws on non-existent relative-path modules', () => @@ -112,9 +112,9 @@ describe('Runtime requireModule', () => { expect(() => { runtime.requireModule(runtime.__mockRootPath, './DoesntExist'); }).toThrow( - new Error('Cannot find module \'./DoesntExist\' from \'root.js\'') + new Error('Cannot find module \'./DoesntExist\' from \'root.js\''), ); - }) + }), ); it('finds node core built-in modules', () => @@ -122,53 +122,53 @@ describe('Runtime requireModule', () => { expect(() => { runtime.requireModule(runtime.__mockRootPath, 'fs'); }).not.toThrow(); - }) + }), ); it('finds and loads JSON files without file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - './JSONFile' + './JSONFile', ); expect(exports.isJSONModule).toBe(true); - }) + }), ); it('finds and loads JSON files with file extension', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - './JSONFile.json' + './JSONFile.json', ); expect(exports.isJSONModule).toBe(true); - }) + }), ); it('requires a JSON file twice successfully', () => createRuntime(__filename).then(runtime => { const exports1 = runtime.requireModule( runtime.__mockRootPath, - './JSONFile.json' + './JSONFile.json', ); const exports2 = runtime.requireModule( runtime.__mockRootPath, - './JSONFile.json' + './JSONFile.json', ); expect(exports1.isJSONModule).toBe(true); expect(exports2.isJSONModule).toBe(true); expect(exports1).toBe(exports2); - }) + }), ); it('provides manual mock when real module doesnt exist', () => createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'ExclusivelyManualMock' + 'ExclusivelyManualMock', ); expect(exports.isExclusivelyManualMockModule).toBe(true); - }) + }), ); it(`doesn't override real modules with manual mocks when explicitly marked with .unmock()`, () => @@ -178,20 +178,20 @@ describe('Runtime requireModule', () => { root.jest.unmock('ManuallyMocked'); const exports = runtime.requireModule( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); expect(exports.isManualMockModule).toBe(false); - }) + }), ); it('resolves haste packages properly', () => createRuntime(__filename).then(runtime => { const hastePackage = runtime.requireModule( runtime.__mockRootPath, - 'haste-package/core/module' + 'haste-package/core/module', ); expect(hastePackage.isHastePackage).toBe(true); - }) + }), ); it('resolves node modules properly when crawling node_modules', () => @@ -205,10 +205,10 @@ describe('Runtime requireModule', () => { }).then(runtime => { const hastePackage = runtime.requireModule( runtime.__mockRootPath, - 'not-a-haste-package' + 'not-a-haste-package', ); expect(hastePackage.isNodeModule).toBe(true); - }) + }), ); it('resolves platform extensions based on the default platform', () => @@ -216,7 +216,7 @@ describe('Runtime requireModule', () => { createRuntime(__filename).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'Platform' + 'Platform', ); expect(exports.platform).toBe('default'); @@ -229,7 +229,7 @@ describe('Runtime requireModule', () => { }).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'Platform' + 'Platform', ); expect(exports.platform).toBe('ios'); @@ -241,7 +241,7 @@ describe('Runtime requireModule', () => { }).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'Platform' + 'Platform', ); expect(exports.platform).toBe('default'); @@ -254,7 +254,7 @@ describe('Runtime requireModule', () => { }).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'Platform' + 'Platform', ); expect(exports.platform).toBe('android'); @@ -267,14 +267,14 @@ describe('Runtime requireModule', () => { }).then(runtime => { const exports = runtime.requireModule( runtime.__mockRootPath, - 'Platform' + 'Platform', ); // We prefer `native` over the default module if the default one // cannot be found. expect(exports.platform).toBe('native'); }), - ]) + ]), ); }); diff --git a/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js b/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js index af6fe351f2ab..effb1966d8bb 100644 --- a/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js +++ b/packages/jest-runtime/src/__tests__/Runtime-requireModuleOrMock-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); jest.mock( 'jest-environment-jsdom', - () => require('../__mocks__/jest-environment-jsdom') + () => require('../__mocks__/jest-environment-jsdom'), ); let createRuntime; @@ -35,10 +35,10 @@ describe('Runtime', () => { createRuntime(__filename, {moduleNameMapper}).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.setModuleStateValue._isMockFunction).toBe(true); - }) + }), ); it(`doesn't mock modules when explicitly unmocked`, () => @@ -47,10 +47,10 @@ describe('Runtime', () => { root.jest.unmock('RegularModule'); const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it(`doesn't mock modules when explicitly unmocked via a different denormalized module name`, () => @@ -59,10 +59,10 @@ describe('Runtime', () => { root.jest.unmock('./RegularModule'); const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it(`doesn't mock modules when disableAutomock() has been called`, () => @@ -71,20 +71,20 @@ describe('Runtime', () => { root.jest.disableAutomock(); const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.isRealModule).toBe(true); - }) + }), ); it('uses manual mock when automocking on and mock is avail', () => createRuntime(__filename, {moduleNameMapper}).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); expect(exports.isManualMockModule).toBe(true); - }) + }), ); it('does not use manual mock when automocking is off and a real module is available', () => @@ -93,50 +93,50 @@ describe('Runtime', () => { root.jest.disableAutomock(); const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'ManuallyMocked' + 'ManuallyMocked', ); expect(exports.isManualMockModule).toBe(false); - }) + }), ); it('resolves mapped module names and unmocks them by default', () => createRuntime(__filename, {moduleNameMapper}).then(runtime => { let exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'image!not-really-a-module' + 'image!not-really-a-module', ); expect(exports.isGlobalImageStub).toBe(true); exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'mappedToPath' + 'mappedToPath', ); expect(exports.isGlobalImageStub).toBe(true); exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'mappedToDirectory' + 'mappedToDirectory', ); expect(exports.isIndex).toBe(true); exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'cat.png' + 'cat.png', ); expect(exports.isRelativeImageStub).toBe(true); exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - '../photos/dog.png' + '../photos/dog.png', ); expect(exports.isRelativeImageStub).toBe(true); exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'module/name/test' + 'module/name/test', ); expect(exports).toBe('mapped_module'); - }) + }), ); it('automocking be disabled by default', () => @@ -146,10 +146,10 @@ describe('Runtime', () => { }).then(runtime => { const exports = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'RegularModule' + 'RegularModule', ); expect(exports.setModuleStateValue._isMockFunction).toBe(undefined); - }) + }), ); describe('transitive dependencies', () => { @@ -168,27 +168,27 @@ describe('Runtime', () => { }).then(runtime => { const root = runtime.requireModule( runtime.__mockRootPath, - './root.js' + './root.js', ); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep' + 'npm3-main-dep', )); // Test twice to make sure Runtime caching works properly root.jest.resetModuleRegistry(); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep') - ); + 'npm3-main-dep', + )); // Directly requiring the transitive dependency will mock it const transitiveDep = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-transitive-dep' + 'npm3-transitive-dep', ); expect(transitiveDep()).toEqual(undefined); - }) + }), ); it('unmocks transitive dependencies in node_modules when using unmock', () => @@ -197,23 +197,23 @@ describe('Runtime', () => { root.jest.unmock('npm3-main-dep'); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep' + 'npm3-main-dep', )); // Test twice to make sure Runtime caching works properly root.jest.resetModuleRegistry(); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep' + 'npm3-main-dep', )); // Directly requiring the transitive dependency will mock it const transitiveDep = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-transitive-dep' + 'npm3-transitive-dep', ); expect(transitiveDep()).toEqual(undefined); - }) + }), ); it('unmocks transitive dependencies in node_modules by default when using both patterns and unmock', () => @@ -225,23 +225,23 @@ describe('Runtime', () => { root.jest.unmock('npm3-main-dep'); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep' + 'npm3-main-dep', )); // Test twice to make sure Runtime caching works properly root.jest.resetModuleRegistry(); expectUnmocked(runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-main-dep' + 'npm3-main-dep', )); // Directly requiring the transitive dependency will mock it const transitiveDep = runtime.requireModuleOrMock( runtime.__mockRootPath, - 'npm3-transitive-dep' + 'npm3-transitive-dep', ); expect(transitiveDep()).toEqual(undefined); - }) + }), ); }); }); diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 70593acfcf67..8b31140a6aee 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -120,7 +120,7 @@ class Runtime { static buildHasteMap( config: Config, - options: BuildHasteMapOptions + options: BuildHasteMapOptions, ): Promise { utils.createDirectory(config.cacheDirectory); const instance = createHasteMap(config, { @@ -135,7 +135,7 @@ class Runtime { }), error => { throw error; - } + }, ); } @@ -183,7 +183,7 @@ class Runtime { this._moduleRegistry[modulePath] = localModule; if (path.extname(modulePath) === '.json') { localModule.exports = this._environment.global.JSON.parse( - fs.readFileSync(modulePath, 'utf8') + fs.readFileSync(modulePath, 'utf8'), ); } else if (path.extname(modulePath) === '.node') { // $FlowFixMe @@ -319,7 +319,7 @@ class Runtime { if (!collectors[filename]) { collectors[filename] = new this._CoverageCollector( moduleContent, - filename + filename, ); } const collector = collectors[filename]; @@ -348,7 +348,7 @@ class Runtime { filename, // __filename this._environment.global, // global object this._createRuntimeFor(filename), // jest object - collectorStore // the coverage object + collectorStore, // the coverage object ); this._isCurrentlyExecutingManualMock = origCurrExecutingManualMock; @@ -380,7 +380,7 @@ class Runtime { `your 'preprocessorIgnorePatterns' configuration is correct: http://facebook.github.io/jest/docs/api.html#preprocessorignorepatterns-array-string\n` + 'If you are currently setting up Jest or modifying your preprocessor, try `jest --no-cache`.\n' + `Preprocessor: ${preprocessorInfo}.\n${babelInfo}` + - `Jest tried to the execute the following ${hasPreprocessor ? 'preprocessed ' : ''}code:\n${moduleContent}\n` + `Jest tried to the execute the following ${hasPreprocessor ? 'preprocessed ' : ''}code:\n${moduleContent}\n`, ); } throw e; @@ -415,13 +415,13 @@ class Runtime { if (mockMetadata === null) { throw new Error( `Failed to get mock metadata: ${modulePath}\n\n` + - `See: http://facebook.github.io/jest/docs/manual-mocks.html#content` + `See: http://facebook.github.io/jest/docs/manual-mocks.html#content`, ); } this._mockMetaDataCache[modulePath] = mockMetadata; } return moduleMocker.generateFromMetadata( - this._mockMetaDataCache[modulePath] + this._mockMetaDataCache[modulePath], ); } @@ -634,7 +634,7 @@ class Runtime { // Make a shallow copy only because a deep copy seems like // overkill.. Object.keys(this._config.testEnvData).forEach( - key => frozenCopy[key] = this._config.testEnvData[key] + key => frozenCopy[key] = this._config.testEnvData[key], ); Object.freeze(frozenCopy); return frozenCopy; diff --git a/packages/jest-runtime/src/lib/transform.js b/packages/jest-runtime/src/lib/transform.js index 76ff7c2df40c..9f8e761aca2b 100644 --- a/packages/jest-runtime/src/lib/transform.js +++ b/packages/jest-runtime/src/lib/transform.js @@ -115,7 +115,7 @@ module.exports = (filePath: Path, config: Config): string => { if (!preprocessorRegExpCache.has(config)) { preprocessorRegExpCache.set( config, - new RegExp(config.preprocessorIgnorePatterns.join('|')) + new RegExp(config.preprocessorIgnorePatterns.join('|')), ); } const regex = preprocessorRegExpCache.get(config); @@ -129,7 +129,7 @@ module.exports = (filePath: Path, config: Config): string => { const preprocessor = require(config.scriptPreprocessor); if (typeof preprocessor.process !== 'function') { throw new TypeError( - 'Jest: a preprocessor must export a `process` function.' + 'Jest: a preprocessor must export a `process` function.', ); } @@ -141,7 +141,7 @@ module.exports = (filePath: Path, config: Config): string => { const cacheDir = path.join(baseCacheDir, cacheKey[0] + cacheKey[1]); const cachePath = path.join( cacheDir, - path.basename(filePath, path.extname(filePath)) + '_' + cacheKey + path.basename(filePath, path.extname(filePath)) + '_' + cacheKey, ); createDirectory(cacheDir); const cachedData = readCacheFile(filePath, cachePath); diff --git a/packages/jest-snapshot/src/SnapshotFile.js b/packages/jest-snapshot/src/SnapshotFile.js index 0f6c36167a45..68870ce29a0f 100644 --- a/packages/jest-snapshot/src/SnapshotFile.js +++ b/packages/jest-snapshot/src/SnapshotFile.js @@ -109,7 +109,7 @@ class SnapshotFile { for (const key in this._content) { const item = this._content[key]; snapshots.push( - 'exports[`' + escape(key) + '`] = `' + escape(item) + '`;' + 'exports[`' + escape(key) + '`] = `' + escape(item) + '`;', ); } @@ -160,7 +160,7 @@ module.exports = { const snapshotFilename = path.join( snapshotsPath, - path.basename(testPath) + '.' + SNAPSHOT_EXTENSION + path.basename(testPath) + '.' + SNAPSHOT_EXTENSION, ); return new SnapshotFile(snapshotFilename); diff --git a/packages/jest-snapshot/src/__tests__/SnapshotFile-test.js b/packages/jest-snapshot/src/__tests__/SnapshotFile-test.js index a534829c4d8c..1acab248264f 100644 --- a/packages/jest-snapshot/src/__tests__/SnapshotFile-test.js +++ b/packages/jest-snapshot/src/__tests__/SnapshotFile-test.js @@ -87,7 +87,7 @@ describe('SnapshotFile', () => { const snapshotFile = SnapshotFile.forFile(TEST_FILE); snapshotFile.add(SNAPSHOT, SNAPSHOT_VALUE); expect( - () => snapshotFile.add(SNAPSHOT, SNAPSHOT_VALUE) + () => snapshotFile.add(SNAPSHOT, SNAPSHOT_VALUE), ).not.toThrow(); }); diff --git a/packages/jest-snapshot/src/__tests__/getMatchers-test.js b/packages/jest-snapshot/src/__tests__/getMatchers-test.js index c3ec8a921d3b..d1d9da409cb7 100644 --- a/packages/jest-snapshot/src/__tests__/getMatchers-test.js +++ b/packages/jest-snapshot/src/__tests__/getMatchers-test.js @@ -25,7 +25,7 @@ describe('getMatchers', () => { const rendered = null; const expected = {}; expect( - () => toMatchSnapshot.compare(rendered, expected) + () => toMatchSnapshot.compare(rendered, expected), ).toThrow(); }); @@ -34,7 +34,7 @@ describe('getMatchers', () => { const rendered = {}; const expected = undefined; expect( - () => toMatchSnapshot.compare(rendered, expected) + () => toMatchSnapshot.compare(rendered, expected), ).toThrow(); }); }); diff --git a/packages/jest-snapshot/src/getMatchers.js b/packages/jest-snapshot/src/getMatchers.js index d2e54b41d05a..99c8b8eed7c3 100644 --- a/packages/jest-snapshot/src/getMatchers.js +++ b/packages/jest-snapshot/src/getMatchers.js @@ -31,13 +31,13 @@ module.exports = ( return { negativeCompare() { throw new Error( - 'Jest: `.not` can not be used with `.toMatchSnapshot()`.' + 'Jest: `.not` can not be used with `.toMatchSnapshot()`.', ); }, compare(actual: any, expected: any): CompareResult { if (expected !== undefined) { throw new Error( - 'Jest: toMatchSnapshot() does not accept parameters.' + 'Jest: toMatchSnapshot() does not accept parameters.', ); } @@ -85,11 +85,11 @@ module.exports = ( message = formatter .formatMatchFailure(Object.assign( ({matcherName}: FailedAssertion), - matches + matches, )) .replace( 'toMatchSnapshot:', - 'toMatchSnapshot #' + (callCount + 1) + ':' + 'toMatchSnapshot #' + (callCount + 1) + ':', ); } else { snapshotState.matched++; diff --git a/packages/jest-snapshot/src/index.js b/packages/jest-snapshot/src/index.js index 16089507678b..705fb52143cb 100644 --- a/packages/jest-snapshot/src/index.js +++ b/packages/jest-snapshot/src/index.js @@ -60,7 +60,7 @@ module.exports = { .filter(snapshotFile => !fileExists(path.resolve( path.dirname(snapshotFile), '..', - path.basename(snapshotFile, '.' + EXTENSION) + path.basename(snapshotFile, '.' + EXTENSION), ))) .map(snapshotFile => update && fs.unlinkSync(snapshotFile)) .length; diff --git a/packages/jest-util/src/FakeTimers.js b/packages/jest-util/src/FakeTimers.js index c09a77a7af30..9cb3bffaff25 100644 --- a/packages/jest-util/src/FakeTimers.js +++ b/packages/jest-util/src/FakeTimers.js @@ -30,13 +30,13 @@ type Timer = { }; type TimerAPI = { - clearImmediate(timeoutId?: any): void; - clearInterval(intervalId?: number): void; - clearTimeout(timeoutId?: any): void; - nextTick?: (callback: Callback) => void; - setImmediate(callback: any, ms?: number, ...args: Array): number; - setInterval(callback: any, ms?: number, ...args: Array): number; - setTimeout(callback: any, ms?: number, ...args: Array): number; + clearImmediate(timeoutId?: any): void, + clearInterval(intervalId?: number): void, + clearTimeout(timeoutId?: any): void, + nextTick?: (callback: Callback) => void, + setImmediate(callback: any, ms?: number, ...args: Array): number, + setInterval(callback: any, ms?: number, ...args: Array): number, + setTimeout(callback: any, ms?: number, ...args: Array): number, } const MS_IN_A_YEAR = 31536000000; @@ -75,22 +75,22 @@ class FakeTimers { this._fakeTimerAPIs = { setTimeout: mocks.getMockFn().mockImpl( - this._fakeSetTimeout.bind(this) + this._fakeSetTimeout.bind(this), ), clearTimeout: mocks.getMockFn().mockImpl( - this._fakeClearTimer.bind(this) + this._fakeClearTimer.bind(this), ), setInterval: mocks.getMockFn().mockImpl( - this._fakeSetInterval.bind(this) + this._fakeSetInterval.bind(this), ), clearInterval: mocks.getMockFn().mockImpl( - this._fakeClearTimer.bind(this) + this._fakeClearTimer.bind(this), ), setImmediate: mocks.getMockFn().mockImpl( - this._fakeSetImmediate.bind(this) + this._fakeSetImmediate.bind(this), ), clearImmediate: mocks.getMockFn().mockImpl( - this._fakeClearImmediate.bind(this) + this._fakeClearImmediate.bind(this), ), }; @@ -100,7 +100,7 @@ class FakeTimers { && typeof global.process.nextTick === 'function') { this._originalTimerAPIs.nextTick = global.process.nextTick; this._fakeTimerAPIs.nextTick = mocks.getMockFn().mockImpl( - this._fakeNextTick.bind(this) + this._fakeNextTick.bind(this), ); } @@ -119,7 +119,7 @@ class FakeTimers { clearAllTimers() { this._immediates.forEach( - immediate => this._fakeClearImmediate(immediate.uuid) + immediate => this._fakeClearImmediate(immediate.uuid), ); for (const uuid in this._timers) { delete this._timers[uuid]; @@ -157,7 +157,7 @@ class FakeTimers { if (i === this._maxLoops) { throw new Error( 'Ran ' + this._maxLoops + ' ticks, and there are still more! ' + - 'Assuming we\'ve hit an infinite recursion and bailing out...' + 'Assuming we\'ve hit an infinite recursion and bailing out...', ); } } @@ -177,7 +177,7 @@ class FakeTimers { throw new Error( 'Ran ' + this._maxLoops + ' immediates, and there are still more! Assuming ' + - 'we\'ve hit an infinite recursion and bailing out...' + 'we\'ve hit an infinite recursion and bailing out...', ); } } @@ -219,7 +219,7 @@ class FakeTimers { if (i === this._maxLoops) { throw new Error( 'Ran ' + this._maxLoops + ' timers, and there are still more! ' + - 'Assuming we\'ve hit an infinite recursion and bailing out...' + 'Assuming we\'ve hit an infinite recursion and bailing out...', ); } } @@ -262,7 +262,7 @@ class FakeTimers { if (i === this._maxLoops) { throw new Error( 'Ran ' + this._maxLoops + ' timers, and there are still more! ' + - 'Assuming we\'ve hit an infinite recursion and bailing out...' + 'Assuming we\'ve hit an infinite recursion and bailing out...', ); } } diff --git a/packages/jest-util/src/JasmineFormatter.js b/packages/jest-util/src/JasmineFormatter.js index 73b2b3031709..f8bc609a14e2 100644 --- a/packages/jest-util/src/JasmineFormatter.js +++ b/packages/jest-util/src/JasmineFormatter.js @@ -47,7 +47,7 @@ class JasmineFormatter { matcherName: string, isNot: boolean, actual: any, - expected: any + expected: any, ) { const ppActual = this.prettyPrint(actual); const ppExpected = this.prettyPrint(expected); @@ -71,7 +71,7 @@ class JasmineFormatter { result.matcherName, isNot, result.actual, - result.expected + result.expected, ); } else { message = ERROR_TITLE_COLOR(result.message); @@ -118,7 +118,7 @@ class JasmineFormatter { prettyPrint( object: any, indent?: string, - cycleWeakMap?: WeakMap + cycleWeakMap?: WeakMap, ) { if (!indent) { indent = ''; @@ -163,8 +163,8 @@ class JasmineFormatter { indent + value[0] + ': ' + this.prettyPrint( value[1], indent, - cycleWeakMap - ) + cycleWeakMap, + ), ); } return `Map {\n${output.join(',')}\n}`; @@ -175,8 +175,8 @@ class JasmineFormatter { this.prettyPrint( value, chalk.gray('|') + ' ' + indent, - cycleWeakMap - ) + cycleWeakMap, + ), ); } return `Set [\n${indent}${output.join(', ')}\n${indent}]`; @@ -190,7 +190,7 @@ class JasmineFormatter { value = object[orderedKeys[i]]; keysOutput.push( indent + keyIndent + orderedKeys[i] + ': ' + - this.prettyPrint(value, indent + keyIndent, cycleWeakMap) + this.prettyPrint(value, indent + keyIndent, cycleWeakMap), ); } return '{\n' + keysOutput.join(',\n') + '\n' + indent + '}'; diff --git a/packages/jest-util/src/__tests__/FakeTimers-test.js b/packages/jest-util/src/__tests__/FakeTimers-test.js index 2d748bbb067e..9eeae7145099 100644 --- a/packages/jest-util/src/__tests__/FakeTimers-test.js +++ b/packages/jest-util/src/__tests__/FakeTimers-test.js @@ -285,7 +285,7 @@ describe('FakeTimers', () => { fakeTimers.runAllTicks(); }).toThrow(new Error( 'Ran 100 ticks, and there are still more! Assuming we\'ve hit an ' + - 'infinite recursion and bailing out...' + 'infinite recursion and bailing out...', )); }); }); @@ -388,7 +388,7 @@ describe('FakeTimers', () => { fakeTimers.runAllTimers(); }).toThrow(new Error( 'Ran 100 timers, and there are still more! Assuming we\'ve hit an ' + - 'infinite recursion and bailing out...' + 'infinite recursion and bailing out...', )); }); }); @@ -459,7 +459,7 @@ describe('FakeTimers', () => { fakeTimers.runTimersToTime(50); }).toThrow(new Error( 'Ran 100 timers, and there are still more! Assuming we\'ve hit an ' + - 'infinite recursion and bailing out...' + 'infinite recursion and bailing out...', )); }); }); diff --git a/packages/jest-util/src/args.js b/packages/jest-util/src/args.js index 3866c945de98..c09639c21ab9 100644 --- a/packages/jest-util/src/args.js +++ b/packages/jest-util/src/args.js @@ -39,9 +39,7 @@ const warnAboutUnrecognizedOptions = (argv: Object, options: Object) => { !allowedOptions.has(arg) )); if (unrecognizedOptions.length) { - console.warn( - 'Unrecognized options: ' + unrecognizedOptions.join(', ') - ); + console.warn('Unrecognized options: ' + unrecognizedOptions.join(', ')); } }; diff --git a/scripts/.eslintrc b/scripts/.eslintrc new file mode 100644 index 000000000000..70b458fe5e7a --- /dev/null +++ b/scripts/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "babel/func-params-comma-dangle": 0 + } +}