oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.48k stars 2.71k forks source link

Support Vitest #4145

Open birkskyum opened 1 year ago

birkskyum commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Console issue you are seeing is https://github.com/oven-sh/bun/issues/3625. It's a constructor that returns a console object that has stdout/stderr redirected

mnik01 commented 1 year ago

Any workarounds?

ghiscoding commented 1 year ago

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 commented 1 year ago

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

birkskyum commented 1 year ago

It's progress, but I get this:

vitest on  main [!?] 
➜ 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 commented 1 year ago

Those warning can be ignored, see https://github.com/tinylibs/tinypool/pull/70/files#diff-478191b8d0c43c3d24bfda206ff15909923b8b5a89eec9c967376feded4edfa7R9

nyxb commented 1 year ago

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 commented 11 months ago

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

image
pafeltowicz commented 11 months ago

I have same problem

birkskyum commented 9 months ago

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 commented 8 months ago

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 commented 6 months ago

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 commented 3 months ago

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 commented 3 months ago

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

redbit86k commented 3 months ago

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

birkskyum commented 3 months ago

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 commented 1 month ago

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

➜ bun --bun x vitest

 DEV  v2.0.5
marviobezerra commented 1 month ago

+1

JarekToro commented 3 weeks ago

+1

birkskyum commented 3 weeks ago

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