Skip to content

Commit

Permalink
Add mini test for checking clearCache emit
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Jul 9, 2019
1 parent ab7f9e2 commit 2f5380a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/jest-core/package.json
Expand Up @@ -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",
Expand Down
54 changes: 54 additions & 0 deletions packages/jest-core/src/__tests__/watch.test.js
Expand Up @@ -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`;
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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`;

Expand Down

0 comments on commit 2f5380a

Please sign in to comment.