From 02879c41144167862a6c4ec58f11a0759759b663 Mon Sep 17 00:00:00 2001 From: Eric Nakagawa Date: Wed, 26 Apr 2017 02:19:38 -0700 Subject: [PATCH] Resolve issues relating to 4-spaces, add crowdin-cli (#3369) Adding additional settings to prettier.js to catch unformatted files in packages/* Running 'yarn prettier' --- examples/async/request.js | 2 +- .../resolve/__tests__/resolve-test.js | 2 +- packages/babel-jest/src/index.js | 4 +- packages/babel-plugin-jest-hoist/src/index.js | 2 +- .../src/rules/no-disabled-tests.js | 3 +- .../src/rules/no-focused-tests.js | 3 +- packages/jest-changed-files/src/git.js | 6 +- packages/jest-changed-files/src/hg.js | 6 +- packages/jest-cli/src/TestSequencer.js | 4 +- packages/jest-cli/src/TestWorker.js | 2 +- .../jest-cli/src/__tests__/TestRunner-test.js | 4 +- packages/jest-cli/src/runJest.js | 2 +- packages/jest-config/src/normalize.js | 5 +- packages/jest-config/src/vendor/jsonlint.js | 4 +- .../src/parsers/BabylonParser.js | 3 +- .../src/__tests__/index-test.js | 303 +++++++++--------- packages/jest-haste-map/src/crawlers/node.js | 2 +- packages/jest-haste-map/src/index.js | 5 +- packages/jest-jasmine2/src/reporter.js | 2 +- .../src/__tests__/matchers-test.js | 22 +- packages/jest-matchers/src/index.js | 4 +- packages/jest-matchers/src/utils.js | 4 +- packages/jest-mock/src/index.js | 2 +- packages/jest-runtime/src/index.js | 7 +- packages/jest-runtime/src/shouldInstrument.js | 3 +- packages/jest-util/src/setGlobal.js | 2 +- packages/pretty-format/src/index.js | 9 +- scripts/prettier.js | 1 + website/package.json | 3 +- website/server/translationPre.js | 76 +++-- website/src/jest/en/help.js | 6 +- website/src/jest/en/index.js | 6 +- website/src/jest/en/support.js | 20 +- website/src/jest/en/users.js | 6 +- website/src/jest/help.js | 6 +- website/src/jest/index.js | 6 +- website/src/jest/support.js | 20 +- website/src/jest/users.js | 6 +- 38 files changed, 301 insertions(+), 272 deletions(-) diff --git a/examples/async/request.js b/examples/async/request.js index 05d9e1e38d57..e0e85fe8f85a 100644 --- a/examples/async/request.js +++ b/examples/async/request.js @@ -11,7 +11,7 @@ export default function request(url) { // This module is being mocked in __mocks__/request.js http.get({path: url}, response => { let data = ''; - response.on('data', _data => data += _data); + response.on('data', _data => (data += _data)); response.on('end', () => resolve(data)); }); }); diff --git a/integration_tests/resolve/__tests__/resolve-test.js b/integration_tests/resolve/__tests__/resolve-test.js index 60f3d6be4c1b..dca2c4f4f1e2 100644 --- a/integration_tests/resolve/__tests__/resolve-test.js +++ b/integration_tests/resolve/__tests__/resolve-test.js @@ -10,7 +10,7 @@ let platform; function testRequire(filename) { - return () => platform = require(filename); + return () => (platform = require(filename)); } test('should explicitly resolve filename..js', () => { diff --git a/packages/babel-jest/src/index.js b/packages/babel-jest/src/index.js index 607a24ccb410..e7c25546c87e 100644 --- a/packages/babel-jest/src/index.js +++ b/packages/babel-jest/src/index.js @@ -53,7 +53,9 @@ const getBabelRC = (filename, {useCache}) => { // $FlowFixMe const packageJsonFileContents = require(packageJsonFilePath); if (packageJsonFileContents[BABEL_CONFIG_KEY]) { - cache[directory] = JSON.stringify(packageJsonFileContents[BABEL_CONFIG_KEY]); + cache[directory] = JSON.stringify( + packageJsonFileContents[BABEL_CONFIG_KEY], + ); break; } } diff --git a/packages/babel-plugin-jest-hoist/src/index.js b/packages/babel-plugin-jest-hoist/src/index.js index cef9ea0f4268..853a24f01b8f 100644 --- a/packages/babel-plugin-jest-hoist/src/index.js +++ b/packages/babel-plugin-jest-hoist/src/index.js @@ -66,7 +66,7 @@ const WHITELISTED_IDENTIFIERS = { require: true, undefined: true, }; -Object.keys(global).forEach(name => WHITELISTED_IDENTIFIERS[name] = true); +Object.keys(global).forEach(name => (WHITELISTED_IDENTIFIERS[name] = true)); const JEST_GLOBAL = {name: 'jest'}; const IDVisitor = { diff --git a/packages/eslint-plugin-jest/src/rules/no-disabled-tests.js b/packages/eslint-plugin-jest/src/rules/no-disabled-tests.js index 41c7a40e6684..1018c265976e 100644 --- a/packages/eslint-plugin-jest/src/rules/no-disabled-tests.js +++ b/packages/eslint-plugin-jest/src/rules/no-disabled-tests.js @@ -37,7 +37,8 @@ module.exports = (context: EslintContext) => ({ } if ( - callee.type === 'MemberExpression' && isCallToTestSkipFunction(callee) + callee.type === 'MemberExpression' && + isCallToTestSkipFunction(callee) ) { context.report({ message: 'Unexpected disabled test.', diff --git a/packages/eslint-plugin-jest/src/rules/no-focused-tests.js b/packages/eslint-plugin-jest/src/rules/no-focused-tests.js index e20cd64e9165..71250160fb8d 100644 --- a/packages/eslint-plugin-jest/src/rules/no-focused-tests.js +++ b/packages/eslint-plugin-jest/src/rules/no-focused-tests.js @@ -37,7 +37,8 @@ module.exports = (context: EslintContext) => ({ } if ( - callee.type === 'MemberExpression' && isCallToTestOnlyFunction(callee) + callee.type === 'MemberExpression' && + isCallToTestOnlyFunction(callee) ) { context.report({ message: 'Unexpected focused test.', diff --git a/packages/jest-changed-files/src/git.js b/packages/jest-changed-files/src/git.js index 3ec7e4ae99a4..801028576693 100644 --- a/packages/jest-changed-files/src/git.js +++ b/packages/jest-changed-files/src/git.js @@ -31,8 +31,8 @@ function findChangedFiles( const child = childProcess.spawn('git', args, {cwd}); let stdout = ''; let stderr = ''; - child.stdout.on('data', data => stdout += data); - child.stderr.on('data', data => stderr += data); + child.stdout.on('data', data => (stdout += data)); + child.stderr.on('data', data => (stderr += data)); child.on('error', e => reject(e)); child.on('close', code => { if (code === 0) { @@ -59,7 +59,7 @@ function isGitRepository(cwd: string): Promise { let stdout = ''; const options = ['rev-parse', '--show-toplevel']; const child = childProcess.spawn('git', options, {cwd}); - child.stdout.on('data', data => stdout += data); + child.stdout.on('data', data => (stdout += data)); child.on('error', () => resolve(null)); child.on('close', code => resolve(code === 0 ? stdout.trim() : null)); } catch (e) { diff --git a/packages/jest-changed-files/src/hg.js b/packages/jest-changed-files/src/hg.js index 6f11fcf8a737..f95b75dec8da 100644 --- a/packages/jest-changed-files/src/hg.js +++ b/packages/jest-changed-files/src/hg.js @@ -35,8 +35,8 @@ function findChangedFiles(cwd: string, options: Options): Promise> { const child = childProcess.spawn('hg', args, {cwd, env}); let stdout = ''; let stderr = ''; - child.stdout.on('data', data => stdout += data); - child.stderr.on('data', data => stderr += data); + child.stdout.on('data', data => (stdout += data)); + child.stderr.on('data', data => (stderr += data)); child.on('error', e => reject(e)); child.on('close', code => { if (code === 0) { @@ -62,7 +62,7 @@ function isHGRepository(cwd: string): Promise { try { let stdout = ''; const child = childProcess.spawn('hg', ['root'], {cwd, env}); - child.stdout.on('data', data => stdout += data); + child.stdout.on('data', data => (stdout += data)); child.on('error', () => resolve(null)); child.on('close', code => resolve(code === 0 ? stdout.trim() : null)); } catch (e) { diff --git a/packages/jest-cli/src/TestSequencer.js b/packages/jest-cli/src/TestSequencer.js index acde44c58419..6e601fcd3676 100644 --- a/packages/jest-cli/src/TestSequencer.js +++ b/packages/jest-cli/src/TestSequencer.js @@ -65,7 +65,7 @@ class TestSequencer { cache[test.path] && cache[test.path][0] === FAIL; const time = (cache, test) => cache[test.path] && cache[test.path][1]; - tests.forEach(test => test.duration = time(this._getCache(test), test)); + tests.forEach(test => (test.duration = time(this._getCache(test), test))); return tests.sort((testA, testB) => { const cacheA = this._getCache(testA); const cacheB = this._getCache(testB); @@ -87,7 +87,7 @@ class TestSequencer { cacheResults(tests: Tests, results: AggregatedResult) { const map = Object.create(null); - tests.forEach(test => map[test.path] = test); + tests.forEach(test => (map[test.path] = test)); results.testResults.forEach(testResult => { if (testResult && map[testResult.testFilePath] && !testResult.skipped) { const cache = this._getCache(map[testResult.testFilePath]); diff --git a/packages/jest-cli/src/TestWorker.js b/packages/jest-cli/src/TestWorker.js index 795e34b505a8..06bc0f0094c5 100644 --- a/packages/jest-cli/src/TestWorker.js +++ b/packages/jest-cli/src/TestWorker.js @@ -79,7 +79,7 @@ module.exports = ( callback: WorkerCallback, ) => { let parentExited = false; - const disconnectCallback = () => parentExited = true; + const disconnectCallback = () => (parentExited = true); const removeListener = () => process.removeListener('disconnect', disconnectCallback); process.on('disconnect', disconnectCallback); diff --git a/packages/jest-cli/src/__tests__/TestRunner-test.js b/packages/jest-cli/src/__tests__/TestRunner-test.js index ca0d15682ad5..047bf63c2166 100644 --- a/packages/jest-cli/src/__tests__/TestRunner-test.js +++ b/packages/jest-cli/src/__tests__/TestRunner-test.js @@ -19,9 +19,9 @@ let workerFarmMock; jest.mock('worker-farm', () => { const mock = jest.fn( (options, worker) => - workerFarmMock = jest.fn((data, callback) => + (workerFarmMock = jest.fn((data, callback) => require(worker)(data, callback), - ), + )), ); mock.end = jest.fn(); return mock; diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index 57147570e858..15e193399368 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -26,7 +26,7 @@ const TestSequencer = require('./TestSequencer'); const setConfig = (contexts, newConfig) => contexts.forEach( - context => context.config = Object.assign({}, context.config, newConfig), + context => (context.config = Object.assign({}, context.config, newConfig)), ); const formatTestPathPattern = pattern => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 5cec63a6f5cc..e65d9d56683f 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -90,7 +90,8 @@ const setupBabelJest = (config: InitialConfig) => { {basedir}, ); if ( - jsTransformer && jsTransformer.includes(NODE_MODULES + 'babel-jest') + jsTransformer && + jsTransformer.includes(NODE_MODULES + 'babel-jest') ) { babelJest = jsTransformer; } @@ -230,7 +231,7 @@ const normalizeArgv = (config: InitialConfig, argv: Object) => { if (argv.collectCoverageOnlyFrom) { const collectCoverageOnlyFrom = Object.create(null); argv.collectCoverageOnlyFrom.forEach( - path => collectCoverageOnlyFrom[path] = true, + path => (collectCoverageOnlyFrom[path] = true), ); config.collectCoverageOnlyFrom = collectCoverageOnlyFrom; } diff --git a/packages/jest-config/src/vendor/jsonlint.js b/packages/jest-config/src/vendor/jsonlint.js index 047f9a408050..c28f59b5b8f9 100644 --- a/packages/jest-config/src/vendor/jsonlint.js +++ b/packages/jest-config/src/vendor/jsonlint.js @@ -309,7 +309,9 @@ var jsonlint = (function() { // handle parse error _handle_error: if ( - typeof action === 'undefined' || !action.length || !action[0] + typeof action === 'undefined' || + !action.length || + !action[0] ) { if (!recovering) { // Report error diff --git a/packages/jest-editor-support/src/parsers/BabylonParser.js b/packages/jest-editor-support/src/parsers/BabylonParser.js index 640b82c519c0..39a0969238a6 100644 --- a/packages/jest-editor-support/src/parsers/BabylonParser.js +++ b/packages/jest-editor-support/src/parsers/BabylonParser.js @@ -145,7 +145,8 @@ const parse = (file: string) => { ) { searchNodes(element.expression.right.body, file); } else if ( - element.type === 'ReturnStatement' && element.argument.arguments + element.type === 'ReturnStatement' && + element.argument.arguments ) { element.argument.arguments .filter(argument => isFunctionDeclaration(argument.type)) diff --git a/packages/jest-haste-map/src/__tests__/index-test.js b/packages/jest-haste-map/src/__tests__/index-test.js index 03951d83e328..15900b78bcd2 100644 --- a/packages/jest-haste-map/src/__tests__/index-test.js +++ b/packages/jest-haste-map/src/__tests__/index-test.js @@ -17,9 +17,9 @@ jest.mock('child_process', () => ({ jest.mock('worker-farm', () => { const mock = jest.fn( (options, worker) => - workerFarmMock = jest.fn((data, callback) => + (workerFarmMock = jest.fn((data, callback) => require(worker)(data, callback), - ), + )), ); mock.end = jest.fn(); return mock; @@ -350,15 +350,15 @@ describe('HasteMap', () => { 'const Banana = require("Banana");', ].join('\n'); - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(data.map.Strawberry[H.GENERIC_PLATFORM][0]).toEqual( - '/fruits/raspberry.js', - ); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(data.map.Strawberry[H.GENERIC_PLATFORM][0]).toEqual( + '/fruits/raspberry.js', + ); - expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); - }); + expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); + }); }); it('throws on duplicate module ids if "throwOnModuleCollision" is set to true', () => { @@ -402,133 +402,138 @@ describe('HasteMap', () => { 'const Blackberry = require("Blackberry");', ].join('\n'); - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(data.files).toEqual({ - '/fruits/strawberry.android.js': ['Strawberry', 32, 1, ['Blackberry']], - '/fruits/strawberry.ios.js': ['Strawberry', 32, 1, ['Raspberry']], - '/fruits/strawberry.js': ['Strawberry', 32, 1, ['Banana']], - }); - - expect(data.map).toEqual({ - Strawberry: { - [H.GENERIC_PLATFORM]: ['/fruits/strawberry.js', H.MODULE], - android: ['/fruits/strawberry.android.js', H.MODULE], - ios: ['/fruits/strawberry.ios.js', H.MODULE], - }, + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(data.files).toEqual({ + '/fruits/strawberry.android.js': [ + 'Strawberry', + 32, + 1, + ['Blackberry'], + ], + '/fruits/strawberry.ios.js': ['Strawberry', 32, 1, ['Raspberry']], + '/fruits/strawberry.js': ['Strawberry', 32, 1, ['Banana']], + }); + + expect(data.map).toEqual({ + Strawberry: { + [H.GENERIC_PLATFORM]: ['/fruits/strawberry.js', H.MODULE], + android: ['/fruits/strawberry.android.js', H.MODULE], + ios: ['/fruits/strawberry.ios.js', H.MODULE], + }, + }); }); - }); }); it('does not access the file system on a warm cache with no changes', () => { - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: initialData, - }) => { - // The first run should access the file system once for the (empty) - // cache file and five times for the files in the system. - expect(fs.readFileSync.mock.calls.length).toBe(6); - - fs.readFileSync.mockClear(); - - // Explicitly mock that no files have changed. - mockChangedFiles = Object.create(null); - - // Watchman would give us different clocks. - mockClocks = object({ - '/fruits': 'c:fake-clock:3', - '/vegetables': 'c:fake-clock:4', - }); - - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(fs.readFileSync.mock.calls.length).toBe(1); - expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); - - expect(data.clocks).toEqual(mockClocks); - expect(data.files).toEqual(initialData.files); - expect(data.map).toEqual(initialData.map); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: initialData}) => { + // The first run should access the file system once for the (empty) + // cache file and five times for the files in the system. + expect(fs.readFileSync.mock.calls.length).toBe(6); + + fs.readFileSync.mockClear(); + + // Explicitly mock that no files have changed. + mockChangedFiles = Object.create(null); + + // Watchman would give us different clocks. + mockClocks = object({ + '/fruits': 'c:fake-clock:3', + '/vegetables': 'c:fake-clock:4', + }); + + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(fs.readFileSync.mock.calls.length).toBe(1); + expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); + + expect(data.clocks).toEqual(mockClocks); + expect(data.files).toEqual(initialData.files); + expect(data.map).toEqual(initialData.map); + }); }); - }); }); it('only does minimal file system access when files change', () => { - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: initialData, - }) => { - fs.readFileSync.mockClear(); - - // Let's assume one JS file has changed. - mockChangedFiles = object({ - '/fruits/banana.js': [ - '/**', - ' * @providesModule Kiwi', // Identity crisis. - ' */', - 'const Raspberry = require("Raspberry");', - ].join('\n'), - }); - - // Watchman would give us different clocks for `/fruits`. - mockClocks = object({ - '/fruits': 'c:fake-clock:3', - '/vegetables': 'c:fake-clock:2', - }); - - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(fs.readFileSync.mock.calls.length).toBe(2); - - expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); - expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); - - expect(data.clocks).toEqual(mockClocks); - - const files = object(initialData.files); - files['/fruits/banana.js'] = ['Kiwi', 32, 1, ['Raspberry']]; - - expect(data.files).toEqual(files); - - const map = object(initialData.map); - - map.Kiwi = map.Banana; - delete map.Banana; - expect(data.map).toEqual(map); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: initialData}) => { + fs.readFileSync.mockClear(); + + // Let's assume one JS file has changed. + mockChangedFiles = object({ + '/fruits/banana.js': [ + '/**', + ' * @providesModule Kiwi', // Identity crisis. + ' */', + 'const Raspberry = require("Raspberry");', + ].join('\n'), + }); + + // Watchman would give us different clocks for `/fruits`. + mockClocks = object({ + '/fruits': 'c:fake-clock:3', + '/vegetables': 'c:fake-clock:2', + }); + + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(fs.readFileSync.mock.calls.length).toBe(2); + + expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8'); + expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8'); + + expect(data.clocks).toEqual(mockClocks); + + const files = object(initialData.files); + files['/fruits/banana.js'] = ['Kiwi', 32, 1, ['Raspberry']]; + + expect(data.files).toEqual(files); + + const map = object(initialData.map); + + map.Kiwi = map.Banana; + delete map.Banana; + expect(data.map).toEqual(map); + }); }); - }); }); it('correctly handles file deletions', () => { - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: initialData, - }) => { - fs.readFileSync.mockClear(); - - // Let's assume one JS file was removed. - delete mockFs['/fruits/banana.js']; - mockChangedFiles = object({ - '/fruits/banana.js': null, - }); - - // Watchman would give us different clocks for `/fruits`. - mockClocks = object({ - '/fruits': 'c:fake-clock:3', - '/vegetables': 'c:fake-clock:2', - }); - - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - const files = object(initialData.files); - delete files['/fruits/banana.js']; - expect(data.files).toEqual(files); - - const map = object(initialData.map); - delete map.Banana; - expect(data.map).toEqual(map); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: initialData}) => { + fs.readFileSync.mockClear(); + + // Let's assume one JS file was removed. + delete mockFs['/fruits/banana.js']; + mockChangedFiles = object({ + '/fruits/banana.js': null, + }); + + // Watchman would give us different clocks for `/fruits`. + mockClocks = object({ + '/fruits': 'c:fake-clock:3', + '/vegetables': 'c:fake-clock:2', + }); + + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + const files = object(initialData.files); + delete files['/fruits/banana.js']; + expect(data.files).toEqual(files); + + const map = object(initialData.map); + delete map.Banana; + expect(data.map).toEqual(map); + }); }); - }); }); it('ignores files that do not exist', () => { @@ -542,14 +547,14 @@ describe('HasteMap', () => { return data; }); }); - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(Object.keys(data.files).length).toBe(5); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(Object.keys(data.files).length).toBe(5); - // Ensure this file is not part of the file list. - expect(data.files['/fruits/invalid/file.js']).toBe(undefined); - }); + // Ensure this file is not part of the file list. + expect(data.files['/fruits/invalid/file.js']).toBe(undefined); + }); }); it('distributes work across workers', () => { @@ -592,18 +597,18 @@ describe('HasteMap', () => { return Promise.resolve(data); }); - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(watchman).toBeCalled(); - expect(node).toBeCalled(); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(watchman).toBeCalled(); + expect(node).toBeCalled(); - expect(data.files).toEqual({ - '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']], - }); + expect(data.files).toEqual({ + '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']], + }); - expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); - }); + expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); + }); }); it('tries to crawl using node as a fallback when promise fails once', () => { @@ -621,16 +626,16 @@ describe('HasteMap', () => { return Promise.resolve(data); }); - return new HasteMap(defaultConfig).build().then(({ - __hasteMapForTest: data, - }) => { - expect(watchman).toBeCalled(); - expect(node).toBeCalled(); + return new HasteMap(defaultConfig) + .build() + .then(({__hasteMapForTest: data}) => { + expect(watchman).toBeCalled(); + expect(node).toBeCalled(); - expect(data.files).toEqual({ - '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']], + expect(data.files).toEqual({ + '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']], + }); }); - }); }); it('stops crawling when both crawlers fail', () => { diff --git a/packages/jest-haste-map/src/crawlers/node.js b/packages/jest-haste-map/src/crawlers/node.js index 922ef52fa732..a2c54d12708b 100644 --- a/packages/jest-haste-map/src/crawlers/node.js +++ b/packages/jest-haste-map/src/crawlers/node.js @@ -94,7 +94,7 @@ function findNative( const child = spawn('find', args); let stdout = ''; child.stdout.setEncoding('utf-8'); - child.stdout.on('data', data => stdout += data); + child.stdout.on('data', data => (stdout += data)); child.stdout.on('close', () => { const lines = stdout.trim().split('\n').filter(x => !ignore(x)); diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 8da6635abcea..bb2c4920b3f2 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -336,7 +336,8 @@ class HasteMap extends EventEmitter { } if ( - this._options.mocksPattern && this._options.mocksPattern.test(filePath) + this._options.mocksPattern && + this._options.mocksPattern.test(filePath) ) { const mockPath = getMockName(filePath); if (mocks[mockPath]) { @@ -689,7 +690,7 @@ class HasteMap extends EventEmitter { this._watchers.map( watcher => new Promise(resolve => watcher.close(resolve)), ), - ).then(() => this._watchers = []); + ).then(() => (this._watchers = [])); } /** diff --git a/packages/jest-jasmine2/src/reporter.js b/packages/jest-jasmine2/src/reporter.js index 2c286f22b4ad..d575571e6a70 100644 --- a/packages/jest-jasmine2/src/reporter.js +++ b/packages/jest-jasmine2/src/reporter.js @@ -58,7 +58,7 @@ class Jasmine2Reporter { this._testResults = []; this._currentSuites = []; this._resolve = null; - this._resultsPromise = new Promise(resolve => this._resolve = resolve); + this._resultsPromise = new Promise(resolve => (this._resolve = resolve)); this._startTimes = new Map(); } diff --git a/packages/jest-matchers/src/__tests__/matchers-test.js b/packages/jest-matchers/src/__tests__/matchers-test.js index 56d41eb33ae8..6dab5abaae8a 100644 --- a/packages/jest-matchers/src/__tests__/matchers-test.js +++ b/packages/jest-matchers/src/__tests__/matchers-test.js @@ -680,10 +680,13 @@ describe('.toMatch()', () => { }); describe('.toHaveLength', () => { - [[[1, 2], 2], [[], 0], [['a', 'b'], 2], ['abc', 3], ['', 0]].forEach(([ - received, - length, - ]) => { + [ + [[1, 2], 2], + [[], 0], + [['a', 'b'], 2], + ['abc', 3], + ['', 0], + ].forEach(([received, length]) => { test(`{pass: true} expect(${stringify(received)}).toHaveLength(${length})`, () => { jestExpect(received).toHaveLength(length); expect(() => @@ -692,10 +695,13 @@ describe('.toHaveLength', () => { }); }); - [[[1, 2], 3], [[], 1], [['a', 'b'], 99], ['abc', 66], ['', 1]].forEach(([ - received, - length, - ]) => { + [ + [[1, 2], 3], + [[], 1], + [['a', 'b'], 99], + ['abc', 66], + ['', 1], + ].forEach(([received, length]) => { test(`{pass: false} expect(${stringify(received)}).toHaveLength(${length})`, () => { jestExpect(received).not.toHaveLength(length); expect(() => diff --git a/packages/jest-matchers/src/index.js b/packages/jest-matchers/src/index.js index e5fed12e806b..8050a009a3e4 100644 --- a/packages/jest-matchers/src/index.js +++ b/packages/jest-matchers/src/index.js @@ -200,7 +200,7 @@ const makeThrowingMatcher = ( // matcher throws, test execution is normally stopped immediately. The // snapshot matcher uses it because we want to log all snapshot // failures in a test. - {dontThrow: () => throws = false}, + {dontThrow: () => (throws = false)}, global[GLOBAL_STATE].state, { isNot, @@ -276,7 +276,7 @@ expect.extend(spyMatchers); expect.extend(toThrowMatchers); expect.assertions = (expected: number) => - global[GLOBAL_STATE].state.assertionsExpected = expected; + (global[GLOBAL_STATE].state.assertionsExpected = expected); expect.setState = (state: MatcherState) => { Object.assign(global[GLOBAL_STATE].state, state); diff --git a/packages/jest-matchers/src/utils.js b/packages/jest-matchers/src/utils.js index fde7a84ec2d5..520177a4cfac 100644 --- a/packages/jest-matchers/src/utils.js +++ b/packages/jest-matchers/src/utils.js @@ -79,7 +79,9 @@ const getObjectSubset = (object: Object, subset: Object) => { const trimmed = {}; Object.keys(subset) .filter(key => object.hasOwnProperty(key)) - .forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key])); + .forEach( + key => (trimmed[key] = getObjectSubset(object[key], subset[key])), + ); if (Object.keys(trimmed).length > 0) { return trimmed; diff --git a/packages/jest-mock/src/index.js b/packages/jest-mock/src/index.js index ba7001b9b30e..b24e878ca3d7 100644 --- a/packages/jest-mock/src/index.js +++ b/packages/jest-mock/src/index.js @@ -438,7 +438,7 @@ class ModuleMockerClass { getSlots(metadata.members).forEach(slot => { const slotMetadata = (metadata.members && metadata.members[slot]) || {}; if (slotMetadata.ref != null) { - callbacks.push(() => mock[slot] = refs[slotMetadata.ref]); + callbacks.push(() => (mock[slot] = refs[slotMetadata.ref])); } else { mock[slot] = this._generateMock(slotMetadata, callbacks, refs); } diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 92b5b5a6b704..4f5dbc44b1d9 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -57,7 +57,8 @@ const SNAPSHOT_EXTENSION = 'snap'; const getModuleNameMapper = (config: ProjectConfig) => { if ( - Array.isArray(config.moduleNameMapper) && config.moduleNameMapper.length + Array.isArray(config.moduleNameMapper) && + config.moduleNameMapper.length ) { return config.moduleNameMapper.map(([regex, moduleName]) => { return {moduleName, regex: new RegExp(regex)}; @@ -126,7 +127,9 @@ class Runtime { this._unmockList = unmockRegExpCache.get(config); if ( - !this._unmockList && config.automock && config.unmockedModulePathPatterns + !this._unmockList && + config.automock && + config.unmockedModulePathPatterns ) { this._unmockList = new RegExp( config.unmockedModulePathPatterns.join('|'), diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index 3799afd69925..c54a38ef8a45 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -39,7 +39,8 @@ const shouldInstrument = (filename: Path, config: ProjectConfig): boolean => { if ( // This configuration field contains an object in the form of: // {'path/to/file.js': true} - config.collectCoverageOnlyFrom && !config.collectCoverageOnlyFrom[filename] + config.collectCoverageOnlyFrom && + !config.collectCoverageOnlyFrom[filename] ) { return false; } diff --git a/packages/jest-util/src/setGlobal.js b/packages/jest-util/src/setGlobal.js index 81bea53bcbca..7832add2b11b 100644 --- a/packages/jest-util/src/setGlobal.js +++ b/packages/jest-util/src/setGlobal.js @@ -14,4 +14,4 @@ import type {Global} from 'types/Global'; module.exports = (global: Global, key: string, value: any) => - global[key] = value; + (global[key] = value); diff --git a/packages/pretty-format/src/index.js b/packages/pretty-format/src/index.js index 2fe3572f8316..952634b70ec7 100644 --- a/packages/pretty-format/src/index.js +++ b/packages/pretty-format/src/index.js @@ -539,7 +539,10 @@ function printComplexValue( const hitMaxDepth = currentDepth > maxDepth; if ( - callToJSON && !hitMaxDepth && val.toJSON && typeof val.toJSON === 'function' + callToJSON && + !hitMaxDepth && + val.toJSON && + typeof val.toJSON === 'function' ) { return print( val.toJSON(), @@ -816,9 +819,9 @@ function normalizeOptions(opts: InitialOptions): Options { Object.keys(DEFAULTS).forEach( key => - result[key] = opts.hasOwnProperty(key) + (result[key] = opts.hasOwnProperty(key) ? key === 'theme' ? normalizeTheme(opts.theme) : opts[key] - : DEFAULTS[key], + : DEFAULTS[key]), ); if (result.min) { diff --git a/scripts/prettier.js b/scripts/prettier.js index 6c1c30eef8fc..f08a8ec3a1a3 100644 --- a/scripts/prettier.js +++ b/scripts/prettier.js @@ -18,6 +18,7 @@ const prettier = isWindows ? 'prettier.cmd' : 'prettier'; const prettierCmd = path.resolve(__dirname, '../node_modules/.bin/' + prettier); const defaultOptions = { 'bracket-spacing': 'false', + 'print-width': 80, 'single-quote': 'true', 'trailing-comma': 'all', }; diff --git a/website/package.json b/website/package.json index f8385b85010c..81e84d7fa952 100644 --- a/website/package.json +++ b/website/package.json @@ -7,15 +7,16 @@ "crowdin-download": "crowdin-cli --config ../crowdin.yaml download -b master" }, "dependencies": { - "prettier": "^1.2.2", "classnames": "2.2.4", "connect": "2.8.3", + "crowdin-cli": "^0.3.0", "feed": "0.3.0", "fs.extra": "*", "glob": "*", "mkdirp": "*", "object-assign": "^2.0.0", "optimist": "0.6.0", + "prettier": "^1.2.2", "react": "0.13.2", "react-page-middleware": "git://github.com/facebook/react-page-middleware.git", "request": "*" diff --git a/website/server/translationPre.js b/website/server/translationPre.js index f94d1e0c71a5..c7e4002c9d8e 100644 --- a/website/server/translationPre.js +++ b/website/server/translationPre.js @@ -89,11 +89,11 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestIndex = require('JestIndex');\n" + 'const index = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + - ' },\n' + + ' },\n' + '});\n' + 'module.exports = index;\n'; const helpTemplate = @@ -101,11 +101,11 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestHelp = require('JestHelp');\n" + 'const help = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + - ' },\n' + + ' },\n' + '});\n' + 'module.exports = help;\n'; const usersTemplate = @@ -113,8 +113,8 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestUsers = require('JestUsers');\n" + 'const users = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + ' },\n' + @@ -125,16 +125,16 @@ function generateBaseFiles() { "const React = require('React');\n" + "const RedirectLayout = require('RedirectLayout');\n" + 'class Support extends React.Component {\n' + - ' render() {\n' + - ' const metadata = {\n' + - " destinationUrl: 'help.html',\n" + - " id: 'support',\n" + - " layout: 'redirect',\n" + - " permalink: '/jest/support.html',\n" + - " source: 'support.md',\n" + - ' };\n' + - ' return ;\n' + - ' }\n' + + ' render() {\n' + + ' const metadata = {\n' + + " destinationUrl: 'help.html',\n" + + " id: 'support',\n" + + " layout: 'redirect',\n" + + " permalink: '/jest/support.html',\n" + + " source: 'support.md',\n" + + ' };\n' + + ' return ;\n' + + ' }\n' + '}\n' + 'module.exports = Support;\n'; @@ -161,9 +161,9 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestIndex = require('JestIndex');\n" + 'const index = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + - ' },\n' + + ' render() {\n' + + " return ;\n" + + ' },\n' + '});\n' + 'module.exports = index;\n'; const helpTemplate = @@ -171,9 +171,9 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestHelp = require('JestHelp');\n" + 'const help = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + - ' },\n' + + ' render() {\n' + + " return ;\n" + + ' },\n' + '});\n' + 'module.exports = help;\n'; const usersTemplate = @@ -181,9 +181,9 @@ function generateBaseFiles() { "const React = require('React');\n" + "const JestUsers = require('JestUsers');\n" + 'const users = React.createClass({\n' + - ' render() {\n' + - " return ;\n" + - ' },\n' + + ' render() {\n' + + " return ;\n" + + ' },\n' + '});\n' + 'module.exports = users;\n'; const supportTemplate = @@ -191,16 +191,16 @@ function generateBaseFiles() { "const React = require('React');\n" + "const RedirectLayout = require('RedirectLayout');\n" + 'class Support extends React.Component {\n' + - ' render() {\n' + - ' const metadata = {\n' + - " destinationUrl: 'help.html',\n" + - " id: 'support',\n" + - " layout: 'redirect',\n" + - " permalink: '/jest/support.html',\n" + - " source: 'support.md',\n" + - ' };\n' + - ' return ;\n' + - ' }\n' + + ' render() {\n' + + ' const metadata = {\n' + + " destinationUrl: 'help.html',\n" + + " id: 'support',\n" + + " layout: 'redirect',\n" + + " permalink: '/jest/support.html',\n" + + " source: 'support.md',\n" + + ' };\n' + + ' return ;\n' + + ' }\n' + '}\n' + 'module.exports = Support;\n'; @@ -244,8 +244,6 @@ function generateJS() { } ); - console.log('// prettier-ignore\n' + prettyFileContent); - fs.writeFileSync('./i18n/' + outputFileName + '.js', prettyFileContent); } }); diff --git a/website/src/jest/en/help.js b/website/src/jest/en/help.js index 4fa320dc1cd5..5c1aea7577ea 100644 --- a/website/src/jest/en/help.js +++ b/website/src/jest/en/help.js @@ -2,8 +2,8 @@ const React = require('React'); const JestHelp = require('JestHelp'); const support = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = support; diff --git a/website/src/jest/en/index.js b/website/src/jest/en/index.js index 0b3dc53c1b7b..60b33ad83fbb 100644 --- a/website/src/jest/en/index.js +++ b/website/src/jest/en/index.js @@ -2,8 +2,8 @@ const React = require('React'); const JestIndex = require('JestIndex'); const index = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = index; diff --git a/website/src/jest/en/support.js b/website/src/jest/en/support.js index a03ad8d0dcfc..d97946d85ebf 100644 --- a/website/src/jest/en/support.js +++ b/website/src/jest/en/support.js @@ -2,15 +2,15 @@ const React = require('React'); const RedirectLayout = require('RedirectLayout'); class Support extends React.Component { - render() { - const metadata = { - destinationUrl: 'help.html', - id: 'support', - layout: 'redirect', - permalink: '/jest/support.html', - source: 'support.md', - }; - return ; - } + render() { + const metadata = { + destinationUrl: 'help.html', + id: 'support', + layout: 'redirect', + permalink: '/jest/support.html', + source: 'support.md', + }; + return ; + } } module.exports = Support; diff --git a/website/src/jest/en/users.js b/website/src/jest/en/users.js index 5f2755e47af7..bd9b1dd158c0 100644 --- a/website/src/jest/en/users.js +++ b/website/src/jest/en/users.js @@ -2,8 +2,8 @@ const React = require('React'); const JestUsers = require('JestUsers'); const index = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = index; diff --git a/website/src/jest/help.js b/website/src/jest/help.js index 0379f75d9192..2e0b8289e1c9 100644 --- a/website/src/jest/help.js +++ b/website/src/jest/help.js @@ -2,8 +2,8 @@ const React = require('React'); const JestHelp = require('JestHelp'); const help = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = help; diff --git a/website/src/jest/index.js b/website/src/jest/index.js index 0b3dc53c1b7b..60b33ad83fbb 100644 --- a/website/src/jest/index.js +++ b/website/src/jest/index.js @@ -2,8 +2,8 @@ const React = require('React'); const JestIndex = require('JestIndex'); const index = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = index; diff --git a/website/src/jest/support.js b/website/src/jest/support.js index a03ad8d0dcfc..d97946d85ebf 100644 --- a/website/src/jest/support.js +++ b/website/src/jest/support.js @@ -2,15 +2,15 @@ const React = require('React'); const RedirectLayout = require('RedirectLayout'); class Support extends React.Component { - render() { - const metadata = { - destinationUrl: 'help.html', - id: 'support', - layout: 'redirect', - permalink: '/jest/support.html', - source: 'support.md', - }; - return ; - } + render() { + const metadata = { + destinationUrl: 'help.html', + id: 'support', + layout: 'redirect', + permalink: '/jest/support.html', + source: 'support.md', + }; + return ; + } } module.exports = Support; diff --git a/website/src/jest/users.js b/website/src/jest/users.js index 836c0274da81..1a3385cdcd5a 100644 --- a/website/src/jest/users.js +++ b/website/src/jest/users.js @@ -2,8 +2,8 @@ const React = require('React'); const JestUsers = require('JestUsers'); const users = React.createClass({ - render() { - return ; - }, + render() { + return ; + }, }); module.exports = users;