From 2f5380a58a0ecad4950fc4d1f01e36dc9a38b5c0 Mon Sep 17 00:00:00 2001 From: Mihail Bodrov Date: Wed, 10 Jul 2019 01:06:54 +0300 Subject: [PATCH] Add mini test for checking clearCache emit --- packages/jest-core/package.json | 2 +- .../jest-core/src/__tests__/watch.test.js | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) 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..1481aa2457cb 100644 --- a/packages/jest-core/src/__tests__/watch.test.js +++ b/packages/jest-core/src/__tests__/watch.test.js @@ -11,6 +11,7 @@ import chalk from 'chalk'; import TestWatcher from '../TestWatcher'; import {JestHook, KEYS} from 'jest-watcher'; +import EventEmmiter from 'events'; const runJestMock = jest.fn(); const watchPluginPath = `${__dirname}/__fixtures__/watch_plugin`; @@ -109,6 +110,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 +581,55 @@ describe('Watch mode flows', () => { }); }); + describe('check clear cache modules', () => { + let Resolver; + let originalClearCache; + + beforeEach(() => { + Resolver = require('jest-resolve'); + originalClearCache = Resolver.clearCache; + }); + + afterEach(() => { + Resolver.clearCache = originalClearCache; + }); + + it('should correct require new files without legacy cache', async () => { + const fileTargetPath = `${__dirname}/__fixtures__/hey.test.js`; + const hasteMapInstance = new EventEmmiter(); + + await watch( + { + ...globalConfig, + rootDir: __dirname, + watchPlugins: [], + }, + contexts, + pipe, + [hasteMapInstance], + stdin, + ); + + Resolver.clearCache = jest.fn(); + + hasteMapInstance.emit('change', { + eventsQueue: [ + { + filePath: fileTargetPath, + stat: {}, + type: 'add', + }, + ], + hasteFS: { + _rootDir: __dirname, + }, + moduleMap: {}, + }); + + expect(Resolver.clearCache).toHaveBeenCalledTimes(1); + }); + }); + it('makes watch plugin initialization errors look nice', async () => { const pluginPath = `${__dirname}/__fixtures__/watch_plugin_throws`;