Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-junit

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-junit - npm Package Compare versions

Comparing version 13.2.0 to 14.0.0

2

package.json
{
"name": "jest-junit",
"version": "13.2.0",
"version": "14.0.0",
"description": "A jest reporter that generates junit xml files",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,2 +14,5 @@ 'use strict';

const testFailureStatus = 'failed';
const testErrorStatus = 'error';
// Replaces var using a template string or a function.

@@ -39,2 +42,54 @@ // When strOrFunc is a template string replaces {varname} with the value from the variables map.

const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, filename, suiteTitle, displayName){
const classname = tc.ancestorTitles.join(suiteOptions.ancestorSeparator);
const testTitle = tc.title;
// Build replacement map
let testVariables = {};
testVariables[constants.FILEPATH_VAR] = filepath;
testVariables[constants.FILENAME_VAR] = filename;
testVariables[constants.SUITENAME_VAR] = suiteTitle;
testVariables[constants.CLASSNAME_VAR] = classname;
testVariables[constants.TITLE_VAR] = testTitle;
testVariables[constants.DISPLAY_NAME_VAR] = displayName;
let testCase = {
'testcase': [{
_attr: {
classname: replaceVars(suiteOptions.classNameTemplate, testVariables),
name: replaceVars(suiteOptions.titleTemplate, testVariables),
time: tc.duration / 1000
}
}]
};
if (suiteOptions.addFileAttribute === 'true') {
testCase.testcase[0]._attr.file = filepath;
}
// Write out all failure messages as <failure> tags
// Nested underneath <testcase> tag
if (tc.status === testFailureStatus || tc.status === testErrorStatus) {
const failureMessages = junitOptions.noStackTrace === 'true' && tc.failureDetails ?
tc.failureDetails.map(detail => detail.message) : tc.failureMessages;
failureMessages.forEach((failure) => {
const tagName = tc.status === testFailureStatus ? 'failure': testErrorStatus
testCase.testcase.push({
[tagName]: stripAnsi(failure)
});
})
}
// Write out a <skipped> tag if test is skipped
// Nested underneath <testcase> tag
if (tc.status === 'pending') {
testCase.testcase.push({
skipped: {}
});
}
return testCase;
}
const addErrorTestResult = function (suite) {

@@ -48,3 +103,3 @@ suite.testResults.push({

"numPassingAsserts": 0,
"status": "error"
"status": testErrorStatus
})

@@ -169,52 +224,28 @@ }

suite.testResults.forEach((tc) => {
const classname = tc.ancestorTitles.join(suiteOptions.ancestorSeparator);
const testTitle = tc.title;
const testCase = generateTestCase(options, suiteOptions, tc, filepath, filename, suiteTitle, displayName)
testSuite.testsuite.push(testCase);
});
// Build replacement map
let testVariables = {};
testVariables[constants.FILEPATH_VAR] = filepath;
testVariables[constants.FILENAME_VAR] = filename;
testVariables[constants.SUITENAME_VAR] = suiteTitle;
testVariables[constants.CLASSNAME_VAR] = classname;
testVariables[constants.TITLE_VAR] = testTitle;
testVariables[constants.DISPLAY_NAME_VAR] = displayName;
let testCase = {
'testcase': [{
_attr: {
classname: replaceVars(suiteOptions.classNameTemplate, testVariables),
name: replaceVars(suiteOptions.titleTemplate, testVariables),
time: tc.duration / 1000
}
}]
// We have all tests passed but a failure in a test hook like in the `beforeAll` method
// Make sure we log them since Jest still reports the suite as failed
if (suite.testExecError !== undefined) {
const fakeTC = {
status: testFailureStatus,
failureMessages: [JSON.stringify(suite.testExecError)],
classname: undefined,
title: "Test execution failure: could be caused by test hooks like 'afterAll'.",
ancestorTitles: [""],
duration: 0,
};
if (suiteOptions.addFileAttribute === 'true') {
testCase.testcase[0]._attr.file = filepath;
}
// Write out all failure messages as <failure> tags
// Nested underneath <testcase> tag
if (tc.status === 'failed'|| tc.status === 'error') {
const failureMessages = options.noStackTrace === 'true' && tc.failureDetails ?
tc.failureDetails.map(detail => detail.message) : tc.failureMessages;
failureMessages.forEach((failure) => {
const tagName = tc.status === 'failed' ? 'failure': 'error'
testCase.testcase.push({
[tagName]: stripAnsi(failure)
});
})
}
// Write out a <skipped> tag if test is skipped
// Nested underneath <testcase> tag
if (tc.status === 'pending') {
testCase.testcase.push({
skipped: {}
});
}
const testCase = generateTestCase(
options,
suiteOptions,
fakeTC,
filepath,
filename,
suiteTitle,
displayName
);
testSuite.testsuite.push(testCase);
});
}

@@ -221,0 +252,0 @@ // Write stdout console output if available

@@ -26,5 +26,8 @@ 'use strict';

// Find nearest package.json by traversing up directories until /
// Get the root dir to detect when we reached the end to our search
const rootDir = path.parse(pathToResolve).root
// Find nearest package.json by traversing up directories until root
while(traversing) {
traversing = pathToResolve !== path.sep;
traversing = pathToResolve !== rootDir;

@@ -34,4 +37,10 @@ const pkgpath = path.join(pathToResolve, 'package.json');

if (fs.existsSync(pkgpath)) {
let options = (require(pkgpath) || {})['jest-junit'];
let options;
try {
options = (require(pkgpath) || {})['jest-junit'];
} catch (error) {
console.warn(`Unable to import package.json to get app Options : ${error}`)
}
if (Object.prototype.toString.call(options) !== '[object Object]') {

@@ -38,0 +47,0 @@ options = {};

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc