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

Can't update inline snapshot in Browser Mode #5263

Closed
6 tasks done
BenoitZugmeyer opened this issue Feb 21, 2024 · 1 comment · Fixed by #5278
Closed
6 tasks done

Can't update inline snapshot in Browser Mode #5263

BenoitZugmeyer opened this issue Feb 21, 2024 · 1 comment · Fixed by #5278
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@BenoitZugmeyer
Copy link

Describe the bug

I am reopening an issue for the previously closed issue #2327.

When using vitest in Browser Mode, an error occurs when updating inline snapshots.

I believe this is because:

  • in Browser Mode, vite:resolve is using the browser entry point to resolve dependencies
  • magic-string (this file) is loaded as a module
  • it imports @jridgewell/sourcemap-codec, which has an UMD bundle as browser entry point (see its package.json)

Importing an UMD bundle from an ES module doesn't work, hence the error.

Reproduction

git clone https://gist.github.com/BenoitZugmeyer/a93d80dbbbadc9e4173a55d82874a875 repro
cd repro
npm ci
npm test -- -u --run

Output:

> test
> vitest -u --run


 RUN  v1.3.1 /home/alk/tmp/repro-vitest-error/repro
      Browser runner started at http://localhost:5173/


⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
SyntaxError: The requested module '/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js?v=15cdcfd9' does not provide an export named 'encode'
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files   (1)
      Tests   (1)
     Errors  1 error
   Start at  23:53:31
   Duration  2.22s (transform 0ms, setup 0ms, collect 7ms, tests 0ms, environment 0ms, prepare 0ms)

System Info

System:
    OS: Linux 6.7 Arch Linux
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 21.55 GB / 31.14 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - /usr/bin/node
    npm: 10.4.0 - /usr/bin/npm
  Browsers:
    Chromium: 122.0.6261.39
  npmPackages:
    @vitest/browser: ^1.3.1 => 1.3.1
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

npm

Validations

@hi-ogawa hi-ogawa added feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Feb 23, 2024
hi-ogawa added a commit to hi-ogawa/reproductions that referenced this issue Feb 23, 2024
@hi-ogawa
Copy link
Contributor

Thanks for the concise reproduction and investigation! I put up a PR to fix this, but I think you can also do the same from your configuration as a temporary workaround:

import { defineConfig } from "vitest/config"

export default defineConfig({
  optimizeDeps: {
    include: ["vitest > @vitest/snapshot > magic-string"],
  },
  test: {
    browser: {
      enabled: true,
      name: "chrome",
    },
  },
});

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants