/
watchModeOnlyFailed.test.ts
49 lines (42 loc) · 1.43 KB
/
watchModeOnlyFailed.test.ts
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
/**
* Copyright (c) Facebook, Inc. and its affiliates. 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.
*/
import {tmpdir} from 'os';
import * as path from 'path';
import {cleanup, extractSummaries, writeFiles} from '../Utils';
import runJest from '../runJest';
const DIR = path.resolve(tmpdir(), 'watch-mode-only-failed');
const pluginPath = path.resolve(__dirname, '../MockStdinWatchPlugin');
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
const setupFiles = (input: Array<{keys: Array<string>}>) => {
writeFiles(DIR, {
'__tests__/bar.spec.js': `
test('bar 1', () => { expect('bar').toBe('foo'); });
`,
'__tests__/foo.spec.js': `
test('foo 1', () => { expect('foo').toBe('foo'); });
`,
'package.json': JSON.stringify({
jest: {
testEnvironment: 'node',
watchPlugins: [[pluginPath, {input}]],
},
}),
});
};
test('can press "f" to run only failed tests', () => {
const input = [{keys: ['f']}, {keys: ['q']}];
setupFiles(input);
const {exitCode, stderr} = runJest(DIR, ['--no-watchman', '--watchAll']);
const results = extractSummaries(stderr);
expect(results).toHaveLength(2);
results.forEach(({rest, summary}) => {
expect(rest).toMatchSnapshot('test results');
expect(summary).toMatchSnapshot('test summary');
});
expect(exitCode).toBe(0);
});