Skip to content

Commit

Permalink
fix: break dependency cycle in jest-cli (#7707)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Jan 26, 2019
1 parent f2fb112 commit 88713fc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
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;
}

0 comments on commit 88713fc

Please sign in to comment.