From 49b5d5d467d42f6fb9b7167d1406f6e79ed0eaca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 3 May 2020 21:47:27 +0200 Subject: [PATCH] fix test --- ...ccess.test.js => watchModeNoAccess.test.ts} | 18 ++++++++++-------- packages/jest-haste-map/src/index.ts | 4 +--- 2 files changed, 11 insertions(+), 11 deletions(-) rename e2e/__tests__/{watch_mode_no_access.test.js => watchModeNoAccess.test.ts} (82%) diff --git a/e2e/__tests__/watch_mode_no_access.test.js b/e2e/__tests__/watchModeNoAccess.test.ts similarity index 82% rename from e2e/__tests__/watch_mode_no_access.test.js rename to e2e/__tests__/watchModeNoAccess.test.ts index 6d6a3038fe34..a198080a2780 100644 --- a/e2e/__tests__/watch_mode_no_access.test.js +++ b/e2e/__tests__/watchModeNoAccess.test.ts @@ -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'); }); `, @@ -37,7 +38,7 @@ const setupFiles = () => { }); }; -let testRun; +let testRun: ReturnType; afterEach(async () => { if (testRun) { @@ -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); diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 37ff65131ec5..b4f11edd99dd 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -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; }