Skip to content

vitest 1.6.0 and axios tests fails with error DataCloneError: function transformRequest  #5848

@lcharlois-neotys

Description

@lcharlois-neotys

Describe the bug

Hello,

After upgrading to vitest 1.6.0 we started to face some weird errors during test execution.
Same tests was working and are still working fine with version 1.5.0.

It looks that the issue occurs when an AxiosError is thrown by the test.

When this error occurs vitest stops executing other test but doesn't really report a failure.
The vitest worker looks to crash and to not execute other tests in the same file.

The error looks like the following:

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

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

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
DataCloneError: function transformRequest(data, headers) {
    const contentType = headers.getContentType() || '';
    const ha...<omitted>... } could not be cloned.
 ❯ new DOMException node:internal/per_context/domexception:53:5
 ❯ post node_modules/vitest/dist/vendor/utils.0uYuCbzo.js:10:12
 ❯ node_modules/vitest/dist/vendor/index.8bPxjt7g.js:48:11
 ❯ sendCall node_modules/vitest/dist/vendor/index.8bPxjt7g.js:33:16
 ❯ node_modules/vitest/dist/vendor/rpc.joBhAkyK.js:79:18

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 25, INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2, HIERARCHY_REQUEST_ERR: 3, WRONG_DOCUMENT_ERR: 4, INVALID_CHARACTER_ERR: 5, NO_DATA_ALLOWED_ERR: 6, NO_MODIFICATION_ALLOWED_ERR: 7, NOT_FOUND_ERR: 8, NOT_SUPPORTED_ERR: 9, INUSE_ATTRIBUTE_ERR: 10, INVALID_STATE_ERR: 11, SYNTAX_ERR: 12, INVALID_MODIFICATION_ERR: 13, NAMESPACE_ERR: 14, INVALID_ACCESS_ERR: 15, VALIDATION_ERR: 16, TYPE_MISMATCH_ERR: 17, SECURITY_ERR: 18, NETWORK_ERR: 19, ABORT_ERR: 20, URL_MISMATCH_ERR: 21, QUOTA_EXCEEDED_ERR: 22, TIMEOUT_ERR: 23, INVALID_NODE_TYPE_ERR: 24, DATA_CLONE_ERR: 25 }
This error originated in "apps/api-e2e/src/test-executions/post2.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "Created nominal case". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{
  stackStr: 'DataCloneError: function transformRequest(data, headers) {\n' +
    "    const contentType = headers.getContentType() || '';\n" +
    '    const ha...<omitted>... } could not be cloned.\n' +
    '    at new DOMException (node:internal/per_context/domexception:53:5)\n' +
    '    at post (file:///.../node_modules/vitest/dist/vendor/utils.0uYuCbzo.js:10:12)\n' +
    '    at file:///.../node_modules/vitest/dist/vendor/index.8bPxjt7g.js:48:11\n' +
    '    at new Promise (<anonymous>)\n' +
    '    at sendCall (file:///..../node_modules/vitest/dist/vendor/index.8bPxjt7g.js:33:16)\n' +
    '    at file:///.../node_modules/vitest/dist/vendor/rpc.joBhAkyK.js:79:18',
  nameStr: 'DataCloneError',
  expected: 'undefined',
  actual: 'undefined',
  type: 'Unhandled Error',
  stacks: [
    {
      method: 'new DOMException',
      file: '/node:internal/per_context/domexception',
      line: 53,
      column: 5
    },
    {
      method: 'post',
      file: '/node_modules/vitest/dist/vendor/utils.0uYuCbzo.js',
      line: 10,
      column: 12
    },
    {
      method: '',
      file: '/node_modules/vitest/dist/vendor/index.8bPxjt7g.js',
      line: 48,
      column: 11
    },
    {
      method: 'sendCall',
      file: '/node_modules/vitest/dist/vendor/index.8bPxjt7g.js',
      line: 33,
      column: 16
    },
    {
      method: '',
      file: '/node_modules/vitest/dist/vendor/rpc.joBhAkyK.js',
      line: 79,
      column: 18
    }
  ]
}
 ❯ new DOMException node:internal/per_context/domexception:53:5
 ❯ post node_modules/vitest/dist/vendor/utils.0uYuCbzo.js:10:12
 ❯ node_modules/vitest/dist/vendor/index.8bPxjt7g.js:48:11
 ❯ sendCall node_modules/vitest/dist/vendor/index.8bPxjt7g.js:33:16
 ❯ node_modules/vitest/dist/vendor/rpc.joBhAkyK.js:79:18

Reproduction

Here is a stackblitz allowing to reproduce the bug: https://stackblitz.com/edit/vitest-dev-vitest-henjam?file=test%2Fsuite.test.ts

System Info

System:
    OS: Linux 6.5 Ubuntu 23.10 23.10 (Mantic Minotaur)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz
    Memory: 14.62 GB / 31.01 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.14.0 - /usr/bin/node
    Yarn: 1.22.21 - /usr/bin/yarn
    npm: 10.7.0 - /usr/bin/npm
  Browsers:
    Chrome: 125.0.6422.141
  npmPackages:
    @vitejs/plugin-react-swc: 3.5.0 => 3.5.0 
    @vitest/coverage-v8: 1.6.0 => 1.6.0 
    @vitest/ui: 1.6.0 => 1.6.0 
    vite: 5.0.12 => 5.0.12 
    vitest: 1.6.0 => 1.6.0

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)pr welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions