Skip to content

runInBand + dynamic imports break in Jest 27.0.0-next.11 #11438

Closed
@jakobrosenberg

Description

@jakobrosenberg

🐛 Bug Report

Running jest in parallel works fine, but with runInBand enabled, all tests with dynamic imports fail with the error Test environment has been torn down

Often, if I run a single test, the test will work the first time and then error on subsequent tests. Changing the imported file will fix the test on the next run, but then fail on the subsequent ones.

To reproduce

//foo.js
export default 'hello'

//faulty.test.js
test('test1', async () => {
    const module = await import('./foo.js')
    expect(module).toBeDefined()
})

Run the above test with --runInBand --watch. Once finished, click enter to trigger another run.

Expected behavior

Test should pass on subsequent runs, but instead only the first test passes and subsequent runs break.

envinfo

Verified on:
Windows, Mac, Ubuntu (Github action), WSL
Node: 14 & 15
NPM: 6 & 7

  System:
    OS: Windows 10 10.0.19041
    CPU: (16) x64 AMD Ryzen 7 1700 Eight-Core Processor
  Binaries:
    Node: 14.17.0 - ~\AppData\Local\Volta\tools\image\node\14.17.0\node.EXE
    Yarn: 1.21.1 - C:\Program Files\Volta\yarn.EXE
    npm: 6.14.13 - ~\AppData\Local\Volta\tools\image\npm\6.14.13\bin\npm.CMD
  npmPackages:
    jest: ^27.0.0-next.11 => 27.0.0-next.11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions