1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const {allowedJestOptions} = require('../build/jest/cli-options');
|
12 | const {TestAppRuntime} = require('../build/test-runtime');
|
13 |
|
14 | exports.run = async function(
|
15 | {
|
16 | dir = '.',
|
17 | debug,
|
18 | match,
|
19 | env,
|
20 | testFolder, // deprecated
|
21 | testMatch,
|
22 | testRegex,
|
23 | configPath,
|
24 | // Allow snapshots to be updated using `-u` as well as --updateSnapshot.
|
25 | // We don't document this argument, but since jest output automatically
|
26 |
|
27 | u,
|
28 | updateSnapshot,
|
29 | collectCoverageFrom,
|
30 |
|
31 | ...rest
|
32 | }
|
33 | ) {
|
34 | const jestArgs = {
|
35 | updateSnapshot: updateSnapshot || u || false,
|
36 | };
|
37 | allowedJestOptions.forEach(arg => {
|
38 | if (rest[arg]) {
|
39 | jestArgs[arg] = rest[arg];
|
40 | }
|
41 | });
|
42 |
|
43 | if ([testFolder, testMatch, testRegex].filter(t => t !== '').length > 1) {
|
44 | throw new Error(
|
45 | 'Only one of testMatch, testRegex and testFolder can be defined at one time'
|
46 | );
|
47 | }
|
48 |
|
49 | const testRuntime = new TestAppRuntime({
|
50 | dir,
|
51 | debug,
|
52 | match,
|
53 | env,
|
54 | testFolder,
|
55 | testMatch,
|
56 | testRegex,
|
57 | configPath,
|
58 | collectCoverageFrom,
|
59 | jestArgs,
|
60 | });
|
61 |
|
62 |
|
63 | await testRuntime.run();
|
64 |
|
65 | return {
|
66 | stop() {
|
67 |
|
68 | testRuntime.stop();
|
69 | },
|
70 | };
|
71 | };
|