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

Support Vitest #4145

Open
birkskyum opened this issue Aug 13, 2023 · 21 comments
Open

Support Vitest #4145

birkskyum opened this issue Aug 13, 2023 · 21 comments
Labels
bug Something isn't working

Comments

@birkskyum
Copy link
Collaborator

birkskyum commented Aug 13, 2023

Vitest - website - github

What version of Bun is running?

0.8.1

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

bun --bun x vitest

What is the expected behavior?

No error

What do you see instead?

SyntaxError: Import named 'Console' not found in module 'node:console'.

Additional information

Related to:

@birkskyum birkskyum added the bug Something isn't working label Aug 13, 2023
@birkskyum
Copy link
Collaborator Author

It seems like the console.ts / console.js that contains:

export default console

Might also have to export the named Console in order to be node compatible.

@paperdave
Copy link
Collaborator

paperdave commented Aug 15, 2023

Console issue you are seeing is #3625. It's a constructor that returns a console object that has stdout/stderr redirected

@mnik01
Copy link

mnik01 commented Sep 9, 2023

Any workarounds?

@ghiscoding
Copy link

might also be worth to know that Vitest itself also have a PR, in draft, to support Bun by using ShadowRealm with this description

Currently, all jsdom tests are failing because bun doesn't seem to correctly support VM module.

@paperdave
Copy link
Collaborator

paperdave commented Sep 19, 2023

console.console is implemented in the next release
that might fix vitest

@birkskyum
Copy link
Collaborator Author

birkskyum commented Sep 19, 2023

It's progress, but I get this:

vitest onmain [!?] 
➜ bun --bun x vitest

 DEV  v0.34.4 /Users/admin/repos/vitest

[bun] Warning: worker_threads.Worker option "argv" is not implemented.
[bun] Warning: worker_threads.Worker option "execArgv" is not implemented.
[bun] Warning: worker_threads.Worker option "resourceLimits" is not implemented.

@AriPerkkio
Copy link

@nyxb
Copy link

nyxb commented Sep 23, 2023

have the same:

[bun] Warning: worker_threads.Worker option "argv" is not implemented.
[bun] Warning: worker_threads.Worker option "execArgv" is not implemented.
[bun] Warning: worker_threads.Worker option "resourceLimits" is not implemented.

and cant ignore tests doesnt finish

and get this if i want cancel need to do it 1000 times before exit:

RangeError: exitCode must be between 0 and 127
      at /Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17951:8
      at _keypressHandler (/Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17946:34)
      at /Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17990:10
      at keypressHandler (/Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17989:33)
      at node:readline:114:54
      at onData (node:readline:476:34)
      at addChunk (node:stream:1940:42)
      at readableAddChunk (node:stream:1894:58)
Cancelling test run. Press CTRL+c again to exit forcefully.

17946 |   async function _keypressHandler(str, key) {
17947 |     if (str === "" || str === "\x1B" || key && key.ctrl && key.name === "c") {
17948 |       if (!ctx.isCancelling) {
17949 |         ctx.logger.logUpdate.clear();
17950 |         ctx.logger.log(c.red("Cancelling test run. Press CTRL+c again to exit forcefully.\n"));
17951 |         process.exitCode = 130;
            ^
RangeError: exitCode must be between 0 and 127
      at /Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17951:8
      at _keypressHandler (/Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17946:34)
      at /Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17990:10
      at keypressHandler (/Users/nyxb/projects/github_packages/eslint-config/node_modules/vitest/dist/vendor-node.81dd929c.js:17989:33)
      at node:readline:114:54
      at onData (node:readline:476:34)
      at addChunk (node:stream:1940:42)
      at readableAddChunk (node:stream:1894:58)

@IndranilKhedkar
Copy link

Same here - error: "vitest" exited with code 9 (SIGKILL)

image

@pafeltowicz
Copy link

I have same problem

@birkskyum
Copy link
Collaborator Author

Hmm... if I now make a small test file like this , and run, it seems to just freeze:

➜ bun --bun x vitest

 DEV  v1.1.1 /Users/admin/repos/histoire-vue3-starter

@MkSavin
Copy link

MkSavin commented Jan 10, 2024

The argument implementation warning was removed in version 1.0.22, but vitest still doesn't work.
It turns out that we need to wait for the implementation of bun's virtualization or the integration of shadowrealm api in vitest

@Rhymmor
Copy link

Rhymmor commented Mar 28, 2024

Getting this error while running bun x -b vitest run.

OS: Darwin 23.1.0 arm64 arm

Bun v1.0.35, Vitest v1.4.0

> bun x -b vitest run  

82 |                                    `You can download it from ${msvcDownloadLink}`,
83 |                            { cause: error }
84 |                    );
85 |            }
86 | 
87 |            throw new Error(
             ^
error: Cannot find module @rollup/rollup-darwin-arm64. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
 cause: {
  "name": "ResolveMessage",
  "position": null,
  "message": "Cannot find module \"@rollup/rollup-darwin-arm64\" from \"***/rollup/dist/native.js\"",
  "level": "error",
  "specifier": "@rollup/rollup-darwin-arm64",
  "importKind": "require-call",
  "referrer": "***/rollup/dist/native.js"
}

      at requireWithFriendlyError (***/node_modules/rollup/dist/native.js:87:9)
      at ***/node_modules/rollup/dist/native.js:96:48

@redbit86k
Copy link

Maybe interesting fact:

if you take the node:20 docker image and install bun there, then our
bun run vitest --coverage --run --watch false
completes without problems.

if we use the oven:bun image it just hangs.
Hope this fact maybe helps someone as a workaround if possible...

@birkskyum
Copy link
Collaborator Author

With the node one, does it pass with the '--bun' flag?

@redbit86k
Copy link

Sadly
bun run --bun vitest --coverage --run
does not finish.
Also does not work on my local dev machine (ubuntu24lts), just hangs

@birkskyum
Copy link
Collaborator Author

I know bun has a competing bun test, but as of writing vitest is quickly becoming a staple, so it would be great if bun could support it as well. If people can adopt bun in their projects, and then consider swapping the test runner, that would give a much nicer migration story towards bun.

https://2023.stateofjs.com/en-US/libraries/#tools_arrows

Screenshot 2024-07-01 at 00 12 29 Screenshot 2024-07-01 at 00 16 58

@birkskyum
Copy link
Collaborator Author

Still issue with vitest 2.x / bun 1.1.22-canary.85+cacbaba52

➜ bun --bun x vitest

 DEV  v2.0.5

@marviobezerra
Copy link

+1

1 similar comment
@JarekToro
Copy link

+1

@birkskyum
Copy link
Collaborator Author

Tried with latest stabe bun 1.1.27 - it hangs, and also makes these weird symbols instead of interrupting why I try to escape it

Screenshot 2024-09-10 at 15 20 05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests