-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Expand file tree
/
Copy pathexecute-tests-once-in-mpr.js
More file actions
65 lines (50 loc) · 1.88 KB
/
execute-tests-once-in-mpr.js
File metadata and controls
65 lines (50 loc) · 1.88 KB
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
/**
* Copyright (c) 2017-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';
const path = require('path');
const skipOnWindows = require('../../scripts/skip_on_windows');
const {extractSummary, cleanup, writeFiles} = require('../utils');
const runJest = require('../runJest');
const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr');
skipOnWindows.suite();
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
test('Tests are executed only once even in an MPR', () => {
// Make a global config that ignores all sub-projects.
const config = {
jest: {
projects: ['<rootDir>/foo/*/'],
testPathIgnorePatterns: ['/foo/'],
},
};
// Make a child config with a special regexp to ensure we execute the tests.
const childConfig = {
jest: {
testRegex: /my-test-.*\.js/.source,
},
};
/* eslint-disable sort-keys */
writeFiles(DIR, {
'foo/folder/my-test-bar.js': `test('bar', () => console.log('Bar!'));`,
'foo/folder/package.json': JSON.stringify(childConfig, null, 2),
'foo/directory/my-test-baz.js': `test('baz', () => console.log('Baz!'));`,
'foo/directory/package.json': JSON.stringify(childConfig, null, 2),
'foo/whatever/my-test-qux.js': `test('qux', () => console.log('Qux!'));`,
'foo/whatever/package.json': JSON.stringify(childConfig, null, 2),
'package.json': JSON.stringify(config, null, 2),
});
/* eslint-enable sort-keys */
const {stderr, status} = runJest(DIR, ['foo/folder/my-test-bar.js']);
expect(status).toBe(0);
const {rest, summary} = extractSummary(stderr);
// We have only one test passed, so total should equal to one, despite we have
// three projects.
expect(rest).toMatchSnapshot();
expect(summary).toMatch(/1 total/);
});