fix(utils): decode URL-encoded paths in stacktrace parser#9618
fix(utils): decode URL-encoded paths in stacktrace parser#961822mb wants to merge 3 commits intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Browser stacktraces contain URL-encoded paths (e.g. %20 for whitespace). Decode them using `decodeURI` API so mock resolution works for paths with whitespaces. fix vitest-dev#7788, fix vitest-dev#9500
d25c9b6 to
71d5330
Compare
|
Can you add test case for non browser tests for #9500? |
|
Ok,I'll address it. |
Add a core test case where `vi.mock()` caller is in a directory with spaces. Also update test titles to reflect the actual issue.
There was a problem hiding this comment.
It looks like the same test is passing on main already.
And now I'm trying to verify the reproduction of #9500. It fails on stackblitz but it passes when downloaded locally. It's possible that that was stackblitz thing.
That said, having this is fine, so we can keep it.
There was a problem hiding this comment.
Applying decodeURI on non browser mode can cause breaking stacktrace e.g. repro-%20.test.ts becoming repro- .test.ts.
FAIL test/repro/repro-%20.test.ts > foo
AssertionError: expected +0 to be 1 // Object.is equality
- Expected
+ Received
- 1
+ 0
❯ test/repro/repro- .test.ts:7:13Vite itself might not reliably support such file path on client, but Vitest should probably try to support where possible, so this decodeURI should happen only for browser mode. I'm not sure how we can detect that though.
Also, for the test case, if we are fixing parseStacktrace, it would be nice to have tests to check error stacktrace like above.
Description
When running browser tests with
vi.mock()in directories containing spaces, the mock resolution fails because browser stack traces contain URL-encoded paths (e.g.,space%20dir/file.tsinstead ofspace dir/file.ts).This PR adds
decodeURIto both V8 and Firefox/Safari stack trace parsers inpackages/utils/src/source-map.ts.Using
decodeURIinstead ofdecodeURIComponentto avoid decoding URI-special characters like/.Resolves #7788, Resolves #9500
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:.