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

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

Open
Norlandz opened this issue Jun 30, 2024 · 1 comment
Open

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

Norlandz opened this issue Jun 30, 2024 · 1 comment

Comments

@Norlandz
Copy link

Norlandz commented Jun 30, 2024

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 TypeStrong/ts-node#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
Copy link

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

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

No branches or pull requests

2 participants