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

Set coverageDirectory during normalize phase #3966

Merged
merged 2 commits into from
Jul 5, 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 @@ -62,6 +62,7 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"framework": "jasmine2",
"globalConfig": {
"bail": false,
"coverageDirectory": "/mocked/root/path/jest/integration_tests/verbose_reporter/coverage",
"coverageReporters": [
"json",
"text",
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-cli/src/lib/__tests__/is_valid_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

const path = require('path');
const isValidPath = require('../is_valid_path');
const {normalize} = require('jest-config');

const rootDir = path.resolve(path.sep, 'root');

Expand Down Expand Up @@ -61,7 +62,7 @@ it('is not valid when it is a snapshot file', () => {
it('is not valid when it is a file in the coverage dir', () => {
expect(
isValidPath(
{},
normalize({rootDir}, {}).options,
config,
path.resolve(rootDir, 'coverage', 'lib', 'index.js'),
),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we still need this test. The same thing is tested in normalize.test.js

Expand Down
7 changes: 1 addition & 6 deletions packages/jest-cli/src/lib/is_valid_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@

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

import path from 'path';

const SNAPSHOT_EXTENSION = 'snap';

function isValidPath(
globalConfig: GlobalConfig,
config: ProjectConfig,
filePath: string,
) {
const coverageDirectory =
globalConfig.coverageDirectory || path.resolve(config.rootDir, 'coverage');

return (
!filePath.includes(coverageDirectory) &&
!filePath.includes(globalConfig.coverageDirectory) &&
!filePath.endsWith(`.${SNAPSHOT_EXTENSION}`)
);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,19 @@ describe('testRunner', () => {
});
});

describe('coverageDirectory', () => {
it('defaults to <rootDir>/coverage', () => {
const {options} = normalize(
{
rootDir: '/root/path/foo',
},
{},
);

expect(options.coverageDirectory).toBe('/root/path/foo/coverage');
});
});

describe('testEnvironment', () => {
let Resolver;
beforeEach(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ function normalize(options: InitialOptions, argv: Argv) {
options.testRunner = require.resolve('jest-jasmine2');
}

if (!options.coverageDirectory) {
options.coverageDirectory = path.resolve(options.rootDir, 'coverage');
}

const babelJest = setupBabelJest(options);
const newOptions = Object.assign({}, DEFAULT_CONFIG);
// Cast back to exact type
Expand Down