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 f404fbd
Show file tree
Hide file tree
Showing 2 changed files with 65 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
64 changes: 64 additions & 0 deletions packages/jest-core/src/__tests__/watch.test.js
Expand Up @@ -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`;
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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`;

Expand Down

0 comments on commit f404fbd

Please sign in to comment.