Exploring the wonders of mocha in NYC alongside the magic of source

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.

Answer №1

Visit this link for more information

In order to resolve the issue, I had to delete

"extends": "@istanbuljs/nyc-config-typescript",
and insert "exclude-after-remap": false,.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: Angular ERROR TypeError - Cannot access the property 'push' of a null value

In my code, I have a property called category = <CategoryModel>{};. The CategoryModel model looks like this: export class CategoryModel { public name: string; public description: string; public image: string; public products?: ProductModel[]; ...

What methods can be used to identify the generic type within a class structure?

Suppose I have a class like this: class Foo<T>{} How can I determine the type of the instance of the class within a method? In other words, something along the lines of: public barbaz(){ // This approach does not function if(typeof(<T>) == ...

Creating a user-friendly interface for an array of objects, complete with an included array containing those same objects

I have an array that I want to iterate through. It contains a single object and an array of objects. How can I create an interface for this structure? What is the appropriate declaration to replace any[]? Here is the code: export const initialPhotoProps: ...

Enhance TypeScript functionality with operator overloading

I am currently involved in a project that heavily relies on vector and matrix mathematics, and I am keen on incorporating operator overloading into my code. Although there are Babel plugins available (such as https://github.com/rob-blackbourn/jetblack-ope ...

Tips for handling numerous requests using Express.JS

I am currently working on an Angular 6 + Express.JS application and have encountered a problem. When multiple requests are made simultaneously, especially when there are more than 4 requests, all of them sometimes respond with a 404 error or get cancelled. ...

Is there a way to create identical copies of data with the identical names?

Here is the code I have written: this.temp1.push(this.json); for(let i=0; i<this.temp1.length; i++){ if(this.temp1[i].name == this.json.name){ this.orderList[i] = this.json; this.DBorder[i] = this.order_json; } ...

Challenges in merging

I'm running into issues with my Angular project. Can anyone lend a hand? ERROR in src/app/app-routing.module.ts(5,1): error TS1185: Merge conflict marker encountered. ...

A comprehensive guide on utilizing the loading.tsx file in Next JS

In the OnboardingForm.tsx component, I have a straightforward function to handle form data. async function handleFormData(formData: FormData) { const result = await createUserFromForm( formData, clerkUserId as string, emailAddress a ...

What are the steps to validate a form control in Angular 13?

My Angular 13 application has a reactive form set up as follows: https://i.sstatic.net/LE219.png I am trying to validate this form using the following approach: https://i.sstatic.net/gxpgN.png However, I encountered the following error messages: https:// ...

A windows application developed using either Javascript or Typescript

Can you provide some suggestions for developing Windows applications using Javascript, Typescript, and Node.js? ...

How can one implement closure in Angular 4?

I am looking to implement a nested function within another function in Angular 4 for closure. However, when attempting the code below, I encounter an error stating "cannot find name innerFn" outerFn(){ let a = "hello"; innerFn(){ console.log(a ...

Can I modify a global array by updating a dynamically created array in the ngOnInit method of Angular?

Are there any suggestions on how to make a dynamic array available globally in Angular? I am currently using this codepen () which stores clicked countries in an array. The issue is that the array is nested within a function in ngOnInit and I need it to b ...

Error in Node.js with MongoDB: Array of OptionalId<Document> Typescript typings

I have successfully established a connection and written to my MongoDB collection, but I am encountering a type error that is causing some confusion. Below is the code snippet along with the error message: interface Movie { id: number; title: string; ...

What causes the module declaration in the .d.ts file to fail in an Angular application?

I have recently created a file named global.d.ts within the src folder and it contains the following content: declare module 'ol-contextmenu'; Despite my efforts, placing the file in the root directory or in node-modules/@types did not solve the ...

A step-by-step guide on generating a single chip using the same word in Angular

I'm trying to find a solution to ensure that only one chip is created from the same word inputted, instead of generating duplicates. Currently, users can input variations such as "apple," "APPLE," "apPPle," "aPpLe," and I want to automatically conver ...

What is the most effective way to compare two arrays of objects in JavaScript?

I'm working on a function that needs to return an array of elements based on certain filters. Here is the code for the function: filter_getCustomFilterItems(filterNameToSearch: string, appliedFilters: Array<any>) { let tempFilterArray = []; ...

A versatile Material UI paper that adjusts its dimensions dynamically

Utilizing Material-UI's Paper component (https://mui.com/components/paper/), I've encountered a scenario where the content within the Paper element needs to be dynamic. <Paper className="modal" elevation={3}> ...Content </Paper ...

Can you explain the concept of BuildOptions in Sequelize?

Despite poring through the sequelize documentation and conducting extensive searches online, I have yet to come across a satisfactory answer: Why is BuildOptions necessary and what impact does it have on the created model? import { Sequelize, Model, Data ...

What is the best way to organize code within the main.ts file in a Vue 3 project?

New to Typescript and vue, I am eager to figure out how I can extract this code from my main.ts file. I'm concerned about it becoming messy as more icons are added. const app = createApp(App); /* import the fontawesome core */ import { library } from ...

Encountering a Typescript error while attempting to remove an event that has a FormEvent type

Struggling to remove an event listener in Typescript due to a mismatch between the expected type EventListenerOrEventListenerObject and the actual type of FormEvent: private saveHighScore (event: React.FormEvent<HTMLInputElement>) { This is how I t ...