/
watch_mode_no_access.test.js
80 lines (62 loc) · 1.95 KB
/
watch_mode_no_access.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* 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();
});