UNPKG

1.58 kBJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9/* eslint-env node */
10
11const {allowedJestOptions} = require('../build/jest/cli-options');
12const {TestAppRuntime} = require('../build/test-runtime');
13
14exports.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 // suggests this as a valid argument, we support it in case it's used.
27 u,
28 updateSnapshot,
29 collectCoverageFrom,
30 // Arguments which are passed through into jest
31 ...rest
32 } /*: any */
33) {
34 const jestArgs /*: any */ = {
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, // deprecated
55 testMatch,
56 testRegex,
57 configPath,
58 collectCoverageFrom,
59 jestArgs,
60 });
61
62 // $FlowFixMe
63 await testRuntime.run();
64
65 return {
66 stop() {
67 // $FlowFixMe
68 testRuntime.stop();
69 },
70 };
71};