vitest icon indicating copy to clipboard operation
vitest copied to clipboard

`toMatchInlineSnapshot` doesn't work with template literal tags, again

Open zardoy opened this issue 2 years ago • 3 comments

Describe the bug

I got used to behavior is that pressing u does nothing most of the time. The most annoying thing is that it's always saying that snapshot is successfully updated, even if it doesn't for some reason :(

So now I encountered behavior where vitests doesn't update even with -u flag.

It should've been fixed previously https://github.com/vitest-dev/vitest/issues/723

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-hwjahu?file=test%2Fsuite.test.ts,package.json&initialPath=vitest

But the example object can be simplified.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vitest: 0.23.2 => 0.23.2

Used Package Manager

npm

Validations

zardoy avatar Sep 15 '22 12:09 zardoy

Yeah, Vitest has this RegExp to detect snapshots:

https://github.com/vitest-dev/vitest/blob/95da4d66933db46da368d5d66f422afd26fba4c1/packages/vitest/src/integrations/snapshot/port/inlineSnapshot.ts#L74

So, if you add a comment it doesn't work. PR welcome.

sheremet-va avatar Sep 15 '22 15:09 sheremet-va

@sheremet-va thanks! I'll take into whats happened with previous regexp.

BUT why does Vitest tell me that snapshot was successfully updated, when it wasn't? Isn't that misleading? I was already discussing that before, that it shouldn't show all-green and then red on next run without -u.

zardoy avatar Sep 15 '22 15:09 zardoy

BUT why does Vitest tell me that snapshot was successfully updated, when it wasn't? Isn't that misleading? I was already discussing that before, that it shouldn't show all-green and then red on next run without -u.

It didn't detect any snapshots actually, so it just showed you default message. I am not against "no snapshots found" message in this case. And show a number of updated snapshots, if there are updated snapshots.

sheremet-va avatar Sep 15 '22 15:09 sheremet-va

Hey @sheremet-va, is this issue still open? If so, can I work on it?

HeitorMC avatar Jan 24 '23 18:01 HeitorMC

Hey @sheremet-va, is this issue still open? If so, can I work on it?

No, I think it was fixed, but we forgot to close the issue since it's not linked automatically

sheremet-va avatar Jan 24 '23 21:01 sheremet-va