Skip to content

Commit

Permalink
Treat snapshots as related to test files (jestjs#3025)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and cpojer committed Mar 1, 2017
1 parent a1c5ccf commit 324c3af
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/jest-resolve-dependencies/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import type {Resolver, ResolveModuleConfig} from 'types/Resolve';

const fileExists = require('jest-file-exists');

const isSnapshotPath = (path: string): boolean =>
!!path.match(/\/__snapshots__\//);

function compact(array: Array<?Path>): Array<Path> {
const result = [];
for (let i = 0; i < array.length; ++i) {
Expand Down Expand Up @@ -91,9 +94,14 @@ class DependencyResolver {
if (fileExists(path, this._hasteFS)) {
const module = this._hasteFS.exists(path);
if (module) {
changed.add(path);
if (filter(path)) {
relatedPaths.add(path);
// /path/to/__snapshots__/test.js.snap is always adjacent to
// /path/to/test.js
const modulePath = isSnapshotPath(path)
? path.replace(/__snapshots__\/(.*)\.snap/, '$1')
: path;
changed.add(modulePath);
if (filter(modulePath)) {
relatedPaths.add(modulePath);
}
}
}
Expand Down

0 comments on commit 324c3af

Please sign in to comment.