Skip to content

Commit a392eb2

Browse files
authored
Minor fixes for jest-runtime. (#1202)
1 parent a737c6e commit a392eb2

File tree

8 files changed

+45
-33
lines changed

8 files changed

+45
-33
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lerna": "2.0.0-beta.20",
3-
"version": "12.1.3",
3+
"version": "12.1.4",
44
"linkedFiles": {
55
"prefix": "/**\n * @flow\n */\n"
66
}

packages/jest-cli/src/Test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ class Test {
4545
process.stderr,
4646
);
4747
env.testFilePath = path;
48-
const moduleLoader = new ModuleLoader(config, env, resolver);
49-
if (config.setupFiles.length) {
50-
for (let i = 0; i < config.setupFiles.length; i++) {
51-
moduleLoader.requireModule(config.setupFiles[i]);
52-
}
53-
}
54-
48+
const runtime = new ModuleLoader(config, env, resolver);
5549
const start = Date.now();
56-
return TestRunner(config, env, moduleLoader, path)
50+
return TestRunner(config, env, runtime, path)
5751
.then(result => {
5852
result.perfStats = {start, end: Date.now()};
5953
result.testFilePath = path;
60-
result.coverage = moduleLoader.getAllCoverageInfo();
54+
result.coverage = runtime.getAllCoverageInfo();
6155
return result;
6256
})
6357
.then(

packages/jest-repl/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"license": "BSD-3-Clause",
99
"main": "build/index.js",
1010
"dependencies": {
11-
"chalk": "^1.1.1",
1211
"jest-runtime": "^12.1.0",
1312
"jest-util": "^12.1.0",
1413
"repl": "^0.1.3",

packages/jest-repl/src/cli/args.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010

1111
'use strict';
1212

13+
const Runtime = require('jest-runtime');
14+
1315
const wrap = require('jest-util').wrap;
1416

1517
const usage = 'Usage: $0 [--config=<pathToConfigFile>] [TestPathRegExp]';
1618

17-
const options = {
18-
config: {
19-
alias: 'c',
20-
description: wrap('The path to a Jest config file.'),
21-
type: 'string',
22-
},
19+
const options = Object.assign({}, Runtime.getCLIOptions(), {
2320
replname: {
2421
alias: 'r',
2522
description: wrap(
@@ -28,12 +25,7 @@ const options = {
2825
),
2926
type: 'string',
3027
},
31-
version: {
32-
alias: 'v',
33-
description: wrap('Print the version and exit'),
34-
type: 'boolean',
35-
},
36-
};
28+
});
3729

3830
module.exports = {
3931
options,

packages/jest-repl/src/cli/repl.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ declare var jest: Object;
1616

1717
jest.disableAutomock();
1818

19-
const chalk = require('chalk');
2019
const path = require('path');
2120
const repl = require('repl');
2221
const vm = require('vm');
@@ -64,7 +63,7 @@ if (jestConfig.scriptPreprocessor) {
6463
}
6564

6665
const replInstance = repl.start({
67-
prompt: chalk.green('\u203A') + ' ',
66+
prompt: '\u203A ',
6867
useGlobal: true,
6968
eval: evalCommand,
7069
});

packages/jest-runtime/src/cli/args.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const wrap = require('jest-util').wrap;
1515
const usage = 'Usage: $0 [--config=<pathToConfigFile>] [TestPathRegExp]';
1616

1717
const options = {
18+
cache: {
19+
default: true,
20+
description: wrap(
21+
'Whether to use the preprocessor cache. Disable the cache using ' +
22+
'--no-cache.',
23+
),
24+
type: 'boolean',
25+
},
1826
config: {
1927
alias: 'c',
2028
description: wrap('The path to a Jest config file.'),
@@ -25,6 +33,14 @@ const options = {
2533
description: wrap('Print the version and exit'),
2634
type: 'boolean',
2735
},
36+
watchman: {
37+
default: true,
38+
description: wrap(
39+
'Whether to use watchman for file crawling. Disable using ' +
40+
'--no-watchman.',
41+
),
42+
type: 'boolean',
43+
},
2844
};
2945

3046
module.exports = {

packages/jest-runtime/src/cli/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
const args = require('./args');
14+
const os = require('os');
1415
const path = require('path');
1516
const yargs = require('yargs');
1617

@@ -54,13 +55,14 @@ function run(cliArgv?: Object, cliInfo?: Array<string>) {
5455

5556
const root = getPackageRoot();
5657
const testFilePath = path.resolve(process.cwd(), argv._[0]);
57-
const info = cliInfo ? cliInfo.join(', ') : '';
58-
59-
console.log(`Using Jest Runtime v${VERSION}, ${info}`);
58+
const info = cliInfo ? ', ' + cliInfo.join(', ') : '';
6059

60+
console.log(`Using Jest Runtime v${VERSION}${info}`);
6161
readConfig(argv, root)
6262
.then(config => {
63-
Runtime.buildHasteMap(config, {maxWorkers: 1})
63+
Runtime.buildHasteMap(config, {
64+
maxWorkers: os.cpus().length - 1,
65+
})
6466
.then(hasteMap => {
6567
/* $FlowFixMe */
6668
const TestEnvironment = require(config.testEnvironment);
@@ -69,8 +71,8 @@ function run(cliArgv?: Object, cliInfo?: Array<string>) {
6971
env.global.console = new Console(process.stdout, process.stderr);
7072
env.global.jestConfig = config;
7173

72-
const moduleLoader = new Runtime(config, env, hasteMap.resolver);
73-
moduleLoader.requireModule(testFilePath);
74+
const runtime = new Runtime(config, env, hasteMap.resolver);
75+
runtime.requireModule(testFilePath);
7476
})
7577
.catch(e => {
7678
console.error(e);

packages/jest-runtime/src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,22 @@ class Runtime {
116116
config.setupFiles.forEach(unmockPath);
117117

118118
this.resetModuleRegistry();
119+
120+
if (config.setupFiles.length) {
121+
for (let i = 0; i < config.setupFiles.length; i++) {
122+
this.requireModule(config.setupFiles[i]);
123+
}
124+
}
119125
}
120126

121127
static buildHasteMap(
122128
config: Config,
123-
options: BuildHasteMapOptions,
129+
options: {maxWorkers: number},
124130
): Promise<HasteResolverContext> {
125131
utils.createDirectory(config.cacheDirectory);
126132
const instance = createHasteMap(config, {
127-
resetCache: !config.cache,
128133
maxWorkers: options.maxWorkers,
134+
resetCache: !config.cache,
129135
});
130136
return instance.build().then(
131137
moduleMap => ({
@@ -143,6 +149,10 @@ class Runtime {
143149
return require('./cli').run(args, info);
144150
}
145151

152+
static getCLIOptions() {
153+
return require('./cli/args').options;
154+
}
155+
146156
requireModule(from: Path, moduleName?: string) {
147157
const moduleID = this._getNormalizedModuleID(from, moduleName);
148158
let modulePath;

0 commit comments

Comments
 (0)