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

Finalize split #3388

Merged
merged 3 commits into from
Apr 27, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Object {

Expected two assertions to be called but only received one assertion call.

at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:56:21)
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:62:21)

● .assertions() › throws on redeclare of assertion count

Expand All @@ -87,7 +87,7 @@ Object {

Expected zero assertions to be called but only received one assertion call.

at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:56:21)
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:62:21)

.assertions()
✕ throws
Expand Down
39 changes: 10 additions & 29 deletions integration_tests/__tests__/__snapshots__/showConfig-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
{
"config": {
"automock": false,
"bail": false,
"browser": false,
"cache": false,
"cacheDirectory": "/tmp/jest",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"expand": false,
"globals": {},
"haste": {
"providesModuleNodeModules": []
},
"mapCoverage": false,
"moduleDirectories": [
"node_modules"
],
Expand All @@ -34,14 +26,17 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
],
"moduleNameMapper": {},
"modulePathIgnorePatterns": [],
"noStackTrace": false,
"notify": false,
"name": "[md5 hash]",
"preset": null,
"resetMocks": false,
"resetModules": false,
"rootDir": "/mocked/root/path/jest/integration_tests/verbose_reporter",
"roots": [
"/mocked/root/path/jest/integration_tests/verbose_reporter"
],
"setupFiles": [
"/mocked/root/path/jest/node_modules/regenerator-runtime/runtime.js"
],
"snapshotSerializers": [],
"testEnvironment": "/mocked/root/path/jest/packages/jest-environment-node/build/index.js",
"testMatch": [
Expand All @@ -52,36 +47,22 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"/node_modules/"
],
"testRegex": "",
"testResultsProcessor": null,
"testRunner": "/mocked/root/path/jest/packages/jest-jasmine2/build/index.js",
"testURL": "about:blank",
"timers": "real",
"transformIgnorePatterns": [
"/node_modules/"
],
"useStderr": false,
"verbose": null,
"watch": false,
"rootDir": "/mocked/root/path/jest/integration_tests/verbose_reporter",
"name": "[md5 hash]",
"setupFiles": [
"/mocked/root/path/jest/node_modules/regenerator-runtime/runtime.js"
],
"testRunner": "/mocked/root/path/jest/packages/jest-jasmine2/build/index.js",
"transform": [
[
"^.+\\\\.jsx?$",
"/mocked/root/path/jest/integration_tests/verbose_reporter/node_modules/babel-jest/build/index.js"
]
],
"cache": false,
"watchman": true
"transformIgnorePatterns": [
"/node_modules/"
]
},
"framework": "jasmine2",
"globalConfig": {
"bail": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"json",
"text",
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ test('watchman config option is respected over default argv', () => {
'--debug',
]);

expect(stdout).toMatch('"watchman": false,');
expect(stdout).toMatch('"watchman": false');
});
33 changes: 19 additions & 14 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type OnTestSuccess = (test: Test, result: TestResult) => void;
const TEST_WORKER_PATH = require.resolve('./TestWorker');

class TestRunner {
_config: GlobalConfig;
_globalConfig: GlobalConfig;
_options: Options;
_dispatcher: ReporterDispatcher;

constructor(config: GlobalConfig, options: Options) {
this._config = config;
constructor(globalConfig: GlobalConfig, options: Options) {
this._globalConfig = globalConfig;
this._dispatcher = new ReporterDispatcher();
this._options = options;
this._setupReporters();
Expand Down Expand Up @@ -125,7 +125,7 @@ class TestRunner {
testResult.failureMessage = formatExecError(
testResult,
test.context.config,
this._config,
this._globalConfig,
test.path,
);
addResult(aggregatedResults, testResult);
Expand All @@ -136,18 +136,19 @@ class TestRunner {
contexts.forEach(context => {
const status = snapshot.cleanup(
context.hasteFS,
this._config.updateSnapshot,
this._globalConfig.updateSnapshot,
);
aggregatedResults.snapshot.filesRemoved += status.filesRemoved;
});
aggregatedResults.snapshot.didUpdate = this._config.updateSnapshot;
aggregatedResults.snapshot.failure = !!(!this._config.updateSnapshot &&
aggregatedResults.snapshot.didUpdate = this._globalConfig.updateSnapshot;
aggregatedResults.snapshot.failure = !!(!this._globalConfig
.updateSnapshot &&
(aggregatedResults.snapshot.unchecked ||
aggregatedResults.snapshot.unmatched ||
aggregatedResults.snapshot.filesRemoved));
};

this._dispatcher.onRunStart(this._config, aggregatedResults, {
this._dispatcher.onRunStart(this._globalConfig, aggregatedResults, {
estimatedTime,
showStatus: !runInBand,
});
Expand All @@ -165,7 +166,11 @@ class TestRunner {
updateSnapshotState();
aggregatedResults.wasInterrupted = watcher.isInterrupted();

this._dispatcher.onRunComplete(contexts, this._config, aggregatedResults);
this._dispatcher.onRunComplete(
contexts,
this._globalConfig,
aggregatedResults,
);

const anyTestFailures = !(aggregatedResults.numFailedTests === 0 &&
aggregatedResults.numRuntimeErrorTestSuites === 0);
Expand Down Expand Up @@ -197,7 +202,7 @@ class TestRunner {
this._dispatcher.onTestStart(test);
return runTest(
test.path,
this._config,
this._globalConfig,
test.context.config,
test.context.resolver,
);
Expand Down Expand Up @@ -237,7 +242,7 @@ class TestRunner {
this._dispatcher.onTestStart(test);
return worker({
config: test.context.config,
globalConfig: this._config,
globalConfig: this._globalConfig,
path: test.path,
rawModuleMap: watcher.isWatchMode()
? test.context.moduleMap.getRawModuleMap()
Expand Down Expand Up @@ -277,7 +282,7 @@ class TestRunner {
}

_setupReporters() {
const {collectCoverage, expand, notify, verbose} = this._config;
const {collectCoverage, expand, notify, verbose} = this._globalConfig;

this.addReporter(
verbose
Expand All @@ -303,13 +308,13 @@ class TestRunner {
aggregatedResults: AggregatedResult,
watcher: TestWatcher,
) {
if (this._config.bail && aggregatedResults.numFailedTests !== 0) {
if (this._globalConfig.bail && aggregatedResults.numFailedTests !== 0) {
if (watcher.isWatchMode()) {
watcher.setState({interrupted: true});
} else {
this._dispatcher.onRunComplete(
contexts,
this._config,
this._globalConfig,
aggregatedResults,
);
process.exit(1);
Expand Down
14 changes: 9 additions & 5 deletions packages/jest-cli/src/__tests__/generateEmptyCoverage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ module.exports = {

it('generates an empty coverage object for a file without running it', () => {
expect(
generateEmptyCoverage(src, '/sum.js', {
baseCacheDir: os.tmpdir(),
cacheDirectory: os.tmpdir(),
rootDir: os.tmpdir(),
}).coverage,
generateEmptyCoverage(
src,
'/sum.js',
{},
{
cacheDirectory: os.tmpdir(),
rootDir: os.tmpdir(),
},
).coverage,
).toMatchSnapshot();
});
1 change: 1 addition & 0 deletions packages/jest-cli/src/cli/runCLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = async (
maxWorkers: getMaxWorkers(argv),
resetCache: !config.cache,
watch: globalConfig.watch,
watchman: globalConfig.watchman,
});
hasteMapInstances[index] = hasteMapInstance;
return createContext(config, await hasteMapInstance.build());
Expand Down
12 changes: 10 additions & 2 deletions packages/jest-cli/src/generateEmptyCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {ProjectConfig, Path} from 'types/Config';
import type {GlobalConfig, ProjectConfig, Path} from 'types/Config';

const IstanbulInstrument = require('istanbul-lib-instrument');

Expand All @@ -19,15 +19,23 @@ const {ScriptTransformer, shouldInstrument} = require('jest-runtime');
module.exports = function(
source: string,
filename: Path,
globalConfig: GlobalConfig,
config: ProjectConfig,
) {
if (shouldInstrument(filename, config)) {
const coverageOptions = {
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
mapCoverage: globalConfig.mapCoverage,
};
if (shouldInstrument(filename, coverageOptions, config)) {
// Transform file without instrumentation first, to make sure produced
// source code is ES6 (no flowtypes etc.) and can be instrumented
const transformResult = new ScriptTransformer(config).transformSource(
filename,
source,
false,
globalConfig.mapCoverage,
);
const instrumenter = IstanbulInstrument.createInstrumenter();
instrumenter.instrumentSync(transformResult.code, filename);
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/reporters/BaseReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseReporter {
}

onRunStart(
config: GlobalConfig,
globalConfig: GlobalConfig,
results: AggregatedResult,
options: ReporterOnStartOptions,
) {
Expand All @@ -38,7 +38,7 @@ class BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: GlobalConfig,
globalConfig: GlobalConfig,
aggregatedResults: AggregatedResult,
): ?Promise<any> {}

Expand Down
42 changes: 27 additions & 15 deletions packages/jest-cli/src/reporters/CoverageReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ class CoverageReporter extends BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: GlobalConfig,
globalConfig: GlobalConfig,
aggregatedResults: AggregatedResult,
) {
this._addUntestedFiles(contexts);
this._addUntestedFiles(globalConfig, contexts);
let map = this._coverageMap;
let sourceFinder: Object;
if (config.mapCoverage) {
if (globalConfig.mapCoverage) {
({map, sourceFinder} = this._sourceMapStore.transformCoverage(map));
}

const reporter = createReporter();
try {
if (config.coverageDirectory) {
reporter.dir = config.coverageDirectory;
if (globalConfig.coverageDirectory) {
reporter.dir = globalConfig.coverageDirectory;
}

let coverageReporters = config.coverageReporters || [];
let coverageReporters = globalConfig.coverageReporters || [];
if (
!config.useStderr &&
!globalConfig.useStderr &&
coverageReporters.length &&
coverageReporters.indexOf('text') === -1
) {
Expand All @@ -101,16 +101,19 @@ class CoverageReporter extends BaseReporter {
);
}

this._checkThreshold(map, config);
this._checkThreshold(globalConfig, map);
}

_addUntestedFiles(contexts: Set<Context>) {
_addUntestedFiles(globalConfig: GlobalConfig, contexts: Set<Context>) {
const files = [];
contexts.forEach(context => {
const config = context.config;
if (config.collectCoverageFrom && config.collectCoverageFrom.length) {
if (
globalConfig.collectCoverageFrom &&
globalConfig.collectCoverageFrom.length
) {
context.hasteFS
.matchFilesWithGlob(config.collectCoverageFrom, config.rootDir)
.matchFilesWithGlob(globalConfig.collectCoverageFrom, config.rootDir)
.forEach(filePath =>
files.push({
config,
Expand All @@ -129,7 +132,12 @@ class CoverageReporter extends BaseReporter {
if (!this._coverageMap.data[path]) {
try {
const source = fs.readFileSync(path).toString();
const result = generateEmptyCoverage(source, path, config);
const result = generateEmptyCoverage(
source,
path,
globalConfig,
config,
);
if (result) {
this._coverageMap.addFileCoverage(result.coverage);
if (result.sourceMapPath) {
Expand All @@ -155,8 +163,8 @@ class CoverageReporter extends BaseReporter {
}
}

_checkThreshold(map: CoverageMap, config: GlobalConfig) {
if (config.coverageThreshold) {
_checkThreshold(globalConfig: GlobalConfig, map: CoverageMap) {
if (globalConfig.coverageThreshold) {
const results = map.getCoverageSummary().toJSON();

function check(name, thresholds, actuals) {
Expand Down Expand Up @@ -188,7 +196,11 @@ class CoverageReporter extends BaseReporter {
return errors;
}, []);
}
const errors = check('global', config.coverageThreshold.global, results);
const errors = check(
'global',
globalConfig.coverageThreshold.global,
results,
);

if (errors.length > 0) {
this.log(`${FAIL_COLOR(errors.join('\n'))}`);
Expand Down
Loading