Skip to content

Commit

Permalink
Use prettier 1.3.1 (#3460)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and cpojer committed May 4, 2017
1 parent ac8811c commit bb72d06
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 72 deletions.
28 changes: 19 additions & 9 deletions integration_tests/__tests__/toMatchSnapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'])});
Expand Down Expand Up @@ -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"}'])});
Expand All @@ -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'`])});
Expand All @@ -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'])});
Expand All @@ -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()});
Expand Down
24 changes: 16 additions & 8 deletions integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()});
Expand All @@ -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()});
Expand All @@ -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()});
Expand All @@ -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()});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand All @@ -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(
Expand Down
17 changes: 11 additions & 6 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand All @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-cli/src/reporters/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down
16 changes: 11 additions & 5 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions packages/jest-config/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}

Expand Down Expand Up @@ -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 */
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
});
});
});
3 changes: 2 additions & 1 deletion packages/jest-snapshot/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions packages/jest-validate/src/__tests__/fixtures/jestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand All @@ -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:
{
Expand Down
Loading

0 comments on commit bb72d06

Please sign in to comment.