Skip to content

Commit

Permalink
Fix code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklas Gummesson committed May 29, 2018
1 parent cfe364b commit 2786bfd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
25 changes: 7 additions & 18 deletions e2e/__tests__/snapshot_resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -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.
"<bold>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.
"<bold>Custom snapshot resolver must implement a \`resolveTestPath\` function.</>
Documentation: https://facebook.github.io/jest/docs/en/configuration.html#snapshotResolver"
`;
7 changes: 5 additions & 2 deletions packages/jest-snapshot/src/snapshot_resolver.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'
);
}

0 comments on commit 2786bfd

Please sign in to comment.