Skip to content

Commit

Permalink
fix: break dependency cycle in jest-cli (jestjs#7707)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and captain-yossarian committed Jul 18, 2019
1 parent a170ee9 commit 75b2fbe
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
@@ -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
@@ -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
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
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
@@ -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;
}

0 comments on commit 75b2fbe

Please sign in to comment.