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

Supporting vitest tracking issue #23882

Open
marvinhagemeister opened this issue May 18, 2024 · 3 comments
Open

Supporting vitest tracking issue #23882

marvinhagemeister opened this issue May 18, 2024 · 3 comments

Comments

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented May 18, 2024

This is an issue to track the progress on getting the vitest test runner to work. I'm currently using the test suite from urql to check our progress.

@birkskyum
Copy link
Contributor

birkskyum commented Jun 30, 2024

With the standard example it appear to still (deno 1.44.4+bc8a0e6) hang at:

➜ deno task test              
Task test vitest

 DEV  v1.6.0 

Both w/o DENO_FUTURE=1

nathanwhit added a commit that referenced this issue Jul 30, 2024
Fixes #24756. Fixes
#24796.

This also gets vitest working when using
[`--pool=forks`](https://vitest.dev/guide/improving-performance#pool)
(which is the default as of vitest 2.0). Ref
#23882.

---

This PR resolves a handful of issues with child_process IPC. In
particular:

- We didn't support sending typed array views over IPC
- Opening an IPC channel resulted in the event loop never exiting
- Sending a `null` over IPC would terminate the channel
- There was some UB in the read implementation (transmuting an `&[u8]`
to `&mut [u8]`)
- The `send` method wasn't returning anything, so there was no way to
signal backpressure (this also resulted in the benchmark
`child_process_ipc.mjs` being misleading, as it tried to respect
backpressure. That gave node much worse results at larger message sizes,
and gave us much worse results at smaller message sizes).
- We weren't setting up the `channel` property on the `process` global
(or on the `ChildProcess` object), and also didn't have a way to
ref/unref the channel
- Calling `kill` multiple times (or disconnecting the channel, then
calling kill) would throw an error
- Node couldn't spawn a deno subprocess and communicate with it over IPC
crowlKats pushed a commit that referenced this issue Jul 31, 2024
Fixes #24756. Fixes
#24796.

This also gets vitest working when using
[`--pool=forks`](https://vitest.dev/guide/improving-performance#pool)
(which is the default as of vitest 2.0). Ref
#23882.

---

This PR resolves a handful of issues with child_process IPC. In
particular:

- We didn't support sending typed array views over IPC
- Opening an IPC channel resulted in the event loop never exiting
- Sending a `null` over IPC would terminate the channel
- There was some UB in the read implementation (transmuting an `&[u8]`
to `&mut [u8]`)
- The `send` method wasn't returning anything, so there was no way to
signal backpressure (this also resulted in the benchmark
`child_process_ipc.mjs` being misleading, as it tried to respect
backpressure. That gave node much worse results at larger message sizes,
and gave us much worse results at smaller message sizes).
- We weren't setting up the `channel` property on the `process` global
(or on the `ChildProcess` object), and also didn't have a way to
ref/unref the channel
- Calling `kill` multiple times (or disconnecting the channel, then
calling kill) would throw an error
- Node couldn't spawn a deno subprocess and communicate with it over IPC

(cherry picked from commit cd59fc5)
@birkskyum
Copy link
Contributor

birkskyum commented Jul 31, 2024

After this PR ( #24763 ) I tried this again with deno 1.45.5, and these scenarios does indeed appear to work now:

  • using "--pool=forks" with Vitest 1.x w/ DENO_FUTURE=1
  • using Vitest 2.x w/ DENO_FUTURE=1

Scenarios that doesn't work out-of-the-box, but which will resolve over time / has workarounds:

  • using Deno 1.x without the DENO_FUTURE=1 flag
  • using vitest 1.x without the --pool=forks flag

@birkskyum
Copy link
Contributor

birkskyum commented Sep 10, 2024

Alright, so I'm on Vitest 2 (it defaults to pool: forks) and Deno 2 (deno 2.0.0-rc.1+7bfcb4d) now.

deno.json

{
  "nodeModulesDir": "auto",
  "tasks": {
    "test": "vitest"
  },
  "imports": { "jsdom": "npm:jsdom@^25.0.0", "vitest": "npm:vitest@^2.0.5" }
}

sum.test.ts

import { expect, test } from "vitest";

export function sum(a, b) {
  return a + b
}

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3)
})

vitest.config.ts

import {defineConfig} from "vitest/config";

export default defineConfig({
  test: {
    environment: 'jsdom'
  }
})

Run

  • deno install
  • deno task test

Error:

 DEV  v2.0.5 /Users/admin/repos/deno-kitchensink/vitest-demo


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

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

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot redefine property: location
 ❯ populateGlobal node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/chunks/index.lVXYBqEP.js:374:12
 ❯ Object.setup node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/chunks/index.lVXYBqEP.js:526:33
 ❯ withEnv node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:92:15
 ❯ run node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:116:3
 ❯ runBaseTests node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/chunks/base.CC5R_kgU.js:31:3
 ❯ ForksBaseWorker.executeTests node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/workers/forks.js:25:7
 ❯ execute node_modules/.deno/vitest@2.0.5/node_modules/vitest/dist/worker.js:115:5
 ❯ onMessage node_modules/.deno/tinypool@1.0.1/node_modules/tinypool/dist/entry/process.js:55:20

⎯⎯⎯⎯⎯⎯⎯⎯

If I remove environment: "jsdom" it works:

 DEV  v2.0.5 /Users/admin/repos/deno-kitchensink/vitest-demo

 ✓ sum.test.ts (1)
   ✓ adds 1 + 2 to equal 3

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  23:47:08
   Duration  170ms (transform 15ms, setup 0ms, collect 15ms, tests 1ms, environment 0ms, prepare 46ms)

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

2 participants