From 84d73c7a7439cca4933f06c30e4f0be70832e358 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 22 Aug 2017 10:34:02 -0700 Subject: [PATCH 1/8] Modify flow types to support displayName --- packages/jest-config/src/index.js | 1 + packages/jest-config/src/normalize.js | 1 + packages/jest-config/src/valid_config.js | 1 + test_utils.js | 1 + types/Config.js | 26 +++++++++++++----------- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js index d5ff0416e7c6..ae1955b22c25 100644 --- a/packages/jest-config/src/index.js +++ b/packages/jest-config/src/index.js @@ -120,6 +120,7 @@ const getConfigs = ( cacheDirectory: options.cacheDirectory, clearMocks: options.clearMocks, coveragePathIgnorePatterns: options.coveragePathIgnorePatterns, + displayName: options.displayName, globals: options.globals, haste: options.haste, moduleDirectories: options.moduleDirectories, diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 6bf35faca52c..b5071f5335ae 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -452,6 +452,7 @@ function normalize(options: InitialOptions, argv: Argv) { case 'collectCoverage': case 'coverageReporters': case 'coverageThreshold': + case 'displayName': case 'expand': case 'globals': case 'findRelatedTests': diff --git a/packages/jest-config/src/valid_config.js b/packages/jest-config/src/valid_config.js index 448336755176..1409f5e1cfc0 100644 --- a/packages/jest-config/src/valid_config.js +++ b/packages/jest-config/src/valid_config.js @@ -36,6 +36,7 @@ module.exports = ({ branches: 50, }, }, + displayName: 'project-name', expand: false, forceExit: false, globals: {}, diff --git a/test_utils.js b/test_utils.js index 82f55427b889..3ac8aad756b3 100644 --- a/test_utils.js +++ b/test_utils.js @@ -60,6 +60,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = { cacheDirectory: '/test_cache_dir/', clearMocks: false, coveragePathIgnorePatterns: [], + displayName: undefined, globals: {}, haste: { providesModuleNodeModules: [], diff --git a/types/Config.js b/types/Config.js index 8d17d4b06ced..617ebf3abb25 100644 --- a/types/Config.js +++ b/types/Config.js @@ -15,7 +15,7 @@ export type HasteConfig = {| defaultPlatform?: ?string, hasteImplModulePath?: string, platforms?: Array, - providesModuleNodeModules: Array, + providesModuleNodeModules: Array |}; export type ReporterConfig = [string, Object]; @@ -37,7 +37,7 @@ export type DefaultOptions = {| mapCoverage: boolean, moduleDirectories: Array, moduleFileExtensions: Array, - moduleNameMapper: {[key: string]: string}, + moduleNameMapper: { [key: string]: string }, modulePathIgnorePatterns: Array, noStackTrace: boolean, notify: boolean, @@ -58,7 +58,7 @@ export type DefaultOptions = {| useStderr: boolean, verbose: ?boolean, watch: boolean, - watchman: boolean, + watchman: boolean |}; export type InitialOptions = { @@ -71,11 +71,12 @@ export type InitialOptions = { changedFilesWithAncestor?: boolean, collectCoverage?: boolean, collectCoverageFrom?: Array, - collectCoverageOnlyFrom?: {[key: string]: boolean}, + collectCoverageOnlyFrom?: { [key: string]: boolean }, coverageDirectory?: string, coveragePathIgnorePatterns?: Array, coverageReporters?: Array, - coverageThreshold?: {global: {[key: string]: number}}, + coverageThreshold?: { global: { [key: string]: number } }, + displayName?: string, expand?: boolean, findRelatedTests?: boolean, forceExit?: boolean, @@ -89,7 +90,7 @@ export type InitialOptions = { moduleDirectories?: Array, moduleFileExtensions?: Array, moduleLoader?: Path, - moduleNameMapper?: {[key: string]: string}, + moduleNameMapper?: { [key: string]: string }, modulePathIgnorePatterns?: Array, modulePaths?: Array, name?: string, @@ -124,7 +125,7 @@ export type InitialOptions = { testRunner?: string, testURL?: string, timers?: 'real' | 'fake', - transform?: {[key: string]: string}, + transform?: { [key: string]: string }, transformIgnorePatterns?: Array, unmockedModulePathPatterns?: Array, updateSnapshot?: boolean, @@ -132,7 +133,7 @@ export type InitialOptions = { verbose?: ?boolean, watch?: boolean, watchAll?: boolean, - watchman?: boolean, + watchman?: boolean }; export type SnapshotUpdateState = 'all' | 'new' | 'none'; @@ -142,10 +143,10 @@ export type GlobalConfig = {| changedFilesWithAncestor: boolean, collectCoverage: boolean, collectCoverageFrom: Array, - collectCoverageOnlyFrom: ?{[key: string]: boolean}, + collectCoverageOnlyFrom: ?{ [key: string]: boolean }, coverageDirectory: string, coverageReporters: Array, - coverageThreshold: {global: {[key: string]: number}}, + coverageThreshold: { global: { [key: string]: number } }, expand: boolean, findRelatedTests: boolean, forceExit: boolean, @@ -175,7 +176,7 @@ export type GlobalConfig = {| verbose: ?boolean, watch: boolean, watchAll: boolean, - watchman: boolean, + watchman: boolean |}; export type ProjectConfig = {| @@ -185,6 +186,7 @@ export type ProjectConfig = {| cacheDirectory: Path, clearMocks: boolean, coveragePathIgnorePatterns: Array, + displayName: ?string, globals: ConfigGlobals, haste: HasteConfig, moduleDirectories: Array, @@ -213,5 +215,5 @@ export type ProjectConfig = {| timers: 'real' | 'fake', transform: Array<[string, Path]>, transformIgnorePatterns: Array, - unmockedModulePathPatterns: ?Array, + unmockedModulePathPatterns: ?Array |}; From 372a1bbe4183216e92505a07116d0ba45307047c Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 22 Aug 2017 11:09:52 -0700 Subject: [PATCH 2/8] Add project displayName --- packages/jest-cli/src/reporters/Status.js | 18 +++++++++-------- .../src/reporters/default_reporter.js | 2 +- .../src/reporters/get_result_header.js | 20 ++++++++++++++----- packages/jest-cli/src/reporters/utils.js | 8 +++++++- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/jest-cli/src/reporters/Status.js b/packages/jest-cli/src/reporters/Status.js index 428a8b35e77f..3c63b9d5f4eb 100644 --- a/packages/jest-cli/src/reporters/Status.js +++ b/packages/jest-cli/src/reporters/Status.js @@ -13,7 +13,13 @@ import type {ProjectConfig, Path} from 'types/Config'; import type {ReporterOnStartOptions} from 'types/Reporters'; import chalk from 'chalk'; -import {getSummary, trimAndFormatPath, wrapAnsiString} from './utils'; +import stringLength from 'string-length'; +import { + getSummary, + trimAndFormatPath, + wrapAnsiString, + printDisplayName, +} from './utils'; const RUNNING_TEXT = ' RUNS '; const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' '; @@ -136,15 +142,11 @@ class Status { this._currentTests.get().forEach(record => { if (record) { const {config, testPath} = record; + const prefix = RUNNING + printDisplayName(config) + ' '; content += wrapAnsiString( - RUNNING + - trimAndFormatPath( - RUNNING_TEXT.length + 1, - config, - testPath, - width, - ), + prefix + + trimAndFormatPath(stringLength(prefix), config, testPath, width), width, ) + '\n'; } diff --git a/packages/jest-cli/src/reporters/default_reporter.js b/packages/jest-cli/src/reporters/default_reporter.js index 08d4a9f24750..1d284b441d4c 100644 --- a/packages/jest-cli/src/reporters/default_reporter.js +++ b/packages/jest-cli/src/reporters/default_reporter.js @@ -173,7 +173,7 @@ class DefaultReporter extends BaseReporter { result: TestResult, ) { if (!result.skipped) { - this.log(getResultHeader(result, config)); + this.log(getResultHeader(result, this._globalConfig, config)); const consoleBuffer = result.console; if (consoleBuffer && consoleBuffer.length) { diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-cli/src/reporters/get_result_header.js index fcd7bd64192d..694a58d5b26d 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -8,11 +8,11 @@ * @flow */ -import type {Path} from 'types/Config'; +import type {Path, GlobalConfig, ProjectConfig} from 'types/Config'; import type {TestResult} from 'types/TestResult'; import chalk from 'chalk'; -import {formatTestPath} from './utils'; +import {formatTestPath, printDisplayName} from './utils'; const LONG_TEST_COLOR = chalk.reset.bold.bgRed; // Explicitly reset for these messages since they can get written out in the @@ -20,7 +20,11 @@ const LONG_TEST_COLOR = chalk.reset.bold.bgRed; const FAIL = chalk.reset.inverse.bold.red(' FAIL '); const PASS = chalk.reset.inverse.bold.green(' PASS '); -module.exports = (result: TestResult, config: {rootDir: Path}) => { +module.exports = ( + result: TestResult, + globalConfig: GlobalConfig, + projectConfig?: ProjectConfig, +) => { const testPath = result.testFilePath; const status = result.numFailingTests > 0 || result.testExecError ? FAIL : PASS; @@ -39,8 +43,14 @@ module.exports = (result: TestResult, config: {rootDir: Path}) => { testDetail.push(`${toMB(result.memoryUsage)} MB heap size`); } + const projectDisplayName = projectConfig + ? printDisplayName(projectConfig) + : ''; + return ( - `${status} ${formatTestPath(config, testPath)}` + - (testDetail.length ? ` (${testDetail.join(', ')})` : '') + `${status} ${projectDisplayName} ${formatTestPath( + globalConfig, + testPath, + )}` + (testDetail.length ? ` (${testDetail.join(', ')})` : '') ); }; diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index 266651888c00..fbc84f2d2703 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -8,7 +8,7 @@ * @flow */ -import type {Path} from 'types/Config'; +import type {Path, ProjectConfig} from 'types/Config'; import type {AggregatedResult} from 'types/TestResult'; import path from 'path'; @@ -23,6 +23,11 @@ type SummaryOptions = {| const PROGRESS_BAR_WIDTH = 40; +const printDisplayName = (config: ProjectConfig) => + config.displayName + ? chalk.reset.inverse.white.dim(` ${config.displayName} `) + : ''; + const trimAndFormatPath = ( pad: number, config: {rootDir: Path}, @@ -235,6 +240,7 @@ module.exports = { formatTestPath, getSummary, pluralize, + printDisplayName, relativePath, trimAndFormatPath, wrapAnsiString, From 417416a1e8cb1aae50f24e9374e8f630def073a7 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 22 Aug 2017 11:58:43 -0700 Subject: [PATCH 3/8] Some small fixes --- .../reporters/__tests__/default_reporter.test.js | 4 ++-- .../jest-cli/src/reporters/get_result_header.js | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js index d22815366861..8e33903aecae 100644 --- a/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js @@ -54,7 +54,7 @@ afterEach(() => { }); test('normal output, everything goes to stdout', () => { - const reporter = new DefaultReporter({useStderr: false}); + const reporter = new DefaultReporter({rootDir: '', useStderr: false}); reporter.onRunStart(aggregatedResults, options); reporter.onTestStart(testCase); @@ -67,7 +67,7 @@ test('normal output, everything goes to stdout', () => { }); test('when using stderr as output, no stdout call is made', () => { - const reporter = new DefaultReporter({useStderr: true}); + const reporter = new DefaultReporter({rootDir: '', useStderr: true}); reporter.onRunStart(aggregatedResults, options); reporter.onTestStart(testCase); diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-cli/src/reporters/get_result_header.js index 694a58d5b26d..1496e55a742e 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -43,14 +43,13 @@ module.exports = ( testDetail.push(`${toMB(result.memoryUsage)} MB heap size`); } - const projectDisplayName = projectConfig - ? printDisplayName(projectConfig) - : ''; + const projectDisplayName = + projectConfig && projectConfig.displayName + ? printDisplayName(projectConfig) + ' ' + : ''; return ( - `${status} ${projectDisplayName} ${formatTestPath( - globalConfig, - testPath, - )}` + (testDetail.length ? ` (${testDetail.join(', ')})` : '') + `${status} ${projectDisplayName}${formatTestPath(globalConfig, testPath)}` + + (testDetail.length ? ` (${testDetail.join(', ')})` : '') ); }; From a6ae265d16d3b5b0c9c778179a9817ef6d2c95f8 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 22 Aug 2017 15:18:11 -0700 Subject: [PATCH 4/8] Add tests --- .../multi_project_runner.test.js.snap | 20 ++++++++++--------- .../__tests__/multi_project_runner.test.js | 18 ++++++++++++++--- packages/jest-cli/src/reporters/Status.js | 7 ++++++- .../src/reporters/get_result_header.js | 6 ++++-- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap b/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap index e843354d2ac5..2f19c738beca 100644 --- a/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can pass projects or global config 1`] = ` -"Test Suites: 2 failed, 2 total +"Test Suites: 3 failed, 3 total Tests: 0 total Snapshots: 0 total Time: <> @@ -10,29 +10,31 @@ Ran all test suites. `; exports[`can pass projects or global config 2`] = ` -"Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total +"Test Suites: 3 passed, 3 total +Tests: 3 passed, 3 total Snapshots: 0 total Time: <> -Ran all test suites in 2 projects. +Ran all test suites in 3 projects. " `; exports[`can pass projects or global config 3`] = ` -"PASS project1/__tests__/file1.test.js +"PASS BACKEND project1/__tests__/file1.test.js +PASS UI project3/__tests__/file1.test.js PASS project2/__tests__/file1.test.js" `; exports[`can pass projects or global config 4`] = ` -"Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total +"Test Suites: 3 passed, 3 total +Tests: 3 passed, 3 total Snapshots: 0 total Time: <> -Ran all test suites in 2 projects. +Ran all test suites in 3 projects. " `; exports[`can pass projects or global config 5`] = ` -"PASS project1/__tests__/file1.test.js +"PASS BACKEND project1/__tests__/file1.test.js +PASS UI project3/__tests__/file1.test.js PASS project2/__tests__/file1.test.js" `; diff --git a/integration_tests/__tests__/multi_project_runner.test.js b/integration_tests/__tests__/multi_project_runner.test.js index eb94d271bf11..c17aa7d65402 100644 --- a/integration_tests/__tests__/multi_project_runner.test.js +++ b/integration_tests/__tests__/multi_project_runner.test.js @@ -48,13 +48,19 @@ test('can pass projects or global config', () => { test('file1', () => {}); `, 'project1/file1.js': fileContentWithProvidesModule('file1'), - 'project1/jest.config.js': `module.exports = {rootDir: './'}`, + 'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`, 'project2/__tests__/file1.test.js': ` const file1 = require('file1'); test('file1', () => {}); `, 'project2/file1.js': fileContentWithProvidesModule('file1'), 'project2/jest.config.js': `module.exports = {rootDir: './'}`, + 'project3/__tests__/file1.test.js': ` + const file1 = require('file1'); + test('file1', () => {}); + `, + 'project3/file1.js': fileContentWithProvidesModule('file1'), + 'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI'}`, }); let stderr; @@ -68,12 +74,18 @@ test('can pass projects or global config', () => { writeFiles(DIR, { 'global_config.js': ` module.exports = { - projects: ['project1/', 'project2/'], + projects: ['project1/', 'project2/', 'project3/'], }; `, }); - ({stderr} = runJest(DIR, ['-i', '--projects', 'project1', 'project2'])); + ({stderr} = runJest(DIR, [ + '-i', + '--projects', + 'project1', + 'project2', + 'project3', + ])); const result1 = extractSummary(stderr); expect(result1.summary).toMatchSnapshot(); diff --git a/packages/jest-cli/src/reporters/Status.js b/packages/jest-cli/src/reporters/Status.js index 3c63b9d5f4eb..7c2267920893 100644 --- a/packages/jest-cli/src/reporters/Status.js +++ b/packages/jest-cli/src/reporters/Status.js @@ -142,7 +142,12 @@ class Status { this._currentTests.get().forEach(record => { if (record) { const {config, testPath} = record; - const prefix = RUNNING + printDisplayName(config) + ' '; + + const projectDisplayName = config.displayName + ? printDisplayName(config) + ' ' + : ''; + const prefix = RUNNING + projectDisplayName; + content += wrapAnsiString( prefix + diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-cli/src/reporters/get_result_header.js index 1496e55a742e..6725157cade3 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -49,7 +49,9 @@ module.exports = ( : ''; return ( - `${status} ${projectDisplayName}${formatTestPath(globalConfig, testPath)}` + - (testDetail.length ? ` (${testDetail.join(', ')})` : '') + `${status} ${projectDisplayName}${formatTestPath( + projectConfig ? projectConfig : globalConfig, + testPath, + )}` + (testDetail.length ? ` (${testDetail.join(', ')})` : '') ); }; From 1192760ef54854daec7f8536507b72f7d970e3dc Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Tue, 22 Aug 2017 15:38:10 -0700 Subject: [PATCH 5/8] Fix eslint --- packages/jest-cli/src/reporters/get_result_header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-cli/src/reporters/get_result_header.js index 6725157cade3..469eab53d603 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -8,7 +8,7 @@ * @flow */ -import type {Path, GlobalConfig, ProjectConfig} from 'types/Config'; +import type {GlobalConfig, ProjectConfig} from 'types/Config'; import type {TestResult} from 'types/TestResult'; import chalk from 'chalk'; From dc72c42a6cf7828f3ed1d8e930b30fa6fab82bcc Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Fri, 25 Aug 2017 11:39:22 -0700 Subject: [PATCH 6/8] Better handling for non interactive terminals --- .../src/reporters/get_result_header.js | 12 ++++++++++-- packages/jest-cli/src/reporters/utils.js | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-cli/src/reporters/get_result_header.js index 469eab53d603..f1fedc71880a 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -17,8 +17,16 @@ import {formatTestPath, printDisplayName} from './utils'; const LONG_TEST_COLOR = chalk.reset.bold.bgRed; // Explicitly reset for these messages since they can get written out in the // middle of error logging -const FAIL = chalk.reset.inverse.bold.red(' FAIL '); -const PASS = chalk.reset.inverse.bold.green(' PASS '); +const FAIL_TEXT = 'FAIL'; +const PASS_TEXT = 'PASS'; + +const FAIL = chalk.supportsColor + ? chalk.reset.inverse.bold.red(` ${FAIL_TEXT} `) + : FAIL_TEXT; + +const PASS = chalk.supportsColor + ? chalk.reset.inverse.bold.green(` ${PASS_TEXT} `) + : PASS_TEXT; module.exports = ( result: TestResult, diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index fbc84f2d2703..eaa3eb1ca578 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -12,6 +12,7 @@ import type {Path, ProjectConfig} from 'types/Config'; import type {AggregatedResult} from 'types/TestResult'; import path from 'path'; +import isCI from 'is-ci'; import chalk from 'chalk'; import slash from 'slash'; @@ -23,10 +24,19 @@ type SummaryOptions = {| const PROGRESS_BAR_WIDTH = 40; -const printDisplayName = (config: ProjectConfig) => - config.displayName - ? chalk.reset.inverse.white.dim(` ${config.displayName} `) - : ''; +const isInteractive = process.stdout.isTTY && !isCI; + +const printDisplayName = (config: ProjectConfig) => { + const {displayName} = config; + + if (displayName) { + return isInteractive + ? chalk.reset.inverse.white.dim(` ${displayName} `) + : displayName; + } + + return ''; +}; const trimAndFormatPath = ( pad: number, From 1084ae9807ca6fe063d46bb69c0289489e8e2e62 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Fri, 25 Aug 2017 11:54:14 -0700 Subject: [PATCH 7/8] Update tests --- .../__snapshots__/console.test.js.snap | 6 +-- ...e_log_output_when_run_in_band.test.js.snap | 2 +- .../custom_reporters.test.js.snap | 2 +- .../__snapshots__/failures.test.js.snap | 10 ++-- .../__snapshots__/globals.test.js.snap | 14 +++--- .../__snapshots__/jest.config.js.test.js.snap | 4 +- .../module_name_mapper.test.js.snap | 4 +- .../multi_project_runner.test.js.snap | 12 ++--- .../__snapshots__/timeouts.test.js.snap | 2 +- .../__tests__/compare_dom_nodes.test.js | 2 +- .../__tests__/find_related_files.test.js | 2 +- .../__tests__/jest_require_actual.test.js | 8 ++-- .../__tests__/jest_require_mock.test.js | 8 ++-- .../__tests__/log_heap_usage.test.js | 2 +- .../__tests__/multi_project_runner.test.js | 8 ++-- .../__tests__/only_changed.test.js | 46 +++++++++---------- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/console.test.js.snap b/integration_tests/__tests__/__snapshots__/console.test.js.snap index ec173b3fb720..02d08692965e 100644 --- a/integration_tests/__tests__/__snapshots__/console.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/console.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`console printing 1`] = ` -" PASS __tests__/console.test.js +"PASS __tests__/console.test.js ● Console console.log __tests__/console.test.js:11 @@ -43,7 +43,7 @@ exports[`console printing with --verbose 1`] = ` `; exports[`console printing with --verbose 2`] = ` -" PASS __tests__/console.test.js +"PASS __tests__/console.test.js ✓ works just fine " @@ -61,7 +61,7 @@ Ran all test suites. exports[`does not print to console with --silent 1`] = `""`; exports[`does not print to console with --silent 2`] = ` -" PASS __tests__/console.test.js +"PASS __tests__/console.test.js " `; diff --git a/integration_tests/__tests__/__snapshots__/console_log_output_when_run_in_band.test.js.snap b/integration_tests/__tests__/__snapshots__/console_log_output_when_run_in_band.test.js.snap index 2d8e865a6cc6..2df77d9af3fd 100644 --- a/integration_tests/__tests__/__snapshots__/console_log_output_when_run_in_band.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/console_log_output_when_run_in_band.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`prints console.logs when run with forceExit 1`] = ` -" PASS __tests__/a-banana.js +"PASS __tests__/a-banana.js ✓ banana " diff --git a/integration_tests/__tests__/__snapshots__/custom_reporters.test.js.snap b/integration_tests/__tests__/__snapshots__/custom_reporters.test.js.snap index 438c382f298c..94375c276203 100644 --- a/integration_tests/__tests__/__snapshots__/custom_reporters.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/custom_reporters.test.js.snap @@ -65,7 +65,7 @@ Object { `; exports[`Custom Reporters Integration default reporters enabled 1`] = ` -" PASS __tests__/add.test.js +"PASS __tests__/add.test.js Custom Reporters ✓ adds ok diff --git a/integration_tests/__tests__/__snapshots__/failures.test.js.snap b/integration_tests/__tests__/__snapshots__/failures.test.js.snap index bf9554f627e8..3180aa0bea2d 100644 --- a/integration_tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/failures.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`not throwing Error objects 1`] = ` -" FAIL __tests__/throw_number.test.js +"FAIL __tests__/throw_number.test.js ● Test suite failed to run Expected an Error, but \\"1\\" was thrown @@ -10,7 +10,7 @@ exports[`not throwing Error objects 1`] = ` `; exports[`not throwing Error objects 2`] = ` -" FAIL __tests__/throw_string.test.js +"FAIL __tests__/throw_string.test.js ● Test suite failed to run Error @@ -20,7 +20,7 @@ exports[`not throwing Error objects 2`] = ` `; exports[`not throwing Error objects 3`] = ` -" FAIL __tests__/throw_object.test.js +"FAIL __tests__/throw_object.test.js ● Test suite failed to run Error: No message was provided @@ -29,7 +29,7 @@ exports[`not throwing Error objects 3`] = ` `; exports[`not throwing Error objects 4`] = ` -" FAIL __tests__/assertion_count.test.js +"FAIL __tests__/assertion_count.test.js ● .assertions() › throws expect(received).toBeTruthy() Expected value to be truthy, instead received @@ -59,7 +59,7 @@ exports[`not throwing Error objects 4`] = ` `; exports[`works with node assert 1`] = ` -" FAIL __tests__/node_assertion_error.test.js +"FAIL __tests__/node_assertion_error.test.js ● assert assert.equal(received, expected) or assert(received) diff --git a/integration_tests/__tests__/__snapshots__/globals.test.js.snap b/integration_tests/__tests__/__snapshots__/globals.test.js.snap index b40dfdc8f509..f58cbac51190 100644 --- a/integration_tests/__tests__/__snapshots__/globals.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/globals.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`basic test constructs 1`] = ` -" PASS __tests__/basic.test-constructs.test.js +"PASS __tests__/basic.test-constructs.test.js ✓ it ✓ test describe @@ -21,7 +21,7 @@ Ran all test suites. `; exports[`only 1`] = ` -" PASS __tests__/only-constructs.test.js +"PASS __tests__/only-constructs.test.js ✓ test.only ✓ it.only ✓ fit @@ -47,7 +47,7 @@ Ran all test suites. `; exports[`only with expand arg 1`] = ` -" PASS __tests__/only-constructs.test.js +"PASS __tests__/only-constructs.test.js ○ it ✓ test.only ✓ it.only @@ -73,7 +73,7 @@ Ran all test suites. `; exports[`skips 1`] = ` -" PASS __tests__/skips-constructs.test.js +"PASS __tests__/skips-constructs.test.js ✓ it ○ skipped 4 tests xdescribe @@ -96,7 +96,7 @@ Ran all test suites. `; exports[`skips with expand arg 1`] = ` -" PASS __tests__/skips-constructs.test.js +"PASS __tests__/skips-constructs.test.js ✓ it ○ xtest ○ xit @@ -123,7 +123,7 @@ Ran all test suites. `; exports[`tests with no implementation 1`] = ` -" PASS __tests__/only-constructs.test.js +"PASS __tests__/only-constructs.test.js ✓ it ○ skipped 2 tests @@ -140,7 +140,7 @@ Ran all test suites. `; exports[`tests with no implementation with expand arg 1`] = ` -" PASS __tests__/only-constructs.test.js +"PASS __tests__/only-constructs.test.js ✓ it ○ it, no implementation ○ test, no implementation diff --git a/integration_tests/__tests__/__snapshots__/jest.config.js.test.js.snap b/integration_tests/__tests__/__snapshots__/jest.config.js.test.js.snap index 0bfe348ef455..70ecdfd1763f 100644 --- a/integration_tests/__tests__/__snapshots__/jest.config.js.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/jest.config.js.test.js.snap @@ -8,7 +8,7 @@ exports[`traverses directory tree up until it finds jest.config 1`] = ` `; exports[`traverses directory tree up until it finds jest.config 2`] = ` -" PASS ../../../__tests__/a-banana.js +"PASS ../../../__tests__/a-banana.js ✓ banana ✓ abc @@ -25,7 +25,7 @@ Ran all test suites. `; exports[`works with jest.conf.js 1`] = ` -" PASS __tests__/a-banana.js +"PASS __tests__/a-banana.js ✓ banana " diff --git a/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap b/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap index d6895f2ed461..dfd436b63467 100644 --- a/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap @@ -1,14 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`moduleNameMapper correct configuration 1`] = ` -" PASS __tests__/index.js +"PASS __tests__/index.js ✓ moduleNameMapping correct configuration " `; exports[`moduleNameMapper wrong configuration 1`] = ` -" FAIL __tests__/index.js +"FAIL __tests__/index.js ● Test suite failed to run Configuration error: diff --git a/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap b/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap index 2f19c738beca..bc4d06f6247a 100644 --- a/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/multi_project_runner.test.js.snap @@ -19,9 +19,9 @@ Ran all test suites in 3 projects. `; exports[`can pass projects or global config 3`] = ` -"PASS BACKEND project1/__tests__/file1.test.js -PASS UI project3/__tests__/file1.test.js -PASS project2/__tests__/file1.test.js" +"PASS BACKEND project1/__tests__/file1.test.js +PASS UI project3/__tests__/file1.test.js +PASS project2/__tests__/file1.test.js" `; exports[`can pass projects or global config 4`] = ` @@ -34,7 +34,7 @@ Ran all test suites in 3 projects. `; exports[`can pass projects or global config 5`] = ` -"PASS BACKEND project1/__tests__/file1.test.js -PASS UI project3/__tests__/file1.test.js -PASS project2/__tests__/file1.test.js" +"PASS BACKEND project1/__tests__/file1.test.js +PASS UI project3/__tests__/file1.test.js +PASS project2/__tests__/file1.test.js" `; diff --git a/integration_tests/__tests__/__snapshots__/timeouts.test.js.snap b/integration_tests/__tests__/__snapshots__/timeouts.test.js.snap index 13b00317ee7a..e87aad8f0993 100644 --- a/integration_tests/__tests__/__snapshots__/timeouts.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/timeouts.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`does not exceed the timeout 1`] = ` -" PASS __tests__/a-banana.js +"PASS __tests__/a-banana.js ✓ banana " diff --git a/integration_tests/__tests__/compare_dom_nodes.test.js b/integration_tests/__tests__/compare_dom_nodes.test.js index fdee8eeebe70..ee5e985ba452 100644 --- a/integration_tests/__tests__/compare_dom_nodes.test.js +++ b/integration_tests/__tests__/compare_dom_nodes.test.js @@ -17,5 +17,5 @@ skipOnWindows.suite(); test('does not crash when expect involving a DOM node fails', () => { const result = runJest('compare-dom-nodes'); - expect(result.stderr).toContain('FAIL __tests__/failed-assertion.js'); + expect(result.stderr).toContain('FAIL __tests__/failed-assertion.js'); }); diff --git a/integration_tests/__tests__/find_related_files.test.js b/integration_tests/__tests__/find_related_files.test.js index 4628944af8ef..431455803498 100644 --- a/integration_tests/__tests__/find_related_files.test.js +++ b/integration_tests/__tests__/find_related_files.test.js @@ -38,7 +38,7 @@ test('runs tests related to filename', () => { expect(stdout).toMatch(/no tests found/i); const {stderr} = runJest(DIR, ['--findRelatedTests', 'a.js']); - expect(stderr).toMatch('PASS __tests__/test.test.js'); + expect(stderr).toMatch('PASS __tests__/test.test.js'); const summaryMsg = 'Ran all test suites related to files matching /a.js/i.'; expect(stderr).toMatch(summaryMsg); diff --git a/integration_tests/__tests__/jest_require_actual.test.js b/integration_tests/__tests__/jest_require_actual.test.js index ba31d5f208fd..c46dee245eb9 100644 --- a/integration_tests/__tests__/jest_require_actual.test.js +++ b/integration_tests/__tests__/jest_require_actual.test.js @@ -41,8 +41,8 @@ test('understands dependencies using require.requireActual', () => { ({stdout, stderr} = runJest(DIR, ['--findRelatedTests', 'a.js'])); expect(stdout).not.toMatch('No tests found'); - expect(stderr).toMatch('PASS __tests__/a.test.js'); - expect(stderr).not.toMatch('PASS __tests__/b.test.js'); + expect(stderr).toMatch('PASS __tests__/a.test.js'); + expect(stderr).not.toMatch('PASS __tests__/b.test.js'); // change to jest.requireActual writeFiles(DIR, { @@ -55,6 +55,6 @@ test('understands dependencies using require.requireActual', () => { ({stderr, stdout} = runJest(DIR, ['--findRelatedTests', 'a.js'])); expect(stdout).not.toMatch('No tests found'); - expect(stderr).toMatch('PASS __tests__/a.test.js'); - expect(stderr).not.toMatch('PASS __tests__/b.test.js'); + expect(stderr).toMatch('PASS __tests__/a.test.js'); + expect(stderr).not.toMatch('PASS __tests__/b.test.js'); }); diff --git a/integration_tests/__tests__/jest_require_mock.test.js b/integration_tests/__tests__/jest_require_mock.test.js index 766f07677cd0..972edb47a2b4 100644 --- a/integration_tests/__tests__/jest_require_mock.test.js +++ b/integration_tests/__tests__/jest_require_mock.test.js @@ -41,8 +41,8 @@ test('understands dependencies using require.requireMock', () => { ({stdout, stderr} = runJest(DIR, ['--findRelatedTests', 'a.js'])); expect(stdout).not.toMatch('No tests found'); - expect(stderr).toMatch('PASS __tests__/a.test.js'); - expect(stderr).not.toMatch('PASS __tests__/b.test.js'); + expect(stderr).toMatch('PASS __tests__/a.test.js'); + expect(stderr).not.toMatch('PASS __tests__/b.test.js'); // change to jest.requireMock writeFiles(DIR, { @@ -55,6 +55,6 @@ test('understands dependencies using require.requireMock', () => { ({stderr, stdout} = runJest(DIR, ['--findRelatedTests', 'a.js'])); expect(stdout).not.toMatch('No tests found'); - expect(stderr).toMatch('PASS __tests__/a.test.js'); - expect(stderr).not.toMatch('PASS __tests__/b.test.js'); + expect(stderr).toMatch('PASS __tests__/a.test.js'); + expect(stderr).not.toMatch('PASS __tests__/b.test.js'); }); diff --git a/integration_tests/__tests__/log_heap_usage.test.js b/integration_tests/__tests__/log_heap_usage.test.js index fe8e6a006804..1246fb037f1d 100644 --- a/integration_tests/__tests__/log_heap_usage.test.js +++ b/integration_tests/__tests__/log_heap_usage.test.js @@ -30,5 +30,5 @@ test('logs memory usage', () => { }); const {stderr} = runJest(DIR, ['--logHeapUsage']); - expect(stderr).toMatch(/PASS\s{2}__tests__\/a-banana.js.*\d+ MB heap size/); + expect(stderr).toMatch(/PASS\s__tests__\/a-banana.js.*\d+ MB heap size/); }); diff --git a/integration_tests/__tests__/multi_project_runner.test.js b/integration_tests/__tests__/multi_project_runner.test.js index c17aa7d65402..2bb3c5ac817c 100644 --- a/integration_tests/__tests__/multi_project_runner.test.js +++ b/integration_tests/__tests__/multi_project_runner.test.js @@ -137,8 +137,8 @@ test('resolves projects and their properly', () => { ({stderr} = runJest(DIR)); expect(stderr).toMatch('Ran all test suites in 2 projects.'); - expect(stderr).toMatch(' PASS project1/__tests__/test.test.js'); - expect(stderr).toMatch(' PASS project2/__tests__/test.test.js'); + expect(stderr).toMatch('PASS project1/__tests__/test.test.js'); + expect(stderr).toMatch('PASS project2/__tests__/test.test.js'); // Use globs writeFiles(DIR, { @@ -153,8 +153,8 @@ test('resolves projects and their properly', () => { ({stderr} = runJest(DIR)); expect(stderr).toMatch('Ran all test suites in 2 projects.'); - expect(stderr).toMatch(' PASS project1/__tests__/test.test.js'); - expect(stderr).toMatch(' PASS project2/__tests__/test.test.js'); + expect(stderr).toMatch('PASS project1/__tests__/test.test.js'); + expect(stderr).toMatch('PASS project2/__tests__/test.test.js'); // Include two projects that will resolve to the same config writeFiles(DIR, { diff --git a/integration_tests/__tests__/only_changed.test.js b/integration_tests/__tests__/only_changed.test.js index 12edc3342227..e1d591f3ba37 100644 --- a/integration_tests/__tests__/only_changed.test.js +++ b/integration_tests/__tests__/only_changed.test.js @@ -46,7 +46,7 @@ test('run only changed files', () => { expect(stdout).toMatch('No tests found related to files'); ({stderr} = runJest(DIR, ['-o', '--lastCommit'])); - expect(stderr).toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file1.test.js'); writeFiles(DIR, { '__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, @@ -57,9 +57,9 @@ test('run only changed files', () => { ({stderr} = runJest(DIR, ['-o'])); - expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); run(`${GIT} add .`, DIR); run(`${GIT} commit -m "second"`, DIR); @@ -72,9 +72,9 @@ test('run only changed files', () => { }); ({stderr} = runJest(DIR, ['-o'])); - expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); }); test('onlyChanged in config is overwritten by --all or testPathPattern', () => { @@ -101,7 +101,7 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { ); ({stderr} = runJest(DIR, ['--lastCommit'])); - expect(stderr).toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file1.test.js'); writeFiles(DIR, { '__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, @@ -112,9 +112,9 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { ({stderr} = runJest(DIR)); - expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); run(`${GIT} add .`, DIR); run(`${GIT} commit -m "second"`, DIR); @@ -124,7 +124,7 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { ({stderr, stdout} = runJest(DIR, ['file2.test.js'])); expect(stdout).not.toMatch('No tests found related to files'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); expect(stderr).toMatch('1 total'); writeFiles(DIR, { @@ -132,14 +132,14 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { }); ({stderr} = runJest(DIR)); - expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); ({stderr} = runJest(DIR, ['--all'])); - expect(stderr).toMatch('PASS __tests__/file1.test.js'); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); }); test('gets changed files for hg', async () => { @@ -174,7 +174,7 @@ test('gets changed files for hg', async () => { }); ({stdout, stderr} = runJest(DIR, ['-o'])); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); run(`${HG} add .`, DIR); run(`${HG} commit -m "test2"`, DIR); @@ -184,10 +184,10 @@ test('gets changed files for hg', async () => { }); ({stdout, stderr} = runJest(DIR, ['-o'])); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); - expect(stderr).not.toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).not.toMatch('PASS __tests__/file2.test.js'); ({stdout, stderr} = runJest(DIR, ['-o', '--changedFilesWithAncestor'])); - expect(stderr).toMatch('PASS __tests__/file2.test.js'); - expect(stderr).toMatch('PASS __tests__/file3.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); }); From fdb0d1ff6a4321da85176dc01ab0b53385708319 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sat, 26 Aug 2017 21:59:25 -0700 Subject: [PATCH 8/8] Use supportColor --- packages/jest-cli/src/reporters/utils.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index eaa3eb1ca578..d8e8155ce098 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -12,7 +12,6 @@ import type {Path, ProjectConfig} from 'types/Config'; import type {AggregatedResult} from 'types/TestResult'; import path from 'path'; -import isCI from 'is-ci'; import chalk from 'chalk'; import slash from 'slash'; @@ -24,13 +23,11 @@ type SummaryOptions = {| const PROGRESS_BAR_WIDTH = 40; -const isInteractive = process.stdout.isTTY && !isCI; - const printDisplayName = (config: ProjectConfig) => { const {displayName} = config; if (displayName) { - return isInteractive + return chalk.supportsColor ? chalk.reset.inverse.white.dim(` ${displayName} `) : displayName; }