feat(reporters): add OSC 8 hyperlinks for stacktrace file paths#9647
feat(reporters): add OSC 8 hyperlinks for stacktrace file paths#9647Ujjwaljain16 wants to merge 7 commits intovitest-dev:mainfrom
Conversation
| export function createTerminalLink(text: string, file: string): string { | ||
| // Graceful fallback for non-TTY or CI | ||
| // Also check VITEST_FORCE_TTY to allow explicit disabling | ||
| if (!process.stdout?.isTTY || process.env.CI || process.env.VITEST_FORCE_TTY === 'false') { |
There was a problem hiding this comment.
That checks seems incomplete
- logger can accept a different
stdoutimplementation, so usingprocess.stdoutis not sufficient CIis not a sufficient check for a CI environment, we haveisCIalready that you can use- I am conflicted on
VITEST_FORCE_TTY: 'false', what do you think, @AriPerkkio? Feels like the presence of a ENV should be a check (likeNO_COLOR=anything)
There was a problem hiding this comment.
Please no new environmental variables for TTY checking.
I think this function should be no-op only when these two indicate so:
vitest/packages/vitest/src/node/logger.ts
Line 52 in 0583f06
isCI from:
vitest/packages/vitest/src/utils/env.ts
Line 15 in 0583f06
There was a problem hiding this comment.
We also have import c from 'tinyrainbow'; c.isColorSupported. Didn't it also had nice baseline check?
| const originalEnv = process.env | ||
| let originalIsTTY: boolean | undefined | ||
|
|
||
| afterEach(() => { |
There was a problem hiding this comment.
Instead of all of this mocking, it might be better to turn createTerminalLink into a pure function that accepts these as options
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
This would be also more beneficial in import durations reporting because we truncate the file name which does actually break IDE (e.g. vscode's integrated terminal) to auto link the file vitest/packages/vitest/src/node/reporters/base.ts Lines 714 to 715 in a628859 |
| try { | ||
| const href = pathToFileURL(file).href | ||
| // OSC 8 escape sequence | ||
| return `\u001B]8;;${href}\u001B\\${text}\u001B]8;;\u001B\\` |
There was a problem hiding this comment.
Looking at https://github.com/sindresorhus/ansi-escapes/blob/6db12c839dafc906cbceda299026d8e78e501478/base.js#L19-L23, this might need some tmux specific handling
Description
This adds optional OSC 8 hyperlink support to stacktrace file paths in terminal output. This allows compatible terminals (Ghostty, iTerm, VS Code, etc.) to make file paths clickable even if they wrap or contain special characters.
stdoutis TTYVITEST_FORCE_TTY=falsepathToFileURLfor cross-platform support (handles Windows paths correctly)Resolves #9565
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.