-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
run.test.js
99 lines (87 loc) · 2.33 KB
/
run.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* 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.
*
*/
'use strict';
import path from 'path';
import {run} from '../../cli';
const runProject = path.join(__dirname, '../__fixtures__/run');
jest.mock('exit');
const runArgvString = [
'--config',
JSON.stringify({
rootDir: runProject,
testMatch: ['<rootDir>/*_spec.js'],
transform: {
'^.+\\.jsx?$': './transform-module',
},
}),
];
const runArgvObject = [
'--config',
{
rootDir: runProject,
testMatch: ['<rootDir>/*_spec.js'],
transform: {
'^.+\\.jsx?$': './transform-module',
},
},
];
const processOnFn = process.on;
const processExitFn = process.exit;
const processErrWriteFn = process.stderr.write;
const consoleErrorFn = console.error;
const noSubTestLogs = true;
describe('run', () => {
beforeEach(() => {
process.on = jest.fn();
process.on.mockReset();
process.exit = jest.fn();
process.exit.mockReset();
if (noSubTestLogs) {
process.stderr.write = jest.fn();
process.stderr.write.mockReset();
console.error = jest.fn();
console.error.mockReset();
}
});
afterEach(() => {
process.on = processOnFn;
process.exit = processExitFn;
if (noSubTestLogs) {
process.stderr.write = processErrWriteFn;
console.error = consoleErrorFn;
}
});
describe('config as string', () => {
it('passes the test when the config has a transform module path', async () => {
let runResult = null;
let error = null;
try {
runResult = await run(runArgvString, runProject);
} catch (ex) {
error = ex;
}
const numPassedTests = runResult ? runResult.numPassedTests : -1;
expect(error).toBe(null);
expect(numPassedTests).toBe(1);
});
});
describe('config as object', () => {
it('throws running the test when the config is an object', async () => {
let runResult = null;
let error = null;
try {
runResult = await run(runArgvObject, runProject);
} catch (ex) {
error = ex;
}
const numPassedTests = runResult ? runResult.numPassedTests : -1;
expect(error).not.toBe(null);
expect(numPassedTests).toBe(-1);
});
});
});