nicolo-ribaudo / jest-light-runner

A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.
MIT License
232 stars 24 forks source link

beforeAll, beforeEach, afterEach, afterAll do not work from setupFilesAfterEnv #70

Open michael42 opened 1 year ago

michael42 commented 1 year ago

Hi there, thanks for the great project!

I consider jest's partial test isolation to be more trouble than it's worth and would rather switch to jest-light-runner, don't mess around with globals (expect with jest.spyOn) and use the built-in jest features to revert these changes after every test.

However, it seems that the resetMocks and restoreMocks config option no longer works with jest-light-runner (probably a separate bug), so I tried working around that using a custom setup script (with setupFilesAfterEnv).

Actual behavior

But it seems that beforeAll, beforeEach, afterEach, afterAll simply do nothing when called from such a script, for example:

setup-after-env.js:

console.log("setup-after-env")
beforeAll(() => console.log("setup beforeAll"))
beforeEach(() => console.log("setup beforeEach"))
afterEach(() => console.log("setup afterEach"))
afterAll(() => console.log("setup afterAll"))

demo.test.js:

it("should work", () => console.log("test"))

With jest-light-runner, this only prints:

setup-after-env
test

edit: Here's a minimal reproduction repo

Expected behavior

setup-after-env
setup beforeAll
setup beforeEach
test
setup afterEach
setup afterAll
cbarceloc commented 1 year ago

Same issue here

nicolo-ribaudo commented 1 year ago

@cbarceloc Would you like to submit a PR? :)