Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Treat snapshots as related to test files #3025

Merged
merged 1 commit into from
Mar 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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