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

🐛 Bug: Test titles not shown for ES dynamic imports #5139

Closed
3 of 4 tasks
nicholaswmin opened this issue Apr 19, 2024 · 1 comment
Closed
3 of 4 tasks

🐛 Bug: Test titles not shown for ES dynamic imports #5139

nicholaswmin opened this issue Apr 19, 2024 · 1 comment
Labels
status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer

Comments

@nicholaswmin
Copy link

nicholaswmin commented Apr 19, 2024

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Grouping tests using dynamic imports under a describe block would show them grouped under it's test title.

i.e this:

describe('Rate Limiting', async () => {
  await import('./conn.spec.js')
  await import('./event.spec.js')
})

would show up as this:

✔ Rate Limiting
    Connections
      ✔ Rejects further handshake attempts
    Events
      ✔ Disconnects client if rate limit exceeded

Actual

Does not show outer describe test title. Instead it reports the run like this:

Connections
  ✔ Rejects further handshake attempts
Events
  ✔ Disconnects client if rate limit exceeded

Minimal, Reproducible Example

// index.spec.js
describe('Rate Limiting', async () => {
  await import('./conn.spec.js')
  await import('./event.spec.js')
})
// conn.spec.js
describe('Connections', () => {
  it ('does some handshake-y thing', () => {
    // some test
  })
})
// event.spec.js
describe('Events', () => {
  it ('does some thing with rate limiting', () => {
    // some test
  })
})

and run:

mocha index.spec.js

Versions

  • Mocha: v10.4.0
  • Node: v21.0.0
  • OS: Mac OS Sonoma v14.4.1

Additional Info

CommonJS modules don't seem to have this issue. This works out fine, no problem.

describe('Rate Limiting', () => {
  require('./conns.spec.cjs')
  require('./event.spec.cjs')
})
@nicholaswmin nicholaswmin added status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer labels Apr 19, 2024
@JoshuaKGoldberg
Copy link
Member

👋 Sorry for the long wait time on this one @nicholaswmin!

I played around with it a bit locally and couldn't figure out why imports would have anything to do with test titles...

...because they don't - this repros with an single-file test!

describe("example", async () => {
    await new Promise();
    it("2 + 2", () => {});
});
$ npx mocha test.spec.js


  example
    ✔ before


  1 passing (2ms)

Two related existing items to look at:

Closing as a duplicate of #2116, as that one is already accepting PRs.

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants