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 2 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');
});
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
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
5 changes: 4 additions & 1 deletion packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const TestSequencer = require('./TestSequencer');

const setConfig = (contexts, newConfig) =>
contexts.forEach(
context => (context.config = Object.assign({}, context.config, newConfig)),
context =>
(context.config = Object.freeze(
Object.assign({}, context.config, newConfig),
)),
);

const formatTestPathPattern = pattern => {
Expand Down
16 changes: 12 additions & 4 deletions packages/jest-cli/src/runTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {TestResult} from 'types/TestResult';
import type {Resolver} from 'types/Resolve';
import type RuntimeClass from 'jest-runtime';

const BufferedConsole = require('./lib/BufferedConsole');
const {Console, NullConsole, setGlobal} = require('jest-util');
Expand Down Expand Up @@ -52,14 +53,16 @@ function runTest(
/* $FlowFixMe */
const TestRunner = require(config.testRunner);
/* $FlowFixMe */
const ModuleLoader = require(config.moduleLoader || 'jest-runtime');
const Runtime = (require(config.moduleLoader || 'jest-runtime'): Class<
RuntimeClass
>);

const env = new TestEnvironment(config);
const TestConsole = globalConfig.verbose
? Console
: config.silent ? NullConsole : BufferedConsole;
: globalConfig.silent ? NullConsole : BufferedConsole;
const testConsole = new TestConsole(
config.useStderr ? process.stderr : process.stdout,
globalConfig.useStderr ? process.stderr : process.stdout,
process.stderr,
(type, message) =>
getConsoleOutput(
Expand All @@ -71,7 +74,12 @@ function runTest(
);
const cacheFS = {[path]: testSource};
setGlobal(env.global, 'console', testConsole);
const runtime = new ModuleLoader(config, env, resolver, cacheFS);
const runtime = new Runtime(config, env, resolver, cacheFS, {
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
mapCoverage: globalConfig.mapCoverage,
});
const start = Date.now();
return TestRunner(globalConfig, config, env, runtime, path)
.then((result: TestResult) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {DefaultConfig} from 'types/Config';
import type {DefaultOptions} from 'types/Config';

const constants = require('./constants');
const os = require('os');
Expand Down Expand Up @@ -66,4 +66,4 @@ module.exports = ({
useStderr: false,
verbose: null,
watch: false,
}: DefaultConfig);
}: DefaultOptions);
39 changes: 36 additions & 3 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ const getConfigs = (
collectCoverageFrom: options.collectCoverageFrom,
collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
coverageDirectory: options.coverageDirectory,
coveragePathIgnorePatterns: options.coveragePathIgnorePatterns,
coverageReporters: options.coverageReporters,
coverageThreshold: options.coverageThreshold,
expand: options.expand,
forceExit: options.forceExit,
logHeapUsage: options.logHeapUsage,
logTransformErrors: options.logTransformErrors,
mapCoverage: options.mapCoverage,
noStackTrace: options.noStackTrace,
notify: options.notify,
Expand All @@ -95,7 +93,42 @@ const getConfigs = (
watch: options.watch,
watchman: options.watchman,
}),
projectConfig: options,
projectConfig: Object.freeze({
automock: options.automock,
browser: options.browser,
cache: options.cache,
cacheDirectory: options.cacheDirectory,
clearMocks: options.clearMocks,
coveragePathIgnorePatterns: options.coveragePathIgnorePatterns,
globals: options.globals,
haste: options.haste,
moduleDirectories: options.moduleDirectories,
moduleFileExtensions: options.moduleFileExtensions,
moduleLoader: options.moduleLoader,
moduleNameMapper: options.moduleNameMapper,
modulePathIgnorePatterns: options.modulePathIgnorePatterns,
modulePaths: options.modulePaths,
name: options.name,
preset: options.preset,
resetMocks: options.resetMocks,
resetModules: options.resetModules,
resolver: options.resolver,
rootDir: options.rootDir,
roots: options.roots,
setupFiles: options.setupFiles,
setupTestFrameworkScriptFile: options.setupTestFrameworkScriptFile,
snapshotSerializers: options.snapshotSerializers,
testEnvironment: options.testEnvironment,
testMatch: options.testMatch,
testPathIgnorePatterns: options.testPathIgnorePatterns,
testRegex: options.testRegex,
testRunner: options.testRunner,
testURL: options.testURL,
timers: options.timers,
transform: options.transform,
transformIgnorePatterns: options.transformIgnorePatterns,
unmockedModulePathPatterns: options.unmockedModulePathPatterns,
}),
};
};

Expand Down
Loading