Skip to content

[Bug]: Test discovery breaks when parent and nested folders are both in the workspace #545

Description

@tmcgannon

Checklist

Actual behavior

Hi! I’ve run into a test discovery problem with a multi-root VS Code workspace.

My repository has a server package with its own .mocharc.cjs. Everything works when I open only the server folder: mocha-vscode finds the correct Mocha installation and discovers the full test suite (around 3,200 tests).

The problem appears when I open a workspace containing both the repository root and the nested server folder.

For now, my workaround is to use a separate workspace containing only the server folder.

Thanks for taking a look!

Expected behavior

I’d expect server/.mocharc.cjs to be registered once, preferably using the nested server workspace folder as its context.

Ideally, the same setup would work whether I open:

  • Only the server folder
  • A multi-root workspace containing both server and its parent repository

Minimal, Reproducible Example

Workspace setup

This works:

{
  "folders": [
    {
      "name": "Server",
      "path": "server"
    }
  ]
}

This does not:

{
  "folders": [
    {
      "name": "Server",
      "path": "server"
    },
    {
      "name": "Repository",
      "path": "."
    }
  ]
}

The relevant layout is:

repo/
  project.code-workspace
  server/
    .mocharc.cjs
    package.json

What happens

Both workspace folders seem to find the same Mocha config:

New Test Controller for workspace folder and config /path/to/repo/server /path/to/repo/server/.mocharc.cjs
New Test Controller for workspace folder and config /path/to/repo /path/to/repo/server/.mocharc.cjs

The second registration then fails:

Error: Attempt to insert a duplicate controller with ID "file:///path/to/repo/server/.mocharc.cjs"
    at ...createTestController...
    at ...coderline.mocha-vscode-1.4.0/out/extension.js...
    at ...addConfigFile...

After that, the Testing view either shows no tests or only part of the suite. It can also appear to resolve Mocha from the wrong workspace-folder context.

I can reproduce the duplicate-controller error especially reliably by creating, moving, or recreating server/.mocharc.cjs while the multi-root workspace is open.

Output

The second registration then fails:

Error: Attempt to insert a duplicate controller with ID "file:///path/to/repo/server/.mocharc.cjs"
    at ...createTestController...
    at ...coderline.mocha-vscode-1.4.0/out/extension.js...
    at ...addConfigFile...

Plugin Version Details

Environment

  • mocha-vscode: 1.4.0
  • Extension build: v1.4.0+bd847bf
  • VS Code: 1.137.0
  • macOS, arm64
  • Node.js: 24.18.0
  • Mocha: 11.8.0

VS Code Version Details

  • VS Code: 1.137.0

Further details

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

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Area

    None yet

    Platform

    None yet

    Work State

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions