forked from jestjs/jest
/
noTestsFound.test.ts
95 lines (81 loc) 路 2.92 KB
/
noTestsFound.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* 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 * as path from 'path';
import runJest from '../runJest';
const DIR = path.resolve(__dirname, '../no-tests-found-test');
describe('No tests are found', () => {
test('fails the test suite in standard situation', () => {
const {exitCode, stdout} = runJest(DIR, [
'--testPathPattern',
'/non/existing/path/',
]);
expect(stdout).toContain('No tests found, exiting with code 1');
expect(stdout).toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(1);
});
test("doesn't fail the test suite if --passWithNoTests passed", () => {
const {exitCode, stdout} = runJest(DIR, [
'--testPathPattern',
'/non/existing/path/',
'--passWithNoTests',
]);
expect(stdout).toContain('No tests found, exiting with code 0');
expect(stdout).not.toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(0);
});
test("doesn't fail the test suite if using --lastCommit", () => {
// Since there are no files in DIR no tests will be found
const {exitCode, stdout} = runJest(DIR, ['--lastCommit']);
expect(stdout).toContain(
'No tests found related to files changed since last commit.',
);
expect(stdout).not.toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(0);
});
test("doesn't fail the test suite if using --onlyChanged", () => {
// Since there are no files in DIR no tests will be found
const {exitCode, stdout} = runJest(DIR, ['--onlyChanged']);
expect(stdout).toContain(
'No tests found related to files changed since last commit.',
);
expect(stdout).not.toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(0);
});
test('fails the test suite if using --findRelatedTests', () => {
// Since there are no files in DIR no tests will be found
const {exitCode, stdout} = runJest(DIR, [
'--findRelatedTests',
'/non/existing/path',
]);
expect(stdout).toContain('No tests found, exiting with code 1');
expect(stdout).toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(1);
});
test("doesn't fail the test suite if using --findRelatedTests and --passWithNoTests", () => {
// Since there are no files in DIR no tests will be found
const {exitCode, stdout} = runJest(DIR, [
'--findRelatedTests',
'/non/existing/path',
'--passWithNoTests',
]);
expect(stdout).toContain('No tests found, exiting with code 0');
expect(stdout).not.toContain(
'Run with `--passWithNoTests` to exit with code 0',
);
expect(exitCode).toBe(0);
});
});