Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: break dependency cycle in jest-cli #7707

Merged
merged 2 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-cli]` Break dependency cycle when using Jest programmatically ([#7707](https://github.com/facebook/jest/pull/7707)

### Chore & Maintenance

- `[website]` Fix broken help link on homepage ([#7706](https://github.com/facebook/jest/pull/7706))
Expand Down
19 changes: 19 additions & 0 deletions e2e/__tests__/runProgramatically.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. 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.
*
* @flow
*/

import {resolve} from 'path';

import {run} from '../Utils';

const dir = resolve(__dirname, '..', 'run-programatically');

test('run Jest programatically', () => {
const {stdout} = run(`node index.js --version`, dir);
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
});
13 changes: 13 additions & 0 deletions e2e/run-programatically/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
/**
* Copyright (c) Facebook, Inc. and its affiliates. 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.
*
* @flow
*/

// Running Jest like this is not officially supported,
// but it is common practice until there is a proper API as a substitute.
require('jest').run(process.argv);
3 changes: 1 addition & 2 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import rimraf from 'rimraf';
import {sync as realpath} from 'realpath-native';
import init from '../lib/init';
import logDebugMessages from '../lib/log_debug_messages';

const {getVersion} = require('../jest');
import getVersion from '../version';

export async function run(maybeArgv?: Argv, project?: Path) {
try {
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-cli/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
* @flow
*/

import {version as VERSION} from '../package.json';

import SearchSource from './SearchSource';
import TestScheduler from './TestScheduler';
import TestWatcher from './TestWatcher';
import {run, runCLI} from './cli';
import getVersion from './version';

module.exports = {
SearchSource,
TestScheduler,
TestWatcher,
getVersion: () => VERSION,
getVersion,
run,
runCLI,
};
14 changes: 14 additions & 0 deletions packages/jest-cli/src/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. 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.
*
* @flow
*/

import {version as VERSION} from '../package.json';

export default function getVersion() {
return VERSION;
}