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

global hooks with @std/testing show "Error: Cannot add global hooks after a global test is registered" #432

Open
ycmjason opened this issue Oct 14, 2024 · 0 comments

Comments

@ycmjason
Copy link

ycmjason commented Oct 14, 2024

Hello,

When I try to use dnt to include the tests, I have noticed that it breaks when my test file try to use global hooks, e.g. beforeEach / afterEach. The following error will be shown:

Error: Cannot add global hooks after a global test is registered
    at addHook (dnt-issue/npm/script/deps/jsr.io/@std/testing/1.0.3/bdd.js:241:19)
    at beforeEach (dnt-issue/npm/script/deps/jsr.io/@std/testing/1.0.3/bdd.js:384:5)
    at Object.<anonymous> (dnt-issue/npm/script/b.test.js:4:25)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at main (dnt-issue/npm/test_runner.js:26:13)
error: Uncaught (in promise) Error: npm run test failed with exit code 1
      throw new Error(
            ^
    at runCommand (https://jsr.io/@deno/dnt/0.41.3/lib/utils.ts:56:13)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async build (https://jsr.io/@deno/dnt/0.41.3/mod.ts:419:5)
    at async file://dnt-issue/dnt.ts:5:1

Current workaround is either

  • Add 01 prefix to the file that uses global hooks, but this causes all subsequent tests to run the hooks too. OR
  • Put global hooks into a describe block.

You can see a minimal reproduction here: https://github.com/ycmjason/dnt-test-global-hook-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant