Skip to content

Commit

Permalink
Add failing e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Nov 9, 2018
1 parent b44e7f2 commit d4712c4
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
27 changes: 27 additions & 0 deletions e2e/__tests__/__snapshots__/watch_mode_no_access.test.js.snap
Original file line number Diff line number Diff line change
@@ -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: <<REPLACED>>
Ran all test suites.",
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.",
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.",
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
",
]
`;
76 changes: 76 additions & 0 deletions e2e/__tests__/watch_mode_no_access.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
4 changes: 2 additions & 2 deletions e2e/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
}),
);
Expand Down

0 comments on commit d4712c4

Please sign in to comment.