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

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object #7082

Open
6 tasks done
dimaMachina opened this issue Dec 14, 2024 · 4 comments

Comments

@dimaMachina
Copy link

dimaMachina commented Dec 14, 2024

Describe the bug

I am migrating tests from jest to vitest and ran into an error from this line

deserialize: v => v8.deserialize(Buffer.from(v)),
or this line (these functions are identical, so I am not sure which is right)
deserialize: v => v8.deserialize(Buffer.from(v)),

here is the stack trace

TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
 ❯ Function.from node:buffer:319:9
 ❯ deserialize ../../node_modules/vitest/dist/chunks/resolveConfig.RxKrDli4.js:6716:67
 ❯ EventEmitter.onMessage ../../node_modules/vitest/dist/chunks/index.68735LiX.js:82:17
 ❯ EventEmitter.emit node:events:519:28
 ❯ Object.postMessage ../../node_modules/vitest/dist/chunks/resolveConfig.RxKrDli4.js:6711:39
 ❯ ChildProcess.<anonymous> ../../node_modules/tinypool/dist/index.js:216:30
 ❯ ChildProcess.emit node:events:519:28
 ❯ emit node:internal/child_process:951:14
 ❯ process.processTicksAndRejections node:internal/process/task_queues:83:21

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-qyahuvyc?file=test%2Fbasic.test.ts

v argument in my case is

{
  v: {
    jsonrpc: '2.0',
    method: 'window/logMessage',
    params: {
      type: 1,
      message: 'Received message which is neither a response nor a notification message:\n' +
        '{\n' +
        '    "type": "Buffer",\n' +
        '    "data": [\n' +
        '        255,\n' +
        '        15,\n' +
        '        111,\n' +
        '        34,\n' +
        '        1,\n' +
        '        116,\n' +
        '        34,\n' +
        '        1,\n' +
        '        115,\n' +
        '        34,\n' +
        '        1,\n' +
        '        105,\n' +
        '        34,\n' +
        '        21,\n' +
        '        71,\n' +
        '        101,\n' +
        '        112,\n' +
        '        110,\n' +
        '        56,\n' +
        '        49,\n' +
        '        99,\n' +
        '        73,\n' +
        '        122,\n' +
        '        98,\n' +
        '        52,\n' +
        '        102,\n' +
        '        55,\n' +
        '        106,\n' +
        '        105,\n' +
        '        77,\n' +
        '        50,\n' +
        '        57,\n' +
        '        48,\n' +
        '        122,\n' +
        '        108,\n' +
        '        34,\n' +
        '        1,\n' +
        '        114,\n' +
        '        95,\n' +
        '        34,\n' +
        '        1,\n' +
        '        101,\n' +
        '        95,\n' +
        '        123,\n' +
        '        4\n' +
        '    ]\n' +
        '}'
    }
  }
}

System Info

System:
    OS: macOS 13.4
    CPU: (12) x64 Apple M2 Max
    Memory: 8.74 GB / 96.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.local/state/fnm_multishells/55235_1734137834788/bin/node
    Yarn: 1.22.22 - ~/.local/state/fnm_multishells/55235_1734137834788/bin/yarn
    npm: 10.8.2 - ~/.local/state/fnm_multishells/55235_1734137834788/bin/npm
    Watchman: 2024.08.05.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 128.0.6613.114
    Safari: 16.5
  npmPackages:
    vitest: ^2.1.8 => 2.1.8

Used Package Manager

yarn

Validations

Copy link

Hello @dimaMachina. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@dimaMachina
Copy link
Author

@AriPerkkio repro

@hi-ogawa
Copy link
Contributor

Probably vscode-jsonrpc/node is interfering with IPC channel used by Vitest. This is a minimal repro:

https://stackblitz.com/edit/vitest-dev-vitest-iqv9ueqx?file=test%2Frepro.test.ts

import { test } from 'vitest';

test('repro', async () => {
  process.send!({ repro: 'boom!!' });
});

From your sample code, I'm not sure if actual IPC is necessary since you didn't manage a parent process. Maybe isn't it intended to mock out process here somehow?

      reader = new IPCMessageReader(process);
      writer = new IPCMessageWriter(process);

@dimaMachina
Copy link
Author

From your sample code, I'm not sure if actual IPC is necessary since you didn't manage a parent process. Maybe isn't it intended to mock out process here somehow?

idk, current tests worked fine with jest but not with vitest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants