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

--showConfig to show all project configs #4078

Merged
merged 1 commit into from
Jul 19, 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
101 changes: 51 additions & 50 deletions integration_tests/__tests__/__snapshots__/show_config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@

exports[`--showConfig outputs config info and exits 1`] = `
"{
\\"config\\": {
\\"automock\\": false,
\\"browser\\": false,
\\"cache\\": false,
\\"cacheDirectory\\": \\"/tmp/jest\\",
\\"clearMocks\\": false,
\\"coveragePathIgnorePatterns\\": [
\\"/node_modules/\\"
],
\\"globals\\": {},
\\"haste\\": {
\\"providesModuleNodeModules\\": []
},
\\"moduleDirectories\\": [
\\"node_modules\\"
],
\\"moduleFileExtensions\\": [
\\"js\\",
\\"json\\",
\\"jsx\\",
\\"node\\"
],
\\"moduleNameMapper\\": {},
\\"modulePathIgnorePatterns\\": [],
\\"name\\": \\"[md5 hash]\\",
\\"resetMocks\\": false,
\\"resetModules\\": false,
\\"rootDir\\": \\"<<REPLACED_ROOT_DIR>>\\",
\\"roots\\": [
\\"<<REPLACED_ROOT_DIR>>\\"
],
\\"setupFiles\\": [],
\\"snapshotSerializers\\": [],
\\"testEnvironment\\": \\"jest-environment-jsdom\\",
\\"testMatch\\": [
\\"**/__tests__/**/*.js?(x)\\",
\\"**/?(*.)(spec|test).js?(x)\\"
],
\\"testPathIgnorePatterns\\": [
\\"/node_modules/\\"
],
\\"testRegex\\": \\"\\",
\\"testRunner\\": \\"<<REPLACED_JEST_PACKAGES_DIR>>/jest-jasmine2/build/index.js\\",
\\"testURL\\": \\"about:blank\\",
\\"timers\\": \\"real\\",
\\"transformIgnorePatterns\\": [
\\"/node_modules/\\"
]
},
\\"framework\\": \\"jasmine2\\",
\\"configs\\": [
{
\\"automock\\": false,
\\"browser\\": false,
\\"cache\\": false,
\\"cacheDirectory\\": \\"/tmp/jest\\",
\\"clearMocks\\": false,
\\"coveragePathIgnorePatterns\\": [
\\"/node_modules/\\"
],
\\"globals\\": {},
\\"haste\\": {
\\"providesModuleNodeModules\\": []
},
\\"moduleDirectories\\": [
\\"node_modules\\"
],
\\"moduleFileExtensions\\": [
\\"js\\",
\\"json\\",
\\"jsx\\",
\\"node\\"
],
\\"moduleNameMapper\\": {},
\\"modulePathIgnorePatterns\\": [],
\\"name\\": \\"[md5 hash]\\",
\\"resetMocks\\": false,
\\"resetModules\\": false,
\\"rootDir\\": \\"<<REPLACED_ROOT_DIR>>\\",
\\"roots\\": [
\\"<<REPLACED_ROOT_DIR>>\\"
],
\\"setupFiles\\": [],
\\"snapshotSerializers\\": [],
\\"testEnvironment\\": \\"jest-environment-jsdom\\",
\\"testMatch\\": [
\\"**/__tests__/**/*.js?(x)\\",
\\"**/?(*.)(spec|test).js?(x)\\"
],
\\"testPathIgnorePatterns\\": [
\\"/node_modules/\\"
],
\\"testRegex\\": \\"\\",
\\"testRunner\\": \\"<<REPLACED_JEST_PACKAGES_DIR>>/jest-jasmine2/build/index.js\\",
\\"testURL\\": \\"about:blank\\",
\\"timers\\": \\"real\\",
\\"transformIgnorePatterns\\": [
\\"/node_modules/\\"
]
}
],
\\"globalConfig\\": {
\\"bail\\": false,
\\"changedFilesWithAncestor\\": false,
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/__tests__/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ describe('jest --debug', () => {
it('outputs debugging info before running the test', () => {
const {stdout} = runJest(dir, ['--debug', '--no-cache']);
expect(stdout).toMatch('"version": "');
expect(stdout).toMatch('"framework": "jasmine2",');
expect(stdout).toMatch('"config": {');
expect(stdout).toMatch('"configs": [');
// config contains many file paths so we cannot do snapshot test
});
});
6 changes: 3 additions & 3 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ const _getRunCLIFn = (projects: Array<Path>) =>
const _printDebugInfoAndExitIfNeeded = (
argv,
globalConfig,
config,
configs,
outputStream,
) => {
if (argv.debug || argv.showConfig) {
logDebugMessages(globalConfig, config, outputStream);
logDebugMessages(globalConfig, configs, outputStream);
}
if (argv.showConfig) {
process.exit(0);
Expand Down Expand Up @@ -213,7 +213,7 @@ const _getConfigs = (
throw new Error('jest: No configuration found for any project.');
}

_printDebugInfoAndExitIfNeeded(argv, globalConfig, configs[0], outputStream);
_printDebugInfoAndExitIfNeeded(argv, globalConfig, configs, outputStream);

return {
configs,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`prints the config object 1`] = `
"{
\\"configs\\": {
\\"rootDir\\": \\"/path/to/dir\\",
\\"roots\\": [
\\"path/to/dir/test\\"
],
\\"testRunner\\": \\"myRunner\\"
},
\\"globalConfig\\": {
\\"automock\\": false,
\\"watch\\": true
},
\\"version\\": 123
}
"
`;

exports[`prints the jest version 1`] = `
"{
\\"configs\\": {
\\"testRunner\\": \\"myRunner\\"
},
\\"globalConfig\\": {
\\"watch\\": true
},
\\"version\\": 123
}
"
`;

exports[`prints the test framework name 1`] = `
"{
\\"configs\\": {
\\"testRunner\\": \\"myRunner\\"
},
\\"globalConfig\\": {
\\"watch\\": true
},
\\"version\\": 123
}
"
`;
73 changes: 28 additions & 45 deletions packages/jest-cli/src/lib/__tests__/log_debug_messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/

'use strict';
Expand All @@ -16,47 +14,32 @@ jest.mock('../../../package.json', () => ({version: 123}));

jest.mock('myRunner', () => ({name: 'My Runner'}), {virtual: true});

const getPipe = () => ({write: jest.fn()});
const print = (
globalConfig = {watch: true},
config = {testRunner: 'myRunner'},
) =>
JSON.stringify(
{
config,
framework: 'My Runner',
globalConfig,
version: 123,
},
null,
' ',
);

describe('logDebugMessages', () => {
it('Prints the jest version', () => {
const pipe = getPipe();
logDebugMessages({watch: true}, {testRunner: 'myRunner'}, pipe);
expect(pipe.write).toHaveBeenCalledWith(print() + '\n');
});

it('Prints the test framework name', () => {
const pipe = getPipe();
logDebugMessages({watch: true}, {testRunner: 'myRunner'}, pipe);
expect(pipe.write).toHaveBeenCalledWith(print() + '\n');
});

it('Prints the config object', () => {
const pipe = getPipe();
const globalConfig = {
automock: false,
watch: true,
};
const config = {
rootDir: '/path/to/dir',
roots: ['path/to/dir/test'],
testRunner: 'myRunner',
};
logDebugMessages(globalConfig, config, pipe);
expect(pipe.write).toHaveBeenCalledWith(print(globalConfig, config) + '\n');
});
const getOutputStream = () => ({
write(message) {
expect(message).toMatchSnapshot();
},
});

it('prints the jest version', () => {
expect.assertions(1);
logDebugMessages({watch: true}, {testRunner: 'myRunner'}, getOutputStream());
});

it('prints the test framework name', () => {
expect.assertions(1);
logDebugMessages({watch: true}, {testRunner: 'myRunner'}, getOutputStream());
});

it('prints the config object', () => {
expect.assertions(1);
const globalConfig = {
automock: false,
watch: true,
};
const config = {
rootDir: '/path/to/dir',
roots: ['path/to/dir/test'],
testRunner: 'myRunner',
};
logDebugMessages(globalConfig, config, getOutputStream());
});
8 changes: 2 additions & 6 deletions packages/jest-cli/src/lib/log_debug_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
*/

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

import {version as VERSION} from '../../package.json';

const logDebugMessages = (
globalConfig: GlobalConfig,
config: ProjectConfig,
configs: Array<ProjectConfig>,
outputStream: stream$Writable | tty$WriteStream,
): void => {
/* $FlowFixMe */
const testFramework = (require(config.testRunner): TestFramework);
const output = {
config,
framework: testFramework.name,
configs,
globalConfig,
version: VERSION,
};
Expand Down