Skip to content

Commit

Permalink
Set coverageDirectory during normalize phase (#3966)
Browse files Browse the repository at this point in the history
* Set coverageDirectory during normalize phase

* Update config snapshot
  • Loading branch information
thymikee authored and cpojer committed Jul 5, 2017
1 parent ab6f4c3 commit a7acc5a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
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'),
),
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 @@ -307,6 +307,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

0 comments on commit a7acc5a

Please sign in to comment.