Skip to content

Commit

Permalink
Add projects option, rename initial config to options. (#3400)
Browse files Browse the repository at this point in the history
* Add projects option, rename initial config to options.

* Add test
  • Loading branch information
cpojer authored May 2, 2017
1 parent 26a63f4 commit 909da52
Show file tree
Hide file tree
Showing 15 changed files with 1,323 additions and 223 deletions.
8 changes: 4 additions & 4 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {PathPattern} from './SearchSource';
import type {Test, Tests} from 'types/TestRunner';
import type {Test} from 'types/TestRunner';
import type BaseReporter from './reporters/BaseReporter';

const {formatExecError} = require('jest-message-util');
Expand Down Expand Up @@ -75,7 +75,7 @@ class TestRunner {
this._dispatcher.unregister(ReporterClass);
}

async runTests(tests: Tests, watcher: TestWatcher) {
async runTests(tests: Array<Test>, watcher: TestWatcher) {
const timings = [];
const contexts = new Set();
tests.forEach(test => {
Expand Down Expand Up @@ -183,7 +183,7 @@ class TestRunner {
}

_createInBandTestRun(
tests: Tests,
tests: Array<Test>,
watcher: TestWatcher,
onResult: OnTestSuccess,
onFailure: OnTestFailure,
Expand Down Expand Up @@ -214,7 +214,7 @@ class TestRunner {
}

_createParallelTestRun(
tests: Tests,
tests: Array<Test>,
watcher: TestWatcher,
onResult: OnTestSuccess,
onFailure: OnTestFailure,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/TestSequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import type {AggregatedResult} from 'types/TestResult';
import type {Context} from 'types/Context';
import type {Test, Tests} from 'types/TestRunner';
import type {Test} from 'types/TestRunner';

const fs = require('fs');
const getCacheFilePath = require('jest-haste-map').getCacheFilePath;
Expand Down Expand Up @@ -57,7 +57,7 @@ class TestSequencer {
// After a test run we store the time it took to run a test and on
// subsequent runs we use that to run the slowest tests first, yielding the
// fastest results.
sort(tests: Tests): Tests {
sort(tests: Array<Test>): Array<Test> {
const stats = {};
const fileSize = test =>
stats[test.path] || (stats[test.path] = fs.statSync(test.path).size);
Expand Down Expand Up @@ -85,7 +85,7 @@ class TestSequencer {
});
}

cacheResults(tests: Tests, results: AggregatedResult) {
cacheResults(tests: Array<Test>, results: AggregatedResult) {
const map = Object.create(null);
tests.forEach(test => (map[test.path] = test));
results.testResults.forEach(testResult => {
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ const options = {
description: 'Use this flag to show full diffs instead of a patch.',
type: 'boolean',
},
experimentalProjects: {
description: 'A list of projects that use Jest to run all tests in a ' +
'single run.',
type: 'array',
},
findRelatedTests: {
description: 'Find related tests for a list of source files that were ' +
'passed in as arguments. Useful for pre-commit hook integration to run ' +
Expand Down Expand Up @@ -181,6 +176,11 @@ const options = {
'also specified.',
type: 'string',
},
projects: {
description: 'A list of projects that use Jest to run all tests of all ' +
'projects in a single instance of Jest.',
type: 'array',
},
runInBand: {
alias: 'i',
description: 'Run all tests serially in the current process (rather than ' +
Expand Down
11 changes: 5 additions & 6 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const runCLI = require('./runCLI');
const validateCLIOptions = require('jest-util').validateCLIOptions;
const yargs = require('yargs');

function run(argv?: Object, root?: Path) {
function run(argv?: Object, project?: Path) {
argv = yargs(argv || process.argv.slice(2))
.usage(args.usage)
.help()
Expand All @@ -36,16 +36,15 @@ function run(argv?: Object, root?: Path) {
return;
}

if (!root) {
root = pkgDir.sync();
if (!project) {
project = pkgDir.sync();
}

argv.projects = argv.experimentalProjects;
if (!argv.projects) {
argv.projects = [root];
argv.projects = [project];
}

const execute = argv.projects.length === 1 ? getJest(root).runCLI : runCLI;
const execute = argv.projects.length === 1 ? getJest(project).runCLI : runCLI;
execute(argv, argv.projects, result => {
const code = !result || result.success ? 0 : 1;
process.on('exit', () => process.exit(code));
Expand Down
36 changes: 30 additions & 6 deletions packages/jest-cli/src/cli/runCLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const VERSION = require('../../package.json').version;

module.exports = async (
argv: Object,
roots: Array<Path>,
projects: Array<Path>,
onComplete: (results: ?AggregatedResult) => void,
) => {
const realFs = require('fs');
Expand Down Expand Up @@ -91,19 +91,43 @@ module.exports = async (
};

try {
const configs = await Promise.all(
roots.map(root => readConfig(argv, root)),
);
let globalConfig;
let hasDeprecationWarnings;
let configs = [];
let config;
if (projects.length === 1) {
({config, globalConfig, hasDeprecationWarnings} = await readConfig(
argv,
projects[0],
));
configs = [{config, globalConfig, hasDeprecationWarnings}];
if (globalConfig.projects && globalConfig.projects.length) {
projects = globalConfig.projects;
}
}

if (projects.length > 1) {
configs = await Promise.all(projects.map(root => readConfig(argv, root)));
// If no config was passed initially, use the one from the first project
if (!globalConfig && !config) {
globalConfig = configs[0].globalConfig;
config = configs[0].config;
}
}

if (!config || !globalConfig || !configs.length) {
throw new Error('jest: No configuration found for any project.');
}

if (argv.debug || argv.showConfig) {
logDebugMessages(configs[0].globalConfig, configs[0].config, pipe);
logDebugMessages(globalConfig, config, pipe);
}

if (argv.showConfig) {
process.exit(0);
}

await _run(configs[0].globalConfig, configs);
await _run(globalConfig, configs);
} catch (error) {
clearLine(process.stderr);
clearLine(process.stdout);
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "build/index.js",
"dependencies": {
"chalk": "^1.1.3",
"glob": "^7.1.1",
"jest-environment-jsdom": "^19.0.2",
"jest-environment-node": "^19.0.2",
"jest-jasmine2": "^19.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports[`preset throws when preset not found 1`] = `
</>"
`;
exports[`rootDir throws if the config is missing a rootDir property 1`] = `
exports[`rootDir throws if the options is missing a rootDir property 1`] = `
"<red><bold><bold>● <bold>Validation Error:
Configuration option <bold>rootDir must be specified.
Expand Down
Loading

0 comments on commit 909da52

Please sign in to comment.