Add the name of the file to the JUnit XML document using the Karma-JUnit-Reporter

I am trying to figure out how to include the filename of a specific test in the JUnit XML results file, as it currently only displays the class name:

<testcase name="xxxTest should do Y." time="0.119" classname="Chrome_80_0_3987_(Mac_OS_X_10_12_6).xxxTest">

In the karma.conf.js file, there is an option called classNameFormatter that can be passed when configuring the report, but I'm unsure if it can be used to extract the file name?

// karma.conf.js

// default configuration
junitReporter: {
  outputDir: '', // results saved as $outputDir/$browserName.xml
  outputFile: undefined, // results saved as $outputDir/$browserName/$outputFile
  suite: '', // suite becomes package name attribute in xml testsuite element
  useBrowserName: true, // add browser name to report and classes names
  nameFormatter: undefined, // function (browser, result) to customize name attribute in xml testcase element
  classNameFormatter: undefined, // function (browser, result) to customize classname attribute in xml testcase element
  properties: {}, // key value pair of properties added to <properties> section of report
  xmlVersion: null // use '1' for SonarQube 6.2 XML format
}

Answer №1

If you're looking to achieve this, here's one way to do it:

formatClassName: function(browser, output) {
    return result.category[0];
}, 

To understand the data you are working with, you can inspect the structure of the input (browser and output) like this:

console.dir(output);

I hope this explanation is helpful!

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

Organizing an intricate collection of objects based on a true/false property in JavaScript

I have been searching for solutions to this issue, but unfortunately nothing seems to be working for me. My problem involves a large array of objects that I need to sort based on a boolean property (with all the true values taking precedence). The common ...

Having trouble with jQuery.cookie saving my JSON data

Being new to jQuery and JSON, I find this situation quite frustrating as it seems pretty straightforward but still doesn't work for me. My ASP.NET MVC website is using AJAX (via jQuery) to load data. Everything works fine until this point. I'm ...

Concealing navigation options using CSS styling

A unique program I developed generates a tree structure that looks like this: <li class="linamesystem">Alternator</li> <ul class="boxfornamegroupsparts"> <li class="linamegroup"><a href="#top(1)">Alternator2</a> ...

When I set the width of my script to 100% in CSS, it causes the width to become distorted

I encountered an issue with my Div Slider that swaps out Divs on click. When I modified the CSS to include the following: .hslide-item {width: 100%}; The script started ignoring the entire div width. I am looking for a solution where the .hslide-item ca ...

Run a PHP script that creates a PDF file using jQuery AJAX

I am currently working with a form that looks like this: <form action="tcpdf/examples/example_0611.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="subm ...

Utilize JSON data from a URL to create a visually appealing bar graph for

I have a source of JSON data stored in a live URL (for example: http://localhost/icx/test/link.html), which updates over time. [{ "call_time": "0", "total_inc_traffic": "1363.10", "total_out_traffic": "88.70" }, { " ...

Ways to update status in intervals of x seconds

I am trying to update the name of every avatar automatically every X seconds. I found a helpful solution that works well, but currently it is displaying the same name for all avatars from the RandomAcidName array. I believe I need to iterate through this ...

Calling a function upon a checkbox event change and passing an object to it

I am attempting to implement a checkbox change so that when it is clicked, a value is added to my object. I tried using an onclick event since jQuery wasn't working for me. Here is the code snippet: The object is named Contact() and contains 'ad ...

How to exclude the port number from the href in a Node.js EJS template?

I have the following code snippet. I am trying to list out the file names in a specific directory and add an href tag to them. The code seems to be working fine, however, it still includes the port number where my node.js app is running. How can I remove ...

Slow CSS :hover animations in the most recent release of Chrome

I recently upgraded my browser from chromium version 67 to the latest Chrome version 79. However, I noticed that after the upgrade, the CSS transitions on my website have become very laggy and unresponsive. Surprisingly, everything works perfectly fine on ...

Injecting resolve into Angular controller and encountering undefined value in logging operation

My setup involves the following: .state('posts', { url: '/posts/{id}', templateUrl: 'posts.html', controller: 'postsController as postsCtrl', resolve: { post: getSinglePostWrapper ...

Warning: Uncontrolled Input Issue with React Google Autocomplete

Within my React application, I have incorporated the react-google-autocomplete and antd packages. Here is how I am utilizing them: import { Button, Input, Form, Row, Col } from "antd"; .... const getCityFromPlace = (place) => { let city ...

I am looking to share videos and large files without the use of a flash plugin

Looking for a way to upload videos without using the Flash Plugin and without relying on the browser's default browse button, especially for large files. It would be great to have a progress bar displayed during the upload process. Alternatively, is ...

When a user inputs in the field, it automatically loses focus

An error is encountered in two scenarios: When the input includes an onChange event handler When the input is located within a component that is called on another page For instance: In Page1.js, we have: return <div> <Page2 /> </div ...

Is there a way to use Javascript to determine if a string within a JSON object has been altered?

I am looking for a way to continuously monitor changes in a specific string or date stored in a JSON file. How can I effectively store this value and create a mechanism to compare it for any differences? Any assistance would be highly appreciated. // Ex ...

What makes 'Parsing JSON with jQuery' unnecessary?

Just performed an ajax request with a query and noticed that my response is already in the form of a JavaScript object. When I try to parse the JSON using: var obj = jQuery.parseJSON(response); 'obj' turns out to be null, yet I can directly ac ...

Executing PHP code on button click in HTMLThe process of running a PHP script when

I am currently working on a project that involves detecting facial expressions using Python. However, I need to pass an image to this code through PHP. The PHP code provided below saves the image in a directory. How can I trigger this code using an HTML ...

I am struggling to grasp the concept of how the g flag in JavaScript's string.match(regexp) method operates

In the JavaScript book "The Good Parts", there is an explanation of the method string.match(regexp): The match method works by comparing a string with a regular expression. Its behavior varies based on whether or not the g flag is present. Without the g ...

Ways to stop Ajax long-poll from refreshing div on Chrome?

Update: Upon further investigation, I believe I am getting closer to a solution, but I still require assistance. It seems that my PHP script is returning empty responses when it queries the MySQL database and finds nothing. Instead of holding the request o ...

The Allure Report runs successfully but encounters issues with data population when using Jasmine and Protractor

Currently, I am facing an issue with my Protractor project set up that incorporates Allure Reporting. Although the Allure Reporter successfully outputs the HTML file to the allure-report directory, when I attempt to view it in a browser, all I see is a "Lo ...