Skip to content

Commit

Permalink
Fix infinity llop in watch mode 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Jul 12, 2019
1 parent 17a35a5 commit a560aa0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/jest-core/src/__tests__/watch-file-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,35 @@ describe('Watch mode flows with changed files', () => {
let watch: any;
let pipe: NodeJS.ReadStream;
let stdin: MockStdin;
const fileTargetPath = path.resolve(__dirname, 'lost-file.js');
const fileTargetPath2 = path.resolve(__dirname, 'watch-test-fake.test.js');
const testDirectory = path.resolve(os.tmpdir(), 'jest-tmp');
const fileTargetPath = path.resolve(testDirectory, 'lost-file.js');
const fileTargetPath2 = path.resolve(
testDirectory,
'watch-test-fake.test.js',
);
const cacheDirectory = path.resolve(os.tmpdir(), `tmp${Math.random()}`);
let hasteMapInstance: HasteMap;

beforeEach(() => {
watch = require('../watch').default;
pipe = {write: jest.fn()} as any;
stdin = new MockStdin();
fs.mkdirSync(testDirectory);
fs.mkdirSync(cacheDirectory);
});

afterEach(() => {
jest.resetModules();
hasteMapInstance.end();
if (hasteMapInstance) {
hasteMapInstance.end();
}
[fileTargetPath2, fileTargetPath].forEach(file => {
try {
fs.unlinkSync(file);
} catch (e) {}
});
rimraf.sync(cacheDirectory);
rimraf.sync(testDirectory);
});

it('should correct require new files without legacy cache', async () => {
Expand Down Expand Up @@ -71,8 +79,8 @@ describe('Watch mode flows with changed files', () => {
moduleDirectories: ['node_modules'],
onlyChanged: false,
reporters: [],
rootDir: __dirname,
roots: [__dirname],
rootDir: testDirectory,
roots: [testDirectory],
silent: true,
testRegex: ['watch-test-fake\\.test\\.js$'],
watch: false,
Expand Down

0 comments on commit a560aa0

Please sign in to comment.