diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index a63d9f48fb08..60bf1868942f 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -19,7 +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": "^24.8.0", "jest-resolve-dependencies": "^24.8.0", "jest-runner": "^24.8.0", "jest-runtime": "^24.8.0", diff --git a/packages/jest-core/src/__tests__/watch.test.js b/packages/jest-core/src/__tests__/watch.test.js index 358446807c64..290490f79b1e 100644 --- a/packages/jest-core/src/__tests__/watch.test.js +++ b/packages/jest-core/src/__tests__/watch.test.js @@ -11,6 +11,8 @@ import chalk from 'chalk'; import TestWatcher from '../TestWatcher'; import {JestHook, KEYS} from 'jest-watcher'; +import HasteMap from 'jest-haste-map'; +import fs from 'fs'; const runJestMock = jest.fn(); const watchPluginPath = `${__dirname}/__fixtures__/watch_plugin`; @@ -109,6 +111,10 @@ describe('Watch mode flows', () => { jest.doMock('jest-util/build/isInteractive', () => isInteractive); watch = require('../watch').default; const config = { + haste: { + defaultPlatform: 'android', + }, + moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'], rootDir: __dirname, roots: [], testPathIgnorePatterns: [], @@ -576,6 +582,64 @@ describe('Watch mode flows', () => { }); }); + describe('check clear cache modules', () => { + const fileTargetPath = `${__dirname}/__fixtures__/hey.test.js`; + let hasteMapInstance; + let Resolver; + let originalClearCache; + + beforeEach(() => { + Resolver = require('jest-resolve'); + originalClearCache = Resolver.clearCache; + }); + + afterEach(() => { + Resolver.clearCache = originalClearCache; + hasteMapInstance.end(); + try { + fs.unlinkSync(fileTargetPath); + } catch (e) {} + }); + + it('should correct require new files without legacy cache', async () => { + hasteMapInstance = new HasteMap({ + computeSha1: false, + extensions: ['js'], + forceNodeFilesystemAPI: false, + maxWorkers: 2, + name: 'tmp_' + Date.now(), + platforms: [], + retainAllFiles: true, + rootDir: __dirname, + roots: [__dirname], + throwOnModuleCollision: true, + useWatchman: true, + watch: true, + }); + + await hasteMapInstance.build(); + + await watch( + { + ...globalConfig, + rootDir: __dirname, + watchPlugins: [], + }, + contexts, + pipe, + [hasteMapInstance], + stdin, + ); + + Resolver.clearCache = jest.fn(); + + fs.writeFileSync(fileTargetPath, '', {encoding: 'utf-8'}); + + await new Promise(resolve => setTimeout(resolve, 100)); + expect(Resolver.clearCache).toHaveBeenCalledTimes(1); + }); + }); + it('makes watch plugin initialization errors look nice', async () => { const pluginPath = `${__dirname}/__fixtures__/watch_plugin_throws`;