Skip to content

With new node:test package, before/beforeEach/after/afterAll don't seem to work #44528

Description

@robogeek

Version

18.8.0

Platform

Linux davidpc 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

node:test

What steps will reproduce the bug?

I created the following code:

import {
    describe, it, before, beforeEach, after, afterEach
} from 'node:test';
import * as assert from 'node:assert';

describe('Describe Container', function() {
    before(() => { console.log('IN BEFORE')});
    beforeEach(() => { console.log('IN BEFORE EACH')});

    it('should equal 1 and 1', () => { assert.equal(1, 1); });
    it('should equal 2 and 2', () => { assert.equal(2, 2); });

    after(() => { console.log('IN AFTER')});
    afterEach(() => { console.log('IN AFTER EACH')});
});

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

Every time

What is the expected behavior?

Appropriate test output, with BEFORE, etc, messages printed

What do you see instead?

$ node --test test-before.mjs 
TAP version 13
# Subtest: /home/david/Projects/nodejs/node-test/test-before.mjs
ok 1 - /home/david/Projects/nodejs/node-test/test-before.mjs
  ---
  duration_ms: 0.074160944
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.134743581

Additional information

No response

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