From d4712c43061bf7fb6655fa5a8c66d5f0ab683cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 9 Nov 2018 00:49:54 +0000 Subject: [PATCH] Add failing e2e test --- .../watch_mode_no_access.test.js.snap | 27 +++++++ e2e/__tests__/watch_mode_no_access.test.js | 76 +++++++++++++++++++ e2e/runJest.js | 4 +- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 e2e/__tests__/__snapshots__/watch_mode_no_access.test.js.snap create mode 100644 e2e/__tests__/watch_mode_no_access.test.js diff --git a/e2e/__tests__/__snapshots__/watch_mode_no_access.test.js.snap b/e2e/__tests__/__snapshots__/watch_mode_no_access.test.js.snap new file mode 100644 index 000000000000..c6dcf0705d5b --- /dev/null +++ b/e2e/__tests__/__snapshots__/watch_mode_no_access.test.js.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`does not re-run tests when only access time is modified 1`] = ` +Array [ + "Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites.", + "Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites.", + "Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites.", + "Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +", +] +`; diff --git a/e2e/__tests__/watch_mode_no_access.test.js b/e2e/__tests__/watch_mode_no_access.test.js new file mode 100644 index 000000000000..6661d7761f72 --- /dev/null +++ b/e2e/__tests__/watch_mode_no_access.test.js @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +import fs from 'fs'; +import os from 'os'; +import path from 'path'; +import {cleanup, extractSummaries, writeFiles} from '../Utils'; +import {until as runJestUntil} from '../runJest'; + +const DIR = path.resolve(os.tmpdir(), 'watch_mode_no_access'); + +const sleep = time => new Promise(resolve => setTimeout(resolve, time)); + +beforeEach(() => cleanup(DIR)); +afterAll(() => cleanup(DIR)); + +const setupFiles = () => { + writeFiles(DIR, { + '__tests__/foo.spec.js': ` + const foo = require('../foo'); + test('foo', () => { expect(typeof foo).toBe('number'); }); + `, + 'foo.js': ` + module.exports = 0; + `, + 'package.json': JSON.stringify({ + jest: {}, + }), + }); +}; + +test('does not re-run tests when only access time is modified', async () => { + setupFiles(); + + const testRun = runJestUntil(DIR, ['--watchAll', '--no-watchman'], '1 failed, 1 total'); + + await sleep(1000); + + // Should re-run the test + const modulePath = path.join(DIR, 'foo.js'); + const stat = fs.lstatSync(modulePath); + fs.utimesSync(modulePath, stat.atime, stat.mtime); + + await sleep(1000); + + // Should not re-run the test + const fakeATime = 1541723621; + fs.utimesSync(modulePath, fakeATime, stat.mtime); + + await sleep(1000); + + // Should re-run the test + fs.writeFileSync(modulePath, 'module.exports = 1;', {encoding: 'utf-8'}); + + await sleep(1000); + + // Should make the test fail and finish the process + fs.writeFileSync(modulePath, 'module.exports = undefined;', { + encoding: 'utf-8', + }); + + const {stderr} = await testRun; + const results = extractSummaries(stderr); + + // initial YES, mtime YES, atime NO, mtime YES, fail YES + expect(results).toHaveLength(4); + expect(results.map(result => result.summary)).toMatchSnapshot(); +}); diff --git a/e2e/runJest.js b/e2e/runJest.js index dca157aebbd1..a71be7ecb8bf 100644 --- a/e2e/runJest.js +++ b/e2e/runJest.js @@ -133,11 +133,11 @@ export const until = async function( write(chunk, encoding, callback) { const output = chunk.toString('utf8'); + callback(); + if (output.includes(text)) { jestPromise.kill(); } - - callback(); }, }), );