Skip to content

Commit

Permalink
chore: fix watch mode test with utimes (#9967)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 4, 2020
1 parent 68d12d5 commit 03dbb2f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions e2e/__tests__/watchModeNoAccess.test.ts
Expand Up @@ -9,13 +9,9 @@
import * as os from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {skipSuiteOnWindows} from '@jest/test-utils';
import {cleanup, writeFiles} from '../Utils';
import {runContinuous} from '../runJest';

// Until https://github.com/nodejs/node/issues/33227 is solved somehow
skipSuiteOnWindows();

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

const sleep = (time: number) =>
Expand Down Expand Up @@ -47,6 +43,8 @@ afterEach(async () => {
}
});

const getOneSecondAfterMs = (ms: number) => ms / 1000 + 1;

test('does not re-run tests when only access time is modified', async () => {
setupFiles();

Expand All @@ -64,13 +62,21 @@ 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.getTime(), stat.mtime.getTime());
fs.utimesSync(
modulePath,
getOneSecondAfterMs(stat.atimeMs),
getOneSecondAfterMs(stat.mtimeMs),
);

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

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

Expand Down

0 comments on commit 03dbb2f

Please sign in to comment.