vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.94k stars 1.16k forks source link

DataCloneError when using snapshotFormat.plugins #4134

Closed ambarvm closed 1 year ago

ambarvm commented 1 year ago

Describe the bug

Using snapshotFormat.plugins in vite.config.ts results in this error. The error is very different on stackblitz but I think this local error shows more relevant info.

DataCloneError: (val) => Array.isArray(val) could not be cloned.
 ❯ new DOMException node:internal/per_context/domexception:53:5
 ❯ WorkerInfo.postTask node_modules/.pnpm/tinypool@0.7.0/node_modules/tinypool/dist/esm/index.js:440:17
 ❯ ThreadPool.runTask node_modules/.pnpm/tinypool@0.7.0/node_modules/tinypool/dist/esm/index.js:732:16
 ❯ Tinypool.run node_modules/.pnpm/tinypool@0.7.0/node_modules/tinypool/dist/esm/index.js:808:38
 ❯ runFiles node_modules/.pnpm/vitest@0.34.4/node_modules/vitest/dist/vendor-node.b14cb9ad.js:7328:20
 ❯ node_modules/.pnpm/vitest@0.34.4/node_modules/vitest/dist/vendor-node.b14cb9ad.js:7370:98
 ❯ Object.runTests node_modules/.pnpm/vitest@0.34.4/node_modules/vitest/dist/vendor-node.b14cb9ad.js:7370:58
 ❯ Object.runTests node_modules/.pnpm/vitest@0.34.4/node_modules/vitest/dist/vendor-node.b14cb9ad.js:7661:5

If run withvitest --threads=false, a different error is shown

 FAIL  test/suite.test.ts > suite name > snapshot
PrettyFormatPluginError: plugins[p].test is not a function
 ❯ findPlugin file:/home/projects/vitest-dev-vitest-vr4kaa/node_modules/pretty-format/build/index.js:302:22
 ❯ format file:/home/projects/vitest-dev-vitest-vr4kaa/node_modules/pretty-format/build/index.js:451:32
 ❯ file:/home/projects/vitest-dev-vitest-vr4kaa/test/suite.test.ts:11:50

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-vr4kaa?file=vite.config.ts

System Info

System:
    OS: macOS 13.5.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.59 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.6.1 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 115.0.5790.170
    Safari: 16.6
  npmPackages:
    vitest: ^0.34.4 => 0.34.4

Used Package Manager

pnpm

Validations

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

sheremet-va commented 1 year ago

Plugins option is not supported there. Use expect.addSnapshotSerializer inside the setup file.

But Vitest should print the warning and remove all function options from the type.