hbenl / vscode-mocha-test-adapter

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

When unsing with hardhat typescript setup, test locations are off #236

Closed migoldfinger closed 1 year ago

migoldfinger commented 1 year ago

This goes to the point where the explorer is unusable. grafik

I spend hours in one project to solve this out, at some point it starts to work correctly without any reason. The screenshot is from a newly created project.

This are the modules that I am using if that is of any relevance

"@commitlint/config-conventional": "^17.4.4",
"@exoda/contracts": "^2.0.1",
"@nomicfoundation/hardhat-toolbox": "^2.0.1",
"@tsconfig/node18": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"eslint": "^8.35.0",
"eslint-config-standard": "^17.0.0",
"eslint-formatter-table": "^7.32.1",
"eslint-plugin-node": "^11.1.0",
"hardhat": "^2.12.7",
"hardhat-abi-exporter": "^2.10.1",
"hardhat-contract-sizer": "^2.8.0",
"hardhat-deploy": "^0.11.24",
"solhint": "^3.4.0"

My .mochaarc.json

{
    "extension": [
        "ts"
    ],
    "require": [
        "hardhat/register"
    ],
    "full-trace": false,
    "exit": true,
    "timeout": 3600000,
    "parallel": true, // Mocha does not run individual tests in parallel. Mocha runs test files in parallel.
    // "jobs": 4, // Default is CPU-Cores-1 
    "spec": "test/**/*.test.ts"
}

My tsconfig.json

{
  "extends": "@tsconfig/node18",
  // Most ts-node options can be specified here using their programmatic names.
  "ts-node": {
    // It is faster to skip typechecking.
    "transpileOnly": false, // Slower but does typechecking
    "files": true,
    "compilerOptions": {
      // compilerOptions specified here will override those declared below,
      // but *only* in ts-node.  Useful if you want ts-node and tsc to use
      // different options with a single tsconfig.json.
    }
  },
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "strict": true,
    "esModuleInterop": true,
    "sourceMap": true
  },
  "exclude": [
    "dist",
  ],
  "include": [
    "scripts/*.ts",
    "test/*.ts",
    "typechain-types/**/*.ts"
  ],
  "files": [
    "./hardhat.config.ts"
  ]
}
migoldfinger commented 1 year ago

I found the solution. The reason for this behavior was a error in the "require" setting in my .mocharc.json file. After fixing the error and setting it to "require": "hardhat/register" the code locations are correct.