Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed May 3, 2020
1 parent d997f2d commit 49b5d5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@

'use strict';

import fs from 'fs';
import os from 'os';
import path from 'path';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {cleanup, writeFiles} from '../Utils';
import {runContinuous} from '../runJest';

const DIR = path.resolve(os.tmpdir(), 'watch_mode_no_access');

const sleep = time => new Promise(resolve => setTimeout(resolve, time));
const sleep = (time: number) =>
new Promise(resolve => setTimeout(resolve, time));

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

const setupFiles = () => {
writeFiles(DIR, {
'__tests__/foo.spec.js': `
'__tests__/foo.test.js': `
const foo = require('../foo');
test('foo', () => { expect(typeof foo).toBe('number'); });
`,
Expand All @@ -37,7 +38,7 @@ const setupFiles = () => {
});
};

let testRun;
let testRun: ReturnType<typeof runContinuous>;

afterEach(async () => {
if (testRun) {
Expand All @@ -62,12 +63,13 @@ test('does not re-run tests when only access time is modified', async () => {
// Should re-run the test
const modulePath = path.join(DIR, 'foo.js');
const stat = fs.lstatSync(modulePath);
fs.utimesSync(modulePath, stat.atime, stat.mtime);
fs.utimesSync(modulePath, stat.atime.getTime(), stat.mtime.getTime());

await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 2);

// Should NOT re-run the test
const fakeATime = 1541723621;
fs.utimesSync(modulePath, fakeATime, stat.mtime);
fs.utimesSync(modulePath, fakeATime, stat.mtime.getTime());
await sleep(3000);
expect(numberOfTestRuns(testRun.getCurrentOutput().stderr)).toBe(2);

Expand Down
4 changes: 1 addition & 3 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,10 +851,8 @@ class HasteMap extends EventEmitter {

// The file has been accessed, not modified
if (
fileMetadata &&
type === 'change' &&
stat &&
fileMetadata[H.MTIME] === stat.mtime.getTime()
fileMetadata?.[H.MTIME] === stat?.mtime.getTime()
) {
return;
}
Expand Down

0 comments on commit 49b5d5d

Please sign in to comment.