Skip to content

Commit 9505866

Browse files
committed
Add failing e2e test
1 parent b44e7f2 commit 9505866

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`does not re-run tests when only access time is modified 1`] = `
4+
Array [
5+
"Test Suites: 1 passed, 1 total
6+
Tests: 1 passed, 1 total
7+
Snapshots: 0 total
8+
Time: <<REPLACED>>
9+
Ran all test suites.",
10+
"Test Suites: 1 passed, 1 total
11+
Tests: 1 passed, 1 total
12+
Snapshots: 0 total
13+
Time: <<REPLACED>>
14+
Ran all test suites.",
15+
"Test Suites: 1 passed, 1 total
16+
Tests: 1 passed, 1 total
17+
Snapshots: 0 total
18+
Time: <<REPLACED>>
19+
Ran all test suites.",
20+
"Test Suites: 1 failed, 1 total
21+
Tests: 1 failed, 1 total
22+
Snapshots: 0 total
23+
Time: <<REPLACED>>
24+
Ran all test suites.
25+
",
26+
]
27+
`;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
import fs from 'fs';
13+
import os from 'os';
14+
import path from 'path';
15+
import {cleanup, extractSummaries, writeFiles} from '../Utils';
16+
import {until as runJestUntil} from '../runJest';
17+
18+
const DIR = path.resolve(os.tmpdir(), 'watch_mode_no_access');
19+
20+
const sleep = time => new Promise(resolve => setTimeout(resolve, time));
21+
22+
beforeEach(() => cleanup(DIR));
23+
afterAll(() => cleanup(DIR));
24+
25+
const setupFiles = () => {
26+
writeFiles(DIR, {
27+
'__tests__/foo.spec.js': `
28+
const foo = require('../foo');
29+
test('foo', () => { expect(typeof foo).toBe('number'); });
30+
`,
31+
'foo.js': `
32+
module.exports = 0;
33+
`,
34+
'package.json': JSON.stringify({
35+
jest: {},
36+
}),
37+
});
38+
};
39+
40+
test('does not re-run tests when only access time is modified', async () => {
41+
setupFiles();
42+
43+
const testRun = runJestUntil(
44+
DIR,
45+
['--watchAll', '--no-watchman'],
46+
'1 failed, 1 total',
47+
);
48+
49+
await sleep(1000);
50+
51+
// Should re-run the test
52+
const modulePath = path.join(DIR, 'foo.js');
53+
const stat = fs.lstatSync(modulePath);
54+
fs.utimesSync(modulePath, stat.atime, stat.mtime);
55+
56+
await sleep(1000);
57+
58+
// Should not re-run the test
59+
const fakeATime = 1541723621;
60+
fs.utimesSync(modulePath, fakeATime, stat.mtime);
61+
62+
await sleep(1000);
63+
64+
// Should re-run the test
65+
fs.writeFileSync(modulePath, 'module.exports = 1;', {encoding: 'utf-8'});
66+
67+
await sleep(1000);
68+
69+
// Should make the test fail and finish the process
70+
fs.writeFileSync(modulePath, 'module.exports = undefined;', {
71+
encoding: 'utf-8',
72+
});
73+
74+
const {stderr} = await testRun;
75+
const results = extractSummaries(stderr);
76+
77+
// initial YES, mtime YES, atime NO, mtime YES, fail YES
78+
expect(results).toHaveLength(4);
79+
expect(results.map(result => result.summary)).toMatchSnapshot();
80+
});

e2e/runJest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ export const until = async function(
133133
write(chunk, encoding, callback) {
134134
const output = chunk.toString('utf8');
135135

136+
callback();
137+
136138
if (output.includes(text)) {
137139
jestPromise.kill();
138140
}
139-
140-
callback();
141141
},
142142
}),
143143
);

0 commit comments

Comments
 (0)