Sonarqube detected an issue in the test report stating that the file in question is not set up as a designated test file when tests and source code are intermingled

My setup involves TypeScript and Jest tests placed alongside my source files. For example:

  • someDir
    • someCode.ts
    • someCode.spec.ts

However, when attempting to import the text-report.xml file (which seems to be correctly formatted), an error occurs:

'Line X report refers to a file which is not configured as a test file: /someDir/someCode.spec.ts'

I am wondering what configuration changes I need in the Sonarqube properties to differentiate between test files and source files?

Answer №1

It appears that the detection of files in sub-folders using "." is not working properly. The only solution I found was to manually list all of the folders.

sonar.sources=helpers,managers,routes,schemas,types
sonar.tests=helpers,managers,routes,schemas,types
sonar.exclusions=**/*.js,test-data,dist,coverage
sonar.test.inclusions=**/*.spec.ts
sonar.testExecutionReportPaths=test-report.xml
sonar.javascript.lcov.reportPaths=coverage/lcov.info

Answer №2

If you want to simplify specifying the directories for SonarQube, you can utilize the following approach:

sonar.sources = **/someDir/**/*
sonar.tests = **/someDir/*
//or
sonar.sources = **/someDir/*
sonar.tests = **/someDir/*

This method is particularly useful if you have sub-directories within your project. It offers a more efficient way of defining locations for both tests and sources.

Answer №3

Despite including

sonar.test.inclusions=**/*-spec.js
, the test reports still weren't showing up for me. It wasn't until I also included
sonar.tests=.(same as sonar.sources)
that they finally appeared.

Answer №4

The issue I encountered was due to an incorrect value in the sonar.test.inclusions= configuration within the sonar.properties file (or any other filename designated for properties in your project). This setting is crucial for Sonar to recognize the test files.

To address this, consider specifying a valid inclusion pattern such as:

sonar.test.inclusions=src/__test__/**/*.test.ts,src/**/*.spec.ts

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

The SonarQube version 4.5.4, when paired with Java plugin 3.5, struggles to identify specific Lombok annotations

After updating SonarQube to version 4.5.4 and the Java plugin to version 3.5, we encountered an issue with classes annotated with @Data. It seems that the rule squid:S1068 is not recognizing these "special" annotations, even though they should be ignored a ...

"Error in Visual Studio: Identical global identifier found in Typescript code

I'm in the process of setting up a visual studio solution using angular 2. Initially, I'm creating the basic program outlined in this tutorial: https://angular.io/docs/ts/latest/guide/setup.html These are the three TS files that have been genera ...

Dynamically change or reassign object types in TypeScript

Check out the example you can copy and test in TypeScript Playground: class GreetMessage { message: {}; constructor(msg: string) { let newTyping: { textMsg: string }; // reassign necessary this.message = newTyping; this.message.textMsg = msg; ...

Leveraging File functionality in TypeScript

In the process of developing a web application with Angular 4 and Typescript, I encountered an issue while attempting to retrieve the date of a file for upload. Specifically, when trying to access the lastModified property of a File object, Typescript retu ...

Error encountered when attempting to retrieve response from Java Servlet using HttpClient

I'm encountering an issue where I am receiving a null response in Angular when attempting to post to a httpservlet (Java) in a WebSphere Application Server environment. The objective is to call an API for logging in. However, I am getting a null resp ...

Transforming "larger" items into "smaller" items using Typescript

I am experiencing challenges when trying to assign larger objects into smaller ones. To illustrate this issue, I will provide a simple example: Let's say I have defined the Typescript interface: export interface CrewMember { name: string; orga ...

What could be the reason that my Jest function mock is interfering with a different test?

Here are some test cases I've encountered: import { loginPagePresenter } from './LoginPagePresenter' import { apiGateway } from 'config/gatewayConfig' import { authRepository } from './AuthRepository' it('should mo ...

What is the process for increasing the number of days in a timestamp?

I am struggling to calculate the correct end date from a given start date and duration in my code. exports.terminateStoreAd = functions.https.onRequest(async(req, res) => { try { const snapshot =await admin.database().ref("StoreAds" ...

Updating the data attribute of an object in HTML using Angular

I am trying to embed a PDF viewer inside a component. In order to dynamically update the PDF document within a sanitizer, I need to use an attribute with []. This works fine with images. <img src="assets/pic.jpg"/> <img [src]="'assets/pi ...

The Promise.then() function is not patient

Whenever I attempt to use Promise.then(), the events from this.events, this.tmEvents, and this.totalEvents keep logging before the promises are fully complete. Even when I tried implementing async/await to prevent this, I faced the same issue. Is there a ...

Operating on an angular table arr with the splicing of an object attribute

Encountering an issue. I have a component with some logic for creating and deleting input fields .ts export class AppComponent implements OnInit { resource: Resource[] = []; fieldId = 0; testArr = ['1', '2', '3', ' ...

Replace i18next property type in React for language setting

We have decided to implement multilanguage support in our app and encountered an issue with function execution. const someFunction = (lang: string, url: string) => any If we mistakenly execute the function like this: someFunction('/some/url', ...

Validation in Angular10 Reactive Forms can be triggered on blur and submit events

Seeking to validate the form both on blur and when the submit button is pressed, but facing a limitation with the options available: updateOn: ['blur', 'submit'] The current choices are either updateOn: 'blur' or updateOn: &a ...

Explaining the process of defining an object type in TypeScript and the conversion from JavaScript

Currently, I am attempting to enhance the background of a React website developed in typescript (.tsx) by incorporating particles. My approach involves utilizing the particle-bg component available at: https://github.com/lindelof/particles-bg However, whe ...

Dealing with an AWS S3 bucket file not found error: A comprehensive guide

My image route uses a controller like this: public getImage(request: Request, response: Response): Response { try { const key = request.params.key; const read = getFileStream(key); return read.pipe(response); } catch (error ...

The standard category of class method parameter nature

I'm encountering difficulties when attempting to correctly define a method within a class. To begin with, here is the initial class structure: export class Plugin { configure(config: AppConfig) {} beforeLaunch(config: AppConfig) {} afterSe ...

The function useNuxtApp() in Nuxt 3 is returning an unknown type

I have been working on creating a helper that can be used across all composables and applications in my Nuxt plugin. Here is how the code looks: // hello.ts export default defineNuxtPlugin(async nuxtApp => { nuxtApp.vueApp.provide('hello', ...

Issue arises with the Prototype extension failing to function properly once an Angular application has been deployed

Utilizing a C# backend, I decided to incorporate a C# principle into the Angular frontend. Here is what I came up with: declare interface Date { addDays(days: number): Date; addYears(years: number): Date; isToday(): boolean; isSameDate(date ...

Troubleshooting Dependency Resolution Problems in NestJS Modular Design

Hello, I am new to using Nest.js and facing a dependency resolution problem in my NestJS application. I'm seeking some guidance on how to resolve this issue. Currently, I have structured my application with NestJS using a modular architecture, where ...

Differentiating between TypeScript string literal types and enums

Is it better to use enum or string literal type in TypeScript? String literal type: export type Animal = { id : number, name : string, type : "dog" | "cat" } Enum: export enum Type{ dog = "dog", cat = &qu ...