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

Make bun test isolated #6024

Open
erwinstone opened this issue Sep 25, 2023 · 1 comment
Open

Make bun test isolated #6024

erwinstone opened this issue Sep 25, 2023 · 1 comment
Labels
bun:test Something related to the `bun test` runner enhancement New feature or request

Comments

@erwinstone
Copy link

erwinstone commented Sep 25, 2023

What is the problem this feature would solve?

Leaks across files.

Example:

// data.ts
export const data = {
  name: 'User',
}
// test1.test.ts
import { expect, test } from 'bun:test'
import { data } from './data'

data.name = 'Admin'

test('test-1', () => {
  expect(data).toEqual({
    name: 'Admin',
  })
})
// test2.test.ts
import { expect, test } from 'bun:test'
import { data } from './data'

test('test-2', () => {
  expect(data).toEqual({
    name: 'User',
  })
})

test2 will fail because the data has been modified in test1.

bun test v1.0.3 (25e69c71)

test/test1.test.ts:
✓ test-1 [0.08ms]

test/test2.test.ts:
1 | import { expect, test } from 'bun:test'
2 | import { data } from './data'
3 | 
4 | test('test-2', () => {
5 |   expect(data).toEqual({
      ^
error: expect(received).toEqual(expected)

  {
+   name: "Admin"
-   name: "User"
  }

- Expected  - 1
+ Received  + 1

In vitest and jest, both tests pass.

What is the feature you are proposing to solve the problem?

Isolated by default, but can be disabled using a parameter.
Ref: https://vitest.dev/config/#isolate

What alternatives have you considered?

No response

@erwinstone erwinstone added the enhancement New feature or request label Sep 25, 2023
@Electroid Electroid added the bun:test Something related to the `bun test` runner label Sep 25, 2023
@Electroid Electroid changed the title Make bun test isolated Make bun test isolated Sep 25, 2023
@owenizedd
Copy link

I think this is important for production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bun:test Something related to the `bun test` runner enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants