hbenl / vscode-mocha-test-adapter

Mocha Test Adapter for the VS Code Test Explorer
MIT License
90 stars 31 forks source link

Stack trace location and code lens location are far off? #254

Open Norlandz opened 4 months ago

Norlandz commented 4 months ago

Stack trace location and code lens location are far off?

eg: image

env: Im using Mocha, with Typescript, Esm import.

{
  "type": "module",
  "scripts": {
    "build:vite": "tsc --project ./src/popupPage/tsconfig.json && vite build --config ./src/popupPage/vite.config.ts",
    "buildw:webpack": "webpack --config ./webpack.config.cjs --watch",
    "buildw:ts": "tsc --project ./tsconfig.json --watch",
    "build:webpack": "webpack --config ./webpack.config.cjs",
    "test": "mocha --config ./.mocharc.cjs"
  },
  "dependencies": {
    "alphanumeric-encoder": "^1.6.1",
    "he": "^1.2.0",
    "jquery": "^3.7.1",
    "js-beautify": "^1.15.1",
    "jsdom": "^24.1.0",
    "puppeteer": "^22.12.1",
    "underscore": "^1.13.6"
  },
  "devDependencies": {
    "@eslint/create-config": "^1.1.5",
    "@types/chai": "^4.3.16",
    "@types/jasmine": "^5.1.4",
    "@types/mocha": "^10.0.7",
    "@types/node": "^20.14.9",
    "@types/source-map-support": "^0.5.10",
    "@typescript-eslint/eslint-plugin": "^7.14.1",
    "@typescript-eslint/parser": "^7.14.1",
    "chai": "^5.1.1",
    "eslint": "8.57.0",
    "mocha": "^10.5.2",
    "source-map-support": "^0.5.21",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "tsx": "^4.16.0",
    "typescript": "^5.5.2",
    "webpack": "^5.92.1",
    "webpack-cli": "^5.1.4"
  }
}

config: Code-20240629_2205_30645

module.exports = {
  require: [
    'ts-node/register',
    'source-map-support/register',
    // feels this cause the misalign; also nyc?.. // pp , said ]] // if put time too 

    // "jsdom-global/register",
    // "./test/config/setup.mjs",
  ],
  extension: ['ts', 'js'],
  spec: [
    'test/**/*.spec.ts',
    'test/**/*.spec.js', //
  ],
  ignore: [
    'test/randomTest/**/*', //
  ],
  'node-option': [
    'experimental-specifier-resolution=node', //
    'loader=ts-node/esm',
  ],
  // timeout: 5000, // Optional timeout for tests
};
  "mochaExplorer.nodeArgv": [
    "--loader=ts-node/esm",
    "--no-warnings=ExperimentalWarning",
    "--experimental-specifier-resolution=node"
  ],

Update:

if I use cmd line directly, the stack trace location is off too... so it seems not the problem of the extension, but Mocha. or my config?... Though, the code lens is still a problem.


Update:

|>" like it was broken recently by an update to node https://github.com/TypeStrong/ts-node/issues/2053, it will probably be fixed at some point, but in the meantime you could confirm that you have "sourceMaps": true in your tsconfig and maybe figure out how to pass --enable-source-maps to the node instance that runs your tests <| https://www.reddit.com/r/typescript/comments/1cwbc95/typescript_esm_mocha_wrong_line_numbers_in_stack/

devhl-labs commented 3 days ago

Thank you for posting this. I also had to add --enable-source-maps to mochaExplorer.nodeArgv to fix the test gutter icons. Otherwise these run buttons were on the wrong lines.

image