diff --git a/integration_tests/__tests__/__snapshots__/show_config.test.js.snap b/integration_tests/__tests__/__snapshots__/show_config.test.js.snap index 7875beebe54d..aea80b32ebea 100644 --- a/integration_tests/__tests__/__snapshots__/show_config.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/show_config.test.js.snap @@ -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", diff --git a/packages/jest-cli/src/lib/__tests__/is_valid_path.test.js b/packages/jest-cli/src/lib/__tests__/is_valid_path.test.js index e84168d28d4c..973e9b385212 100644 --- a/packages/jest-cli/src/lib/__tests__/is_valid_path.test.js +++ b/packages/jest-cli/src/lib/__tests__/is_valid_path.test.js @@ -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'); @@ -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'), ), diff --git a/packages/jest-cli/src/lib/is_valid_path.js b/packages/jest-cli/src/lib/is_valid_path.js index cad082e6727b..15e5ca51553a 100644 --- a/packages/jest-cli/src/lib/is_valid_path.js +++ b/packages/jest-cli/src/lib/is_valid_path.js @@ -10,8 +10,6 @@ import type {GlobalConfig, ProjectConfig} from 'types/Config'; -import path from 'path'; - const SNAPSHOT_EXTENSION = 'snap'; function isValidPath( @@ -19,11 +17,8 @@ function isValidPath( 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}`) ); } diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index c26c291df90e..8f7a7f630aea 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -513,6 +513,19 @@ describe('testRunner', () => { }); }); +describe('coverageDirectory', () => { + it('defaults to /coverage', () => { + const {options} = normalize( + { + rootDir: '/root/path/foo', + }, + {}, + ); + + expect(options.coverageDirectory).toBe('/root/path/foo/coverage'); + }); +}); + describe('testEnvironment', () => { let Resolver; beforeEach(() => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 852358bc35e0..d00075096d8a 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -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