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

feat: transform file paths into hyperlinks #8980

Merged
merged 7 commits into from Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/jest-reporters/package.json
Expand Up @@ -25,7 +25,8 @@
"jest-worker": "^24.6.0",
"slash": "^3.0.0",
"source-map": "^0.6.0",
"string-length": "^3.1.0"
"string-length": "^3.1.0",
"terminal-link": "^2.0.0"
},
"devDependencies": {
"@types/exit": "^0.1.30",
Expand Down
14 changes: 10 additions & 4 deletions packages/jest-reporters/src/get_result_header.ts
Expand Up @@ -9,6 +9,7 @@ import {Config} from '@jest/types';
import {TestResult} from '@jest/test-result';
import chalk from 'chalk';
import {formatTestPath, printDisplayName} from './utils';
import terminalLink = require('terminal-link');

const LONG_TEST_COLOR = chalk.reset.bold.bgRed;
// Explicitly reset for these messages since they can get written out in the
Expand All @@ -30,6 +31,13 @@ export default (
projectConfig?: Config.ProjectConfig,
) => {
const testPath = result.testFilePath;
const formattedTestPath = formatTestPath(
projectConfig ? projectConfig : globalConfig,
testPath,
);
const fileLink = terminalLink(formattedTestPath, `file://${testPath}`, {
fallback: () => formattedTestPath,
});
const status =
result.numFailingTests > 0 || result.testExecError ? FAIL : PASS;

Expand All @@ -53,9 +61,7 @@ export default (
: '';

return (
`${status} ${projectDisplayName}${formatTestPath(
projectConfig ? projectConfig : globalConfig,
testPath,
)}` + (testDetail.length ? ` (${testDetail.join(', ')})` : '')
`${status} ${projectDisplayName}${fileLink}` +
(testDetail.length ? ` (${testDetail.join(', ')})` : '')
);
};