From 2786bfd5cd71b27f9579848df7238ed0d6f01508 Mon Sep 17 00:00:00 2001 From: Nicklas Gummesson Date: Tue, 29 May 2018 10:05:30 -0700 Subject: [PATCH] Fix code review feedback --- e2e/__tests__/snapshot_resolver.test.js | 25 ++++++------------- .../snapshot_resolver.test.js.snap | 6 ++--- .../jest-snapshot/src/snapshot_resolver.js | 7 ++++-- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/e2e/__tests__/snapshot_resolver.test.js b/e2e/__tests__/snapshot_resolver.test.js index 27d239a0335b..36b9968a11b0 100644 --- a/e2e/__tests__/snapshot_resolver.test.js +++ b/e2e/__tests__/snapshot_resolver.test.js @@ -9,25 +9,16 @@ const runJest = require('../runJest'); const snapshotDir = path.resolve( __dirname, - path.join('..', 'snapshot-resolver', '__snapshots__'), + '../snapshot-resolver/__snapshots__' ); const snapshotFile = path.resolve(snapshotDir, 'snapshot.test.js.snap'); -const fileExists = filePath => { - try { - return fs.statSync(filePath).isFile(); - } catch (e) {} - return false; -}; - describe('Custom snapshot resolver', () => { const cleanup = () => { - [snapshotFile].forEach(file => { - if (fileExists(file)) { - fs.unlinkSync(file); - } - }); - if (fileExists(snapshotDir)) { + if (fs.existsSync(snapshotFile)) { + fs.unlinkSync(snapshotFile); + } + if (fs.existsSync(snapshotDir)) { fs.rmdirSync(snapshotDir); } }; @@ -39,12 +30,10 @@ describe('Custom snapshot resolver', () => { const result = runJest('snapshot-resolver', ['-w=1', '--ci=false']); const info = result.stderr.toString(); - expect(info).toMatch('1 snapshot written in 1 test suite'); + expect(info).toMatch('1 snapshot written from 1 test suite'); // $FlowFixMe dynamic require const content = require(snapshotFile); - expect(content['snapshots are written to custom location 1']).not.toBe( - undefined, - ); + expect(content['snapshots are written to custom location 1']).toBeDefined(); }); }); diff --git a/packages/jest-snapshot/src/__tests__/__snapshots__/snapshot_resolver.test.js.snap b/packages/jest-snapshot/src/__tests__/__snapshots__/snapshot_resolver.test.js.snap index b1bae49640e4..fd07ed326c17 100644 --- a/packages/jest-snapshot/src/__tests__/__snapshots__/snapshot_resolver.test.js.snap +++ b/packages/jest-snapshot/src/__tests__/__snapshots__/snapshot_resolver.test.js.snap @@ -1,13 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`malformed custom resolver in project config missing resolveSnapshotPath throws 1`] = ` -"Custom snapshot resolver must implement a \`resolveSnapshotPath\` function. - +"Custom snapshot resolver must implement a \`resolveSnapshotPath\` function. Documentation: https://facebook.github.io/jest/docs/en/configuration.html#snapshotResolver" `; exports[`malformed custom resolver in project config missing resolveTestPath throws 1`] = ` -"Custom snapshot resolver must implement a \`resolveTestPath\` function. - +"Custom snapshot resolver must implement a \`resolveTestPath\` function. Documentation: https://facebook.github.io/jest/docs/en/configuration.html#snapshotResolver" `; diff --git a/packages/jest-snapshot/src/snapshot_resolver.js b/packages/jest-snapshot/src/snapshot_resolver.js index a9258276fb4d..15a967d5bb4a 100644 --- a/packages/jest-snapshot/src/snapshot_resolver.js +++ b/packages/jest-snapshot/src/snapshot_resolver.js @@ -1,5 +1,6 @@ import type {ProjectConfig, Path} from 'types/Config'; import type {SnapshotResolver} from 'types/SnapshotResolver'; +import chalk from 'chalk'; import path from 'path'; export const EXTENSION = 'snap'; @@ -60,7 +61,9 @@ function createCustomSnapshotResolver( function mustImplement(functionName: string) { return ( - `Custom snapshot resolver must implement a \`${functionName}\` function.\n\n` + - 'Documentation: https://facebook.github.io/jest/docs/en/configuration.html#snapshotResolver' + chalk.bold( + `Custom snapshot resolver must implement a \`${functionName}\` function.`, + ) + + '\nDocumentation: https://facebook.github.io/jest/docs/en/configuration.html#snapshotResolver' ); }