Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

describe block without it does not trigger hooks #45028

Closed
scally opened this issue Oct 16, 2022 · 3 comments · Fixed by #45161
Closed

describe block without it does not trigger hooks #45028

scally opened this issue Oct 16, 2022 · 3 comments · Fixed by #45161

Comments

@scally
Copy link

scally commented Oct 16, 2022

Version

18.9.0

Platform

Darwin Eorzea.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64

Subsystem

node:test

What steps will reproduce the bug?

Nested beforeEach contexts do not work with describe/it:

import { beforeEach, describe, it } from 'node:test'
import { strict as assert } from 'node:assert'

let obj = {}
describe('outer', () => {
  beforeEach(() => {
    obj.outer = 'ok'
  })
  describe('inner', () => {
    beforeEach(() => {
      obj.inner = 'ok'
    })
    it('works', () => {
      assert.deepEqual(obj, { outer: 'ok', inner: 'ok' })
    })
  })
})

The output looks like this, a failure, due to what seems is only the inner beforeEach being run:

Expected values to be strictly deep-equal:
            + actual - expected

              {
                inner: 'ok',
            -   outer: 'ok'
              }

The same style of suite beforeEach nesting works with test

import { test } from 'node:test'
import { strict as assert } from 'node:assert'

let obj = {}
test('outer', async outer => {
  outer.beforeEach(() => {
    obj.outer = 'ok'
  })
  await outer.test('inner', async inner => {
    inner.beforeEach(() => {
      obj.inner = 'ok'
    })
    await inner.test('works', () => {
      assert.deepEqual(obj, { outer: 'ok', inner: 'ok' })
    })
  })
})

Outputs:

TAP version 13
    # Subtest: inner
        # Subtest: works
        ok 1 - works
          ---
          duration_ms: 1.353708
          ...
# Subtest: outer
        1..1
    ok 1 - inner
      ---
      duration_ms: 2.2555
      ...
    1..1
ok 1 - outer
  ---
  duration_ms: 2.722792
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 4.435458

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

Always reproduces

What is the expected behavior?

Nested test contexts should work the same whether you are using describe/it or test

What do you see instead?

The expected and actual outputs are in the repro example above

Additional information

No response

@cjihrig
Copy link
Contributor

cjihrig commented Oct 16, 2022

It looks like nested beforeEach() does work with describe()/it() syntax. However, describe() with no tests does not trigger the hook. If you add an it() at the same level as describe('inner'), then it works as expected.

@MoLow is this a bug or intended behavior? I don't know what other test runners do in this case, but I'm leaning toward bug.

@scally scally changed the title Nested suite beforeEach context works for test but not describe describe block without it does not trigger hooks Oct 16, 2022
@scally
Copy link
Author

scally commented Oct 16, 2022

FWIW, this works in Jest

@MoLow
Copy link
Member

MoLow commented Oct 18, 2022

this is not intended

cjihrig added a commit to cjihrig/node that referenced this issue Oct 25, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs#45028
cjihrig added a commit to cjihrig/node that referenced this issue Oct 25, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs#45028
nodejs-github-bot pushed a commit that referenced this issue Oct 27, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RafaelGSS pushed a commit that referenced this issue Nov 1, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RafaelGSS pushed a commit that referenced this issue Nov 10, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MoLow pushed a commit to MoLow/node that referenced this issue Nov 23, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs#45028
PR-URL: nodejs#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MoLow pushed a commit to MoLow/node that referenced this issue Nov 23, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs#45028
PR-URL: nodejs#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MoLow pushed a commit to MoLow/node that referenced this issue Dec 9, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs#45028
PR-URL: nodejs#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 3, 2023
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: #45028
PR-URL: #45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MoLow pushed a commit to MoLow/node-core-test that referenced this issue Feb 2, 2023
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs/node#45028
PR-URL: nodejs/node#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
(cherry picked from commit a69a30016cf3395b0bd775c1340ab6ecbac58296)
MoLow pushed a commit to MoLow/node-core-test that referenced this issue Feb 2, 2023
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs/node#45028
PR-URL: nodejs/node#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
(cherry picked from commit a69a30016cf3395b0bd775c1340ab6ecbac58296)
MoLow pushed a commit to MoLow/node-core-test that referenced this issue Feb 2, 2023
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs/node#45028
PR-URL: nodejs/node#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
(cherry picked from commit a69a30016cf3395b0bd775c1340ab6ecbac58296)
MoLow pushed a commit to MoLow/node-core-test that referenced this issue Feb 2, 2023
Prior to this commit, beforeEach() and afterEach() hooks were
not called on test suites (describe()). This commit addresses that.

Fixes: nodejs/node#45028
PR-URL: nodejs/node#45161
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
(cherry picked from commit a69a30016cf3395b0bd775c1340ab6ecbac58296)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants