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

Implement generational test isolation in bun:test #10210

Closed
wants to merge 4 commits into from

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

WIP. Towards #9243

Adds --isolate=lite to bun test

After each test() ends:

  • kill() all Subprocess and Bun.$ created during the test
  • Close all Bun.serve(), Bun.connect(), Bun.listen() created during the test

After each .test.* file finishes running:

  • kill() all Subprocess and Bun.$ created since the module started
  • Close all Bun.serve(), Bun.connect(), Bun.listen() created since the module started

Before bun test's process exits:

  • kill() all Subprocess and Bun.$
  • Close all Bun.serve(), Bun.connect(), Bun.listen()
How it works

Each test scope gets an (incremented) generation ID. I/O resources add themselves to the list of active resources and add the current generation ID. Each time we finish a test, a module, or a test scope we run a cleanup function for each I/O resource that has a generation ID >= the current generation ID.

TODO:

  • Write tests for each type
  • Store a pointer to ActiveSpySet in DescribeScope and TestScope, associate all mocks with these and restore all these mocks created per scope

How did you verify your code works?

Copy link
Contributor

github-actions bot commented Apr 12, 2024

Copy link
Contributor

github-actions bot commented Apr 12, 2024

Copy link
Contributor

github-actions bot commented Apr 12, 2024

@Jarred-Sumner 1 files with test failures on bun-darwin-aarch64:

View test output

#15b808db07ded015d99c956a89d65fe28a0be4c7

Copy link
Contributor

github-actions bot commented Apr 12, 2024

@MonsterDeveloper
Copy link

This would be awesome. Currently mock restoration doesn't work with mock.module (see #7823 and #7376), and this is a big blocker for using Bun as a test runner.

Hopefully test isolation fixes this issue.

@Jarred-Sumner
Copy link
Collaborator Author

Closing due to bitrot. But would like to revisit in the future.

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

Successfully merging this pull request may close these issues.

2 participants