Trying to understand why this approach isn't yielding the desired results.
The task involves developing TypeScript code in files located within the src
and tests
directories. These files are of types *.ts
and *.spec.ts
.
The transpilation of both source and test files to the directory build
is done using npx tsc
. As a result, the build
directory now contains various file types such as *.js
, *.spec.js
, *.js.map
, and *.spec.js.map
.
What steps should be taken to configure mocha and nyc for this setup?
The current configuration includes:
.nycrc.json
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"branches": 0,
"lines": 0,
"functions": 0,
"statements": 0,
"check-coverage": true,
"exclude": [".ignore", "coverage"],
"report-dir": "./coverage/",
"cache": false,
"source-map": true,
"produce-source-map": true
}
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"module": "commonjs",
"target": "es2016",
"lib": ["es2016"],
"moduleResolution": "node",
"types": ["mocha", "node"],
"typeRoots": ["node_modules/@types"],
"sourceMap": true,
"outDir": "./build/",
"skipLibCheck": true,
"removeComments": false
},
"include": ["./**/*.ts", "./**/*.js"]
}
Error Encountered:
karl@karl-Dell-Precision-M3800:~/dev/escd$ NODE_ENV=test npx nyc --reporter=html --reporter=text mocha "./build/tests/**/*.js"
mappedCoverage.addStatement is not a function
If the all
setting is changed to false
in the .nycrc.json
file, the issue seems to disappear. Why does this happen?
Avoiding the use of ts-node
or similar tools since the files have already been transpiled.