Skip to content

Commit

Permalink
Clear resolved modules cache before runJest in watch mode 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Jul 5, 2019
1 parent d051b0d commit debd2a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"jest-haste-map": "^24.8.0",
"jest-message-util": "^24.8.0",
"jest-regex-util": "^24.3.0",
"jest-resolve": "^24.3.0",
"jest-resolve-dependencies": "^24.8.0",
"jest-runner": "^24.8.0",
"jest-runtime": "^24.8.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {formatExecError} from 'jest-message-util';
import {isInteractive, preRunMessage, specialChars} from 'jest-util';
import {ValidationError} from 'jest-validate';
import {Context} from 'jest-runtime';
import Resolver from 'jest-resolve';
import {Config} from '@jest/types';
import {
AllowedConfigOptions,
Expand Down Expand Up @@ -275,6 +276,9 @@ export default function watch(
isRunning = true;
const configs = contexts.map(context => context.config);
const changedFilesPromise = getChangedFilesPromise(globalConfig, configs);
// Clear cache for required modules
Resolver.clearCache();

return runJest({
changedFilesPromise,
contexts,
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-resolve/src/defaultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default function defaultResolver(
});
}

export const clearResolverCache = () => {
checkedPaths.clear();
};

const REGEX_RELATIVE_IMPORT = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/;

function resolveSync(
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-resolve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {sync as realpath} from 'realpath-native';
import chalk from 'chalk';
import nodeModulesPaths from './nodeModulesPaths';
import isBuiltinModule from './isBuiltinModule';
import defaultResolver from './defaultResolver';
import defaultResolver, {clearResolverCache} from './defaultResolver';
import {ResolverConfig} from './types';

type FindNodeModuleConfig = {
Expand Down Expand Up @@ -79,6 +79,10 @@ class Resolver {
this._modulePathCache = new Map();
}

static clearCache() {
clearResolverCache();
}

static findNodeModule(
path: Config.Path,
options: FindNodeModuleConfig,
Expand Down

0 comments on commit debd2a8

Please sign in to comment.