Skip to content

Commit f5c0d8f

Browse files
committed
Move jest-runtime CLI into jest-repl
Fixes #10011
1 parent dbb1290 commit f5c0d8f

File tree

20 files changed

+194
-124
lines changed

20 files changed

+194
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921))
2323
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
2424
- `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688))
25+
- `[jest-repl, jest-runtime]` [**BREAKING**] Move the `jest-runtime` CLI into `jest-repl` ([#10016](https://github.com/facebook/jest/pull/10016))
2526

2627
### Performance
2728

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
'/packages/jest-haste-map/src/__tests__/haste_impl.js',
5151
'/packages/jest-haste-map/src/__tests__/dependencyExtractor.js',
5252
'/packages/jest-haste-map/src/__tests__/test_dotfiles_root/',
53+
'/packages/jest-repl/src/__tests__/test_root',
5354
'/packages/jest-resolve-dependencies/src/__tests__/__fixtures__/',
5455
'/packages/jest-runtime/src/__tests__/defaultResolver.js',
5556
'/packages/jest-runtime/src/__tests__/module_dir/',

packages/jest-core/src/__tests__/SearchSource.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,12 @@ describe('SearchSource', () => {
451451
it('finds tests that depend directly on the path', () => {
452452
const filePath = path.join(rootDir, 'RegularModule.js');
453453
const file2Path = path.join(rootDir, 'RequireRegularModule.js');
454-
const loggingDep = path.join(rootDir, 'logging.js');
455454
const parentDep = path.join(rootDir, 'ModuleWithSideEffects.js');
456455
const data = searchSource.findRelatedTests(new Set([filePath]), false);
457456
expect(toPaths(data.tests).sort()).toEqual([
458457
parentDep,
459458
filePath,
460459
file2Path,
461-
loggingDep,
462460
rootPath,
463461
]);
464462
});

packages/jest-runtime/bin/jest-runtime.js renamed to packages/jest-repl/bin/jest-runtime-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ if (process.env.NODE_ENV == null) {
1010
process.env.NODE_ENV = 'test';
1111
}
1212

13-
require('../build/cli').run();
13+
require('../build/cli/runtime-cli').run();

packages/jest-repl/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
"./bin/jest-repl": "./bin/jest-repl.js"
1616
},
1717
"dependencies": {
18+
"@jest/console": "^26.6.2",
19+
"@jest/environment": "^26.6.2",
1820
"@jest/transform": "^26.6.2",
1921
"@jest/types": "^26.6.2",
22+
"chalk": "^4.0.0",
2023
"jest-config": "^26.6.3",
2124
"jest-runtime": "^26.6.3",
25+
"jest-util": "^26.6.2",
2226
"jest-validate": "^26.6.2",
2327
"repl": "^0.1.3",
2428
"yargs": "^16.0.3"
2529
},
2630
"devDependencies": {
2731
"@jest/test-utils": "^26.6.2",
28-
"@types/yargs": "^15.0.0"
32+
"@types/yargs": "^15.0.0",
33+
"execa": "^4.0.0"
2934
},
3035
"bin": "./bin/jest-repl.js",
3136
"engines": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import path from 'path';
9+
import {sync as spawnSync} from 'execa';
10+
11+
const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-runtime-cli.js');
12+
13+
const run = args =>
14+
spawnSync(JEST_RUNTIME, args, {
15+
cwd: process.cwd(),
16+
env: process.env,
17+
reject: false,
18+
});
19+
20+
describe('Runtime CLI', () => {
21+
it('fails with no path', () => {
22+
const expectedOutput =
23+
'Please provide a path to a script. (See --help for details)';
24+
expect(run([]).stdout).toBe(expectedOutput);
25+
});
26+
27+
it('displays script output', () => {
28+
const scriptPath = path.resolve(__dirname, './test_root/logging.js');
29+
expect(run([scriptPath, '--no-cache']).stdout).toMatch('Hello, world!');
30+
});
31+
32+
it('always disables automocking', () => {
33+
const scriptPath = path.resolve(__dirname, './test_root/logging.js');
34+
const output = run([
35+
scriptPath,
36+
'--no-cache',
37+
'--config=' +
38+
JSON.stringify({
39+
automock: true,
40+
}),
41+
]);
42+
expect(output.stdout).toMatch('Hello, world!');
43+
});
44+
45+
it('throws script errors', () => {
46+
const scriptPath = path.resolve(__dirname, './test_root/throwing.js');
47+
expect(run([scriptPath, '--no-cache']).stderr).toMatch('Error: throwing');
48+
});
49+
});

packages/jest-runtime/src/__tests__/test_root/logging.js renamed to packages/jest-repl/src/__tests__/test_root/logging.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
'use strict';
99

10-
if (require('./RegularModule').getModuleStateValue()) {
10+
if (
11+
require('jest-runtime/src/__tests__/test_root/RegularModule').getModuleStateValue()
12+
) {
1113
console.log('Hello, world!');
1214
} else {
1315
console.log('Automocking is not properly disabled in jest-runtime.');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
throw new Error('throwing');

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,45 @@
77
*/
88

99
import type {Options} from 'yargs';
10-
import Runtime from 'jest-runtime';
1110

1211
export const usage = 'Usage: $0 [--config=<pathToConfigFile>]';
1312

13+
const runtimeCLIOptions: Record<
14+
'cache' | 'config' | 'debug' | 'version' | 'watchman',
15+
Options
16+
> = {
17+
cache: {
18+
default: true,
19+
description:
20+
'Whether to use the preprocessor cache. Disable ' +
21+
'the cache using --no-cache.',
22+
type: 'boolean',
23+
},
24+
config: {
25+
alias: 'c',
26+
description: 'The path to a Jest config file.',
27+
type: 'string',
28+
},
29+
debug: {
30+
description: 'Print debugging info about your jest config.',
31+
type: 'boolean',
32+
},
33+
version: {
34+
alias: 'v',
35+
description: 'Print the version and exit',
36+
type: 'boolean',
37+
},
38+
watchman: {
39+
default: true,
40+
description:
41+
'Whether to use watchman for file crawling. Disable using ' +
42+
'--no-watchman.',
43+
type: 'boolean',
44+
},
45+
};
46+
1447
export const options: Record<string, Options> = {
15-
...Runtime.getCLIOptions(),
48+
...runtimeCLIOptions,
1649
replname: {
1750
alias: 'r',
1851
description:

packages/jest-repl/src/cli/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import yargs = require('yargs');
1111
import type {Config} from '@jest/types';
1212
import {deprecationEntries} from 'jest-config';
13-
import Runtime from 'jest-runtime';
1413
import {validateCLIOptions} from 'jest-validate';
1514
import * as args from './args';
16-
const {version: VERSION} = require('../../package.json');
15+
import {run as runtimeCLI} from './runtime-cli';
16+
import {VERSION} from './version';
1717

1818
const REPL_SCRIPT = require.resolve('./repl.js');
1919

@@ -24,5 +24,5 @@ export = function (): void {
2424

2525
argv._ = [REPL_SCRIPT];
2626

27-
Runtime.runCLI(argv, [`Jest REPL v${VERSION}`]);
27+
runtimeCLI(argv, [`Jest REPL v${VERSION}`]);
2828
};

0 commit comments

Comments
 (0)