hbenl / vscode-test-explorer

The VS Code Test Explorer extension
MIT License
215 stars 55 forks source link

Test Explorer UI reports incorrect line number with tests folder structure having subdirectories #218

Closed sebastiantf closed 3 years ago

sebastiantf commented 3 years ago

I am using the Mocha Test Explorer

I have the following folder structure for my mocha tests:

root/test
├── helpers
│   └── index.ts
├── index.ts
├── integration
│   └── Class.test.ts
└── unit
    └── Class.test.ts

root/test/index.ts:

import ClassUnitTest from './unit/Class.test';

import ClassIntegrationTest from './integration/Class.test';

describe('App', function () {
  describe('Unit Tests', function () {
    describe('Class', ClassUnitTest);
  });

  describe('Integration Tests', function () {
    describe('Class', ClassIntegrationTest);
  });
});

The Mocha Test Explorer lists all the individual test in this test folder structure very correctly. And I could run each test individually via the UI too.

The problem is when a test fails. When I double click on the failed test to take me to the line in the particular test thats failing, it only takes me to the describe line in the root/test/index.ts which the failed test is part of.

i.e, If a test inside ClassUnitTest failed, Mocha Test Explorer UI takes me just to the describe('Class', ClassUnitTest); line in root/test/index.ts

But the stacktrace that I get on the Test Explorer Output console in VSCode reports the correct line number

hbenl commented 3 years ago

The problem is that the extension trusts Mocha to find the right file for a test, but in your setup Mocha thinks the tests are located in root/test/index.ts. Try adding "mochaExplorer.multiFileSuites": true to your VSCode settings.

sebastiantf commented 3 years ago

Awesome! It works fine now. Thanks!