diff --git a/integration_tests/__tests__/toMatchSnapshot-test.js b/integration_tests/__tests__/toMatchSnapshot-test.js index 16fd092a82cd..459de5611fc9 100644 --- a/integration_tests/__tests__/toMatchSnapshot-test.js +++ b/integration_tests/__tests__/toMatchSnapshot-test.js @@ -20,7 +20,9 @@ afterAll(() => cleanup(TESTS_DIR)); test('basic support', () => { const filename = 'basic-support-test.js'; - const template = makeTemplate(`test('snapshots', () => expect($1).toMatchSnapshot());`); + const template = makeTemplate( + `test('snapshots', () => expect($1).toMatchSnapshot());`, + ); { makeTests(TESTS_DIR, {[filename]: template(['{apple: "original value"}'])}); @@ -52,10 +54,12 @@ test('basic support', () => { test('error thrown before snapshot', () => { const filename = 'error-thrown-before-snapshot-test.js'; - const template = makeTemplate(`test('snapshots', () => { + const template = makeTemplate( + `test('snapshots', () => { expect($1).toBeTruthy(); expect($2).toMatchSnapshot(); - });`); + });`, + ); { makeTests(TESTS_DIR, {[filename]: template(['true', '{a: "original"}'])}); @@ -80,10 +84,12 @@ test('error thrown before snapshot', () => { test('first snapshot fails, second passes', () => { const filename = 'first-snapshot-fails-second-passes-test.js'; - const template = makeTemplate(`test('snapshots', () => { + const template = makeTemplate( + `test('snapshots', () => { expect($1).toMatchSnapshot(); expect($2).toMatchSnapshot(); - });`); + });`, + ); { makeTests(TESTS_DIR, {[filename]: template([`'apple'`, `'banana'`])}); @@ -104,14 +110,16 @@ test('first snapshot fails, second passes', () => { test('does not mark snapshots as obsolete in skipped tests', () => { const filename = 'no-obsolete-if-skipped-test.js'; - const template = makeTemplate(`test('snapshots', () => { + const template = makeTemplate( + `test('snapshots', () => { expect(true).toBe(true); }); $1('will be skipped', () => { expect({a: 6}).toMatchSnapshot(); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template(['test'])}); @@ -130,10 +138,12 @@ test('does not mark snapshots as obsolete in skipped tests', () => { test('accepts custom snapshot name', () => { const filename = 'accept-custom-snapshot-name-test.js'; - const template = makeTemplate(`test('accepts custom snapshot name', () => { + const template = makeTemplate( + `test('accepts custom snapshot name', () => { expect(true).toMatchSnapshot('custom-name'); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template()}); diff --git a/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js b/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js index 908f959d9229..a5f5ce3b0b2e 100644 --- a/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js +++ b/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js @@ -20,11 +20,13 @@ afterAll(() => cleanup(TESTS_DIR)); test('works fine when function throws error', () => { const filename = 'works-fine-when-function-throws-error-test.js'; - const template = makeTemplate(`test('works fine when function throws error', () => { + const template = makeTemplate( + `test('works fine when function throws error', () => { expect(() => { throw new Error('apple'); }) .toThrowErrorMatchingSnapshot(); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template()}); @@ -36,10 +38,12 @@ test('works fine when function throws error', () => { test(`throws the error if tested function didn't throw error`, () => { const filename = 'throws-if-tested-function-did-not-throw-test.js'; - const template = makeTemplate(`test('throws the error if tested function did not throw error', () => { + const template = makeTemplate( + `test('throws the error if tested function did not throw error', () => { expect(() => {}).toThrowErrorMatchingSnapshot(); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template()}); @@ -51,11 +55,13 @@ test(`throws the error if tested function didn't throw error`, () => { test('does not accept arguments', () => { const filename = 'does-not-accept-arguments-test.js'; - const template = makeTemplate(`test('does not accept arguments', () => { + const template = makeTemplate( + `test('does not accept arguments', () => { expect(() => { throw new Error('apple'); }) .toThrowErrorMatchingSnapshot('foobar'); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template()}); @@ -67,10 +73,12 @@ test('does not accept arguments', () => { test('cannot be used with .not', () => { const filename = 'cannot-be-used-with-not-test.js'; - const template = makeTemplate(`test('cannot be used with .not', () => { + const template = makeTemplate( + `test('cannot be used with .not', () => { expect('').not.toThrowErrorMatchingSnapshot(); }); - `); + `, + ); { makeTests(TESTS_DIR, {[filename]: template()}); diff --git a/package.json b/package.json index 4aa818a3be8f..f956c4462587 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "lerna": "2.0.0-rc.4", "micromatch": "^2.3.11", "mkdirp": "^0.5.1", - "prettier": "1.3.0", + "prettier": "1.3.1", "progress": "^1.1.8", "react": "15.4.2", "react-addons-test-utils": "15.4.2", diff --git a/packages/jest-cli/src/TestNamePatternPrompt.js b/packages/jest-cli/src/TestNamePatternPrompt.js index 4db5362a92a3..f79f68d899af 100644 --- a/packages/jest-cli/src/TestNamePatternPrompt.js +++ b/packages/jest-cli/src/TestNamePatternPrompt.js @@ -76,8 +76,9 @@ module.exports = class TestNamePatternPrompt { if (pattern) { if (total) { - this._pipe - .write(`\n\n Pattern matches ${total} ${pluralizeTest(total)}`); + this._pipe.write( + `\n\n Pattern matches ${total} ${pluralizeTest(total)}`, + ); } else { this._pipe.write(`\n\n Pattern matches no tests`); } @@ -94,12 +95,16 @@ module.exports = class TestNamePatternPrompt { if (total > max) { const more = total - max; - this._pipe.write(// eslint-disable-next-line max-len - `\n ${chalk.dim(`\u203A and ${more} more ${pluralizeTest(more)}`)}`); + this._pipe.write( + // eslint-disable-next-line max-len + `\n ${chalk.dim(`\u203A and ${more} more ${pluralizeTest(more)}`)}`, + ); } } else { - this._pipe.write(// eslint-disable-next-line max-len - `\n\n ${chalk.italic.yellow('Start typing to filter by a test name regex pattern.')}`); + this._pipe.write( + // eslint-disable-next-line max-len + `\n\n ${chalk.italic.yellow('Start typing to filter by a test name regex pattern.')}`, + ); } this._pipe.write( diff --git a/packages/jest-cli/src/TestPathPatternPrompt.js b/packages/jest-cli/src/TestPathPatternPrompt.js index 2e97b878b6a4..0fce3466ba93 100644 --- a/packages/jest-cli/src/TestPathPatternPrompt.js +++ b/packages/jest-cli/src/TestPathPatternPrompt.js @@ -95,8 +95,9 @@ module.exports = class TestPathPatternPrompt { if (pattern) { if (total) { - this._pipe - .write(`\n\n Pattern matches ${total} ${pluralizeFile(total)}.`); + this._pipe.write( + `\n\n Pattern matches ${total} ${pluralizeFile(total)}.`, + ); } else { this._pipe.write(`\n\n Pattern matches no files.`); } @@ -121,12 +122,16 @@ module.exports = class TestPathPatternPrompt { if (total > max) { const more = total - max; - this._pipe.write(// eslint-disable-next-line max-len - `\n ${chalk.dim(`\u203A and ${more} more ${pluralizeFile(more)}`)}`); + this._pipe.write( + // eslint-disable-next-line max-len + `\n ${chalk.dim(`\u203A and ${more} more ${pluralizeFile(more)}`)}`, + ); } } else { - this._pipe.write(// eslint-disable-next-line max-len - `\n\n ${chalk.italic.yellow('Start typing to filter by a filename regex pattern.')}`); + this._pipe.write( + // eslint-disable-next-line max-len + `\n\n ${chalk.italic.yellow('Start typing to filter by a filename regex pattern.')}`, + ); } this._pipe.write( diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index f604a941bbad..bd3f2f9eb311 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -74,10 +74,8 @@ const relativePath = (config: {rootDir: Path}, testPath: Path) => { return {basename, dirname}; }; -const pluralize = ( - word: string, - count: number, -) => `${count} ${word}${count === 1 ? '' : 's'}`; +const pluralize = (word: string, count: number) => + `${count} ${word}${count === 1 ? '' : 's'}`; const getSummary = ( aggregatedResults: AggregatedResult, diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index fc3cbc2c9f6e..3a9606afda47 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -57,11 +57,8 @@ const getNoTestsFoundMessage = (testRunData, pattern) => { ); } - const pluralize = ( - word: string, - count: number, - ending: string, - ) => `${count} ${word}${count === 1 ? '' : ending}`; + const pluralize = (word: string, count: number, ending: string) => + `${count} ${word}${count === 1 ? '' : ending}`; const testPathPattern = formatTestPathPattern(pattern); const individualResults = testRunData.map(testRun => { const stats = testRun.matches.stats || {}; diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 0814c369628e..72f95cdc0472 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -177,13 +177,17 @@ const normalizeUnmockedModulePathPatterns = ( const normalizePreprocessor = (options: InitialOptions): InitialOptions => { /* eslint-disable max-len */ if (options.scriptPreprocessor && options.transform) { - throw createConfigError(` Options: ${chalk.bold('scriptPreprocessor')} and ${chalk.bold('transform')} cannot be used together. - Please change your configuration to only use ${chalk.bold('transform')}.`); + throw createConfigError( + ` Options: ${chalk.bold('scriptPreprocessor')} and ${chalk.bold('transform')} cannot be used together. + Please change your configuration to only use ${chalk.bold('transform')}.`, + ); } if (options.preprocessorIgnorePatterns && options.transformIgnorePatterns) { - throw createConfigError(` Options ${chalk.bold('preprocessorIgnorePatterns')} and ${chalk.bold('transformIgnorePatterns')} cannot be used together. - Please change your configuration to only use ${chalk.bold('transformIgnorePatterns')}.`); + throw createConfigError( + ` Options ${chalk.bold('preprocessorIgnorePatterns')} and ${chalk.bold('transformIgnorePatterns')} cannot be used together. + Please change your configuration to only use ${chalk.bold('transformIgnorePatterns')}.`, + ); } /* eslint-enable max-len */ @@ -220,7 +224,9 @@ const normalizeMissingOptions = (options: InitialOptions): InitialOptions => { const normalizeRootDir = (options: InitialOptions): InitialOptions => { // Assert that there *is* a rootDir if (!options.hasOwnProperty('rootDir')) { - throw createConfigError(` Configuration option ${chalk.bold('rootDir')} must be specified.`); + throw createConfigError( + ` Configuration option ${chalk.bold('rootDir')} must be specified.`, + ); } options.rootDir = path.normalize(options.rootDir); return options; diff --git a/packages/jest-config/src/utils.js b/packages/jest-config/src/utils.js index 4c5c129166f7..37b9b15860cd 100644 --- a/packages/jest-config/src/utils.js +++ b/packages/jest-config/src/utils.js @@ -39,7 +39,9 @@ const resolve = (rootDir: string, key: string, filePath: Path) => { if (!module) { /* eslint-disable max-len */ - throw createValidationError(` Module ${chalk.bold(filePath)} in the ${chalk.bold(key)} option was not found.`); + throw createValidationError( + ` Module ${chalk.bold(filePath)} in the ${chalk.bold(key)} option was not found.`, + ); /* eslint-disable max-len */ } @@ -117,7 +119,9 @@ const getTestEnvironment = (config: Object) => { } catch (e) {} /* eslint-disable max-len */ - throw createValidationError(` Test environment ${chalk.bold(env)} cannot be found. Make sure the ${chalk.bold('testEnvironment')} configuration option points to an existing node module.`); + throw createValidationError( + ` Test environment ${chalk.bold(env)} cannot be found. Make sure the ${chalk.bold('testEnvironment')} configuration option points to an existing node module.`, + ); /* eslint-disable max-len */ }; diff --git a/packages/jest-editor-support/src/__tests__/TestReconciler-test.js b/packages/jest-editor-support/src/__tests__/TestReconciler-test.js index 4a336913d2d4..8ec02216d382 100644 --- a/packages/jest-editor-support/src/__tests__/TestReconciler-test.js +++ b/packages/jest-editor-support/src/__tests__/TestReconciler-test.js @@ -47,10 +47,12 @@ describe('Test Reconciler', () => { expect(status.line).toEqual(12); const errorMessage = 'Expected value to be falsy, instead received true'; expect(status.terseMessage).toEqual(errorMessage); - expect(status.shortMessage).toEqual(`Error: expect(received).toBeFalsy() + expect(status.shortMessage).toEqual( + `Error: expect(received).toBeFalsy() Expected value to be falsy, instead received - true`); + true`, + ); }); }); }); diff --git a/packages/jest-snapshot/src/utils.js b/packages/jest-snapshot/src/utils.js index 19bbe765ed06..62166cd313fb 100644 --- a/packages/jest-snapshot/src/utils.js +++ b/packages/jest-snapshot/src/utils.js @@ -30,7 +30,8 @@ const SNAPSHOT_VERSION_WARNING = chalk.yellow( `to ensure that you do not store invalid state.`, ); -const writeSnapshotVersion = () => `// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`; +const writeSnapshotVersion = () => + `// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`; const validateSnapshotVersion = (snapshotContents: string) => { const versionTest = SNAPSHOT_VERSION_REGEXP.exec(snapshotContents); diff --git a/packages/jest-validate/src/__tests__/fixtures/jestConfig.js b/packages/jest-validate/src/__tests__/fixtures/jestConfig.js index 3b7d3757e57b..6210c1da2450 100644 --- a/packages/jest-validate/src/__tests__/fixtures/jestConfig.js +++ b/packages/jest-validate/src/__tests__/fixtures/jestConfig.js @@ -130,9 +130,8 @@ const format = (value: string) => require('pretty-format')(value, {min: true}); /* eslint-disable max-len */ const deprecatedConfig = { - preprocessorIgnorePatterns: ( - config: Object, - ) => ` Option ${chalk.bold('preprocessorIgnorePatterns')} was replaced by ${chalk.bold('transformIgnorePatterns')}, which support multiple preprocessors. + preprocessorIgnorePatterns: (config: Object) => + ` Option ${chalk.bold('preprocessorIgnorePatterns')} was replaced by ${chalk.bold('transformIgnorePatterns')}, which support multiple preprocessors. Jest now treats your current configuration as: { @@ -141,9 +140,8 @@ const deprecatedConfig = { Please update your configuration.`, - scriptPreprocessor: ( - config: Object, - ) => ` Option ${chalk.bold('scriptPreprocessor')} was replaced by ${chalk.bold('transform')}, which support multiple preprocessors. + scriptPreprocessor: (config: Object) => + ` Option ${chalk.bold('scriptPreprocessor')} was replaced by ${chalk.bold('transform')}, which support multiple preprocessors. Jest now treats your current configuration as: { diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js b/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js index 02ecd29ca233..3c6525ebe00b 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js @@ -52,8 +52,9 @@ beforeEach(() => { }, options, ); - expect(result) - .toEqual(`Object {\n "test": Object {\n "nested": Any<${fnNameFor(type)}>,\n },\n}`); + expect(result).toEqual( + `Object {\n "test": Object {\n "nested": Any<${fnNameFor(type)}>,\n },\n}`, + ); }); }); @@ -64,17 +65,21 @@ test(`anything()`, () => { test(`arrayContaining()`, () => { const result = prettyFormat(expect.arrayContaining([1, 2]), options); - expect(result).toEqual(`ArrayContaining [ + expect(result).toEqual( + `ArrayContaining [ 1, 2, -]`); +]`, + ); }); test(`objectContaining()`, () => { const result = prettyFormat(expect.objectContaining({a: 'test'}), options); - expect(result).toEqual(`ObjectContaining { + expect(result).toEqual( + `ObjectContaining { "a": "test", -}`); +}`, + ); }); test(`stringContaining(string)`, () => { @@ -108,7 +113,8 @@ test(`supports multiple nested asymmetric matchers`, () => { }, options, ); - expect(result).toEqual(`Object { + expect(result).toEqual( + `Object { "test": Object { "nested": ObjectContaining { "a": ArrayContaining [ @@ -123,7 +129,8 @@ test(`supports multiple nested asymmetric matchers`, () => { }, }, }, -}`); +}`, + ); }); test(`supports minified output`, () => { @@ -143,6 +150,7 @@ test(`supports minified output`, () => { }, options, ); - expect(result) - .toEqual(`{"test": {"nested": ObjectContaining {"a": ArrayContaining [1], "b": Anything, "c": Any, "d": StringContaining "jest", "e": StringMatching /jest/, "f": ObjectContaining {"test": "case"}}}}`); + expect(result).toEqual( + `{"test": {"nested": ObjectContaining {"a": ArrayContaining [1], "b": Anything, "c": Any, "d": StringContaining "jest", "e": StringMatching /jest/, "f": ObjectContaining {"test": "case"}}}}`, + ); }); diff --git a/packages/pretty-format/src/__tests__/ConvertAnsi-test.js b/packages/pretty-format/src/__tests__/ConvertAnsi-test.js index 47aec6c98fe7..7d0a888659d3 100644 --- a/packages/pretty-format/src/__tests__/ConvertAnsi-test.js +++ b/packages/pretty-format/src/__tests__/ConvertAnsi-test.js @@ -22,19 +22,25 @@ const prettyFormatResult = (val: string) => { describe('ConvertAnsi plugin', () => { it('supports style.red', () => { expect( - prettyFormatResult(`${ansiStyle.red.open} foo content ${ansiStyle.red.close}`), + prettyFormatResult( + `${ansiStyle.red.open} foo content ${ansiStyle.red.close}`, + ), ).toEqual('" foo content "'); }); it('supports style.green', () => { expect( - prettyFormatResult(`${ansiStyle.green.open} foo content ${ansiStyle.green.close}`), + prettyFormatResult( + `${ansiStyle.green.open} foo content ${ansiStyle.green.close}`, + ), ).toEqual('" foo content "'); }); it('supports style.reset', () => { expect( - prettyFormatResult(`${ansiStyle.reset.open} foo content ${ansiStyle.reset.close}`), + prettyFormatResult( + `${ansiStyle.reset.open} foo content ${ansiStyle.reset.close}`, + ), ).toEqual('" foo content "'); }); diff --git a/scripts/prettier.js b/scripts/prettier.js index 1ded17a54674..f08a8ec3a1a3 100644 --- a/scripts/prettier.js +++ b/scripts/prettier.js @@ -66,7 +66,9 @@ Object.keys(config).forEach(key => { console.log(e); if (!shouldWrite) { console.log( - chalk.red(` This project uses prettier to format all JavaScript code.\n`) + + chalk.red( + ` This project uses prettier to format all JavaScript code.\n` + ) + chalk.dim(` Please run `) + chalk.reset('yarn prettier') + chalk.dim(` and add changes to files listed above to your commit.`) + diff --git a/yarn.lock b/yarn.lock index 30fa2987e3c3..bf6ebf1c9e31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3199,9 +3199,9 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.3.0.tgz#cb02314f1ae2a99e951c17acb77a4096a1060ac2" +prettier@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.3.1.tgz#fa0ea84b45ac0ba6de6a1e4cecdcff900d563151" dependencies: ast-types "0.9.8" babel-code-frame "6.22.0"