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

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

Closed
6 tasks done
lcharlois-neotys opened this issue Jun 5, 2024 · 10 comments
Closed
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@lcharlois-neotys
Copy link

lcharlois-neotys commented Jun 5, 2024

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

@Crispy-rw
Copy link

Had the same error Today

@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jun 11, 2024
@sheremet-va
Copy link
Member

sheremet-va commented Jun 11, 2024

Looks like axios's toJSON doesn't return json-compatible object. We still need to process it:

return val.toJSON()

Like here:

return serializeError(val.toJSON(), seen)

@lcharlois-neotys
Copy link
Author

@sheremet-va If the change is to apply the same logic at line 48 than line 40, I guess I can do it.
By the way, is there a chance to have this fix in a 1.6.x or more genreally on 1.x version?
And if yes is there something special to do?

@sheremet-va
Copy link
Member

@sheremet-va If the change is to apply the same logic at line 48 than line 40, I guess I can do it. By the way, is there a chance to have this fix in a 1.6.x or more genreally on 1.x version? And if yes is there something special to do?

The change is applying the logic and adding a test.

@lcharlois-neotys
Copy link
Author

Do you have an idea on how to write a such test?

@sheremet-va
Copy link
Member

Just call the function with previously failing parameters here:

describe('error serialize', () => {

@lcharlois-neotys
Copy link
Author

lcharlois-neotys commented Jun 13, 2024

Hello, I took a look unfortunately I don't know how to write a test the fails with the current implementation.
Is it possible to get help on this?

@eddienubes
Copy link
Contributor

eddienubes commented Jun 14, 2024

Also faced this issue testing axios clients.

Submitted a PR fixing that - #5884

@lcharlois-neotys
Copy link
Author

Hello @sheremet-va ,

Do you know if it is planned to releas a 1.6.1 or a 1.7.0 version with this fix?

@sheremet-va
Copy link
Member

Hello @sheremet-va ,

Do you know if it is planned to releas a 1.6.1 or a 1.7.0 version with this fix?

The next release is 2.0. If this bug is bothering you, you can stay at 1.5.3.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome
Projects
None yet
Development

No branches or pull requests

4 participants