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

fix: correctly generate inline snapshots inside js files #1510

Merged
merged 8 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 6 additions & 2 deletions packages/vitest/src/integrations/snapshot/port/state.ts
Expand Up @@ -87,7 +87,7 @@ export default class SnapshotState {
})
}

private _getInlineSnapshotStack(stacks: ParsedStack[]) {
private _inferInlineSnapshotStack(stacks: ParsedStack[]) {
// if called inside resolves/rejects, stacktrace is different
const promiseIndex = stacks.findIndex(i => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/))
if (promiseIndex !== -1)
Expand All @@ -109,12 +109,16 @@ export default class SnapshotState {
const error = options.error || new Error('Unknown error')
const stacks = parseStacktrace(error, true)
stacks.forEach(i => i.file = slash(i.file))
const stack = this._getInlineSnapshotStack(stacks)
const stack = this._inferInlineSnapshotStack(stacks)
if (!stack) {
throw new Error(
`Vitest: Couldn't infer stack frame for inline snapshot.\n${JSON.stringify(stacks)}`,
)
}
// removing 1 column, because source map points to the wrong
// location for js files, but `column-1` points to the same in both js/ts
// #vite/8657
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
stack.column--
this._inlineSnapshots.push({
snapshot: receivedSerialized,
...stack,
Expand Down