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 e843354d2ac5..bc4d06f6247a 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 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`] = ` -"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 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 24d8d3b29377..1ff2fa796c16 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(); @@ -161,8 +173,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, { @@ -177,8 +189,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'); }); diff --git a/packages/jest-cli/src/reporters/Status.js b/packages/jest-cli/src/reporters/Status.js index 428a8b35e77f..7c2267920893 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,16 @@ class Status { this._currentTests.get().forEach(record => { if (record) { const {config, testPath} = record; + + const projectDisplayName = config.displayName + ? printDisplayName(config) + ' ' + : ''; + const prefix = RUNNING + projectDisplayName; + 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/__tests__/default_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js index 45710329751f..dd96671c1a13 100644 --- a/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js @@ -62,7 +62,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); @@ -75,7 +75,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/default_reporter.js b/packages/jest-cli/src/reporters/default_reporter.js index 84eb33eb6258..ded771dbffb2 100644 --- a/packages/jest-cli/src/reporters/default_reporter.js +++ b/packages/jest-cli/src/reporters/default_reporter.js @@ -174,7 +174,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..f1fedc71880a 100644 --- a/packages/jest-cli/src/reporters/get_result_header.js +++ b/packages/jest-cli/src/reporters/get_result_header.js @@ -8,19 +8,31 @@ * @flow */ -import type {Path} from 'types/Config'; +import type {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 // 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'; -module.exports = (result: TestResult, config: {rootDir: Path}) => { +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, + globalConfig: GlobalConfig, + projectConfig?: ProjectConfig, +) => { const testPath = result.testFilePath; const status = result.numFailingTests > 0 || result.testExecError ? FAIL : PASS; @@ -39,8 +51,15 @@ module.exports = (result: TestResult, config: {rootDir: Path}) => { testDetail.push(`${toMB(result.memoryUsage)} MB heap size`); } + const projectDisplayName = + projectConfig && projectConfig.displayName + ? printDisplayName(projectConfig) + ' ' + : ''; + return ( - `${status} ${formatTestPath(config, testPath)}` + - (testDetail.length ? ` (${testDetail.join(', ')})` : '') + `${status} ${projectDisplayName}${formatTestPath( + projectConfig ? projectConfig : 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..d8e8155ce098 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,18 @@ type SummaryOptions = {| const PROGRESS_BAR_WIDTH = 40; +const printDisplayName = (config: ProjectConfig) => { + const {displayName} = config; + + if (displayName) { + return chalk.supportsColor + ? chalk.reset.inverse.white.dim(` ${displayName} `) + : displayName; + } + + return ''; +}; + const trimAndFormatPath = ( pad: number, config: {rootDir: Path}, @@ -235,6 +247,7 @@ module.exports = { formatTestPath, getSummary, pluralize, + printDisplayName, relativePath, trimAndFormatPath, wrapAnsiString, diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js index decf9f41ab5b..c92558f6fba5 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 c823adc13602..1f6e24290a7e 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -453,6 +453,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 0aa0f32e9a47..66139c1ad5ea 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 2daf3bfa41f7..45c5aef89582 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 47ab2ac9c116..33e809f8d7a7 100644 --- a/types/Config.js +++ b/types/Config.js @@ -77,6 +77,7 @@ export type InitialOptions = { coveragePathIgnorePatterns?: Array, coverageReporters?: Array, coverageThreshold?: {global: {[key: string]: number}}, + displayName?: string, expand?: boolean, findRelatedTests?: boolean, forceExit?: boolean, @@ -187,6 +188,7 @@ export type ProjectConfig = {| cacheDirectory: Path, clearMocks: boolean, coveragePathIgnorePatterns: Array, + displayName: ?string, globals: ConfigGlobals, haste: HasteConfig, moduleDirectories: Array,