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 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- `[jest-runner]` Warn if a worker had to be force exited ([#8206](https://github.com/facebook/jest/pull/8206))
- `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867))
- `[jest-worker]` [**BREAKING**] Return a promise from `end()`, resolving with the information whether workers exited gracefully ([#8206](https://github.com/facebook/jest/pull/8206))
- `[jest-reporters]` Transform file paths into hyperlinks ([#8980](https://github.com/facebook/jest/pull/8980))

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
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
38 changes: 38 additions & 0 deletions packages/jest-reporters/src/__tests__/get_result_header.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {makeGlobalConfig} from '../../../../TestUtils';
import getResultHeader from '../get_result_header';
const terminalLink = require('terminal-link');

jest.mock('terminal-link', () => jest.fn(() => 'wannabehyperlink'));

const testResult = {
testFilePath: '/foo',
};

const globalConfig = makeGlobalConfig();

beforeEach(() => {
terminalLink.mockClear();
lekterable marked this conversation as resolved.
Show resolved Hide resolved
});

test('should call `terminal-link` correctly', () => {
getResultHeader(testResult, globalConfig);

expect(terminalLink).toBeCalledWith(
expect.stringContaining('foo'),
'file:///foo',
expect.objectContaining({fallback: expect.any(Function)}),
);
});

test('should render the terminal link', () => {
const result = getResultHeader(testResult, globalConfig);

expect(result).toContain('wannabehyperlink');
});
14 changes: 10 additions & 4 deletions packages/jest-reporters/src/get_result_header.ts
Original file line number Diff line number Diff line change
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(', ')})` : '')
);
};
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13130,6 +13130,14 @@ supports-color@^7.0.0:
dependencies:
has-flag "^4.0.0"

supports-hyperlinks@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-2.0.0.tgz#b1b94a159e9df00b0a554b2d5f0e0a89690334b0"
integrity sha512-bFhn0MQ8qefLyJ3K7PpHiPUTuTVPWw6RXfaMeV6xgJLXtBbszyboz1bvGTVv4R0YpQm2DqlXXn0fFHhxUHVE5w==
dependencies:
has-flag "^4.0.0"
supports-color "^7.0.0"

svgo@^1.0.0, svgo@^1.0.5:
version "1.3.0"
resolved "https://registry.yarnpkg.com/svgo/-/svgo-1.3.0.tgz#bae51ba95ded9a33a36b7c46ce9c359ae9154313"
Expand Down Expand Up @@ -13245,6 +13253,14 @@ tempfile@^2.0.0:
temp-dir "^1.0.0"
uuid "^3.0.1"

terminal-link@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.0.0.tgz#daa5d9893d57d3a09f981e1a45be37daba3f0ce6"
integrity sha512-rdBAY35jUvVapqCuhehjenLbYY73cVgRQ6podD6u9EDBomBBHjCOtmq2InPgPpTysOIOsQ5PdBzwSC/sKjv6ew==
dependencies:
ansi-escapes "^4.2.1"
supports-hyperlinks "^2.0.0"

terser-webpack-plugin@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.1.tgz#61b18e40eaee5be97e771cdbb10ed1280888c2b4"
Expand Down