Skip to content

After inside describe is not executed when the before has an error #50842

Description

@jorenvandeweyer

Version

20.5.1

Platform

mac arm64

Subsystem

test_runner

What steps will reproduce the bug?

import { it, before, describe, after } from 'node:test'
import { expect } from 'expect'
import { mainDataSource } from './config/sql/index.js'

describe('failing test suite', () => {
  before(async () => {
    await mainDataSource.initialize()
    
    throw new Error('error')
  })

  after(async () => {
    await mainDataSource.destroy()
  })

  it('should be ok', async () => {
    expect(1).toBe(1)
  })
})

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Running the after inside the describe.

What do you see instead?

The after is not executed and the test will never finish because it's not able to close all open handles.

Additional information

Using the global before & after just works as intended

import { it, before, describe, after } from 'node:test'
import { expect } from 'expect'
import { mainDataSource } from './config/sql/index.js'

before(async () => {
  await mainDataSource.initialize()
    
  throw new Error('error')
})

after(async () => {
  await mainDataSource.destroy()
})

describe('failing test suite', () => {
  it('should be ok', async () => {
    expect(1).toBe(1)
  })
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions