nodejs / node-core-test

Node 18's node:test, as an npm package
Other
95 stars 10 forks source link

Before and After hooks of other test get called even when skipped #52

Closed ade885 closed 1 month ago

ade885 commented 8 months ago

before, beforeEach, afterEach and after hooks of other tests in a file gets called whenever a singular test is intended to be run.

See example

When you run node --test --test-name-pattern "should add two numbers " on this test file, it is not meant to call the before hooks of the
second and third describe in the code below.

see the codesanbox here

const assert = require('node:assert');
const { before, beforeEach, it, describe, after } = require("node:test");

describe("First test", () => {
  describe("first describe", () => {
    before(() => {
      console.log("in first before ");
    });

    it("should add two numbers ", () => {
      assert.equal(1 + 1, 2);
    });
  });

  describe("second describe", () => {
    before(() => {
      console.log("in second before ");
    });

    it("should multiply two numbers", () => {
      assert.equal(1 *1, 1);
    });
  });

  describe("third describe", () => {
    before(() => {
      console.log("in third before ");
    });

    it("should divide two numbers ", () => {
      assert.equal(6/3, 2);
    });
  });
});
RedYetiDev commented 1 month ago

Hi! This repository is for the backport of the node:test module. If you have an issue with the module, please open an issue in nodejs/node