Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix watch mode test with utimes #9967

Merged
merged 2 commits into from
May 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions e2e/__tests__/watchModeNoAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ 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 +44,8 @@ afterEach(async () => {
}
});

const getOneSecondAfterMs = (ms: number) => ms / 1000 + 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier won't allow me to do (ms / 1000) + 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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

Expand All @@ -64,13 +63,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