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

fix: pick correct frame when looking for test locations #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robertrossmann
Copy link
Contributor

The test locations were not selected correctly because they ended up somewhere inside Mocha's describe and it function definitions, since those functions are called last when constructing the stack frames to find the call sites. When I then tried to open the test file I always ended up at the same and incorrect place.

Note that this has further implications - test failures were also not being attributed to the correct test location in my code before this patch as they again ended up inside Mocha's function definitions.

Here is a sample stack trace that is produced when the adapter is looking for the test location:

[2022-10-07 10:25:31.164] [INFO] Worker: Looking for /Users/robert/repos/strv/enter/enter-backend in Error: 
    at findCallLocation (/Users/robert/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.14.1/out/worker/bundle.js:918:17)
    at /Users/robert/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.14.1/out/worker/bundle.js:909:30
⚠️  at exports.describe (/Users/robert/repos/strv/enter/enter-backend/node_modules/mocha/lib/mocha.js:111:60)
    at Object.<anonymous> (/Users/robert/repos/strv/enter/enter-backend/test/rest/root.e2e-spec.ts:6:9)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Function.Module._load (node:internal/modules/cjs/loader:838:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

This is expected; you do call describe and it functions from Mocha before you call your assertions. We therefore need to ignore call sites from the node_modules folder and go deeper.

Here are some screenshots of before and after this change:

Before

before

After

after

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

Successfully merging this pull request may close these issues.

None yet

1 participant