Socket
Socket
Sign inDemoInstall

jest-junit

Package Overview
Dependencies
Maintainers
1
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 1.4.0 to 1.5.0

108

index.js

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

// Look for these when replacing template vars
const CLASSNAME_VAR = '{classname}';
const TITLE_VAR = '{title}';
const buildJsonResults = require('./utils/buildJsonResults');
const getOptions = require('./utils/getOptions');
const cfg = {};
try {
const config = (require(path.join(process.cwd(), 'package.json')) || {})['jest-junit'];
if (config) {
Object.assign(cfg, config);
}
} catch (e) {
//don't blowup if there was an error...just skip
}
const SUITE_NAME = process.env.JEST_SUITE_NAME || cfg.suiteName || 'jest tests';
const OUTPUT_PATH = process.env.JEST_JUNIT_OUTPUT || cfg.output ||
path.join(process.cwd(), './junit.xml');
const CLASSNAME_TEMPLATE = process.env.JEST_JUNIT_CLASSNAME || cfg.classNameTemplate || '{classname} {title}';
const TITLE_TEMPLATE = process.env.JEST_JUNIT_TITLE || cfg.titleTemplate || '{classname} {title}';
const replaceVars = function (str, classname, title) {
return str
.replace(CLASSNAME_VAR, classname)
.replace(TITLE_VAR, title);
};
/*

@@ -47,83 +24,10 @@ At the end of ALL of the test suites this method is called

module.exports = (report) => {
// Generate a single XML file for all jest tests
let jsonResults = {
'testsuites': [
{
'_attr': {
'name': SUITE_NAME
}
}
]
};
const options = getOptions();
const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);
// Iterate through outer testResults (test suites)
report.testResults.forEach((suite) => {
// Skip empty test suites
if (suite.testResults.length <= 0) {
return;
}
// Add <testsuite /> properties
let testSuite = {
'testsuite': [{
_attr: {
name: suite.testResults[0].ancestorTitles[0],
tests: suite.numFailingTests + suite.numPassingTests + suite.numPendingTests,
errors: 0, // not supported
failures: suite.numFailingTests,
skipped: suite.numPendingTests,
timestamp: (new Date(suite.perfStats.start)).toISOString().slice(0, -5),
time: (suite.perfStats.end - suite.perfStats.start) / 1000
}
}]
};
// Iterate through test cases
suite.testResults.forEach((tc) => {
const classname = tc.ancestorTitles.join(' ');
const title = tc.title;
let testCase = {
'testcase': [{
_attr: {
classname: replaceVars(CLASSNAME_TEMPLATE, classname, title),
name: replaceVars(TITLE_TEMPLATE, classname, title),
time: tc.duration / 1000
}
}]
};
// Write out all failure messages as <failure> tags
// Nested underneath <testcase> tag
if (tc.status === 'failed') {
tc.failureMessages.forEach((failure) => {
testCase.testcase.push({
'failure': [{
_attr: {
message: failure || ''
}
}]
});
})
}
// Write out a <skipped> tag if test is skipped
// Nested underneath <testcase> tag
if (tc.status === 'pending') {
testCase.testcase.push({
skipped: {}
});
}
testSuite.testsuite.push(testCase);
});
jsonResults.testsuites.push(testSuite);
});
// Ensure output path exists
mkdirp.sync(path.dirname(OUTPUT_PATH));
mkdirp.sync(path.dirname(options.output));
// Write data to file
fs.writeFileSync(OUTPUT_PATH, xml(jsonResults, { indent: ' '}));
fs.writeFileSync(options.output, xml(jsonResults, { indent: ' '}));

@@ -130,0 +34,0 @@ // Jest 18 compatibility

9

package.json
{
"name": "jest-junit",
"version": "1.4.0",
"version": "1.5.0",
"description": "A jest result processor that generates junit xml files",

@@ -15,6 +15,13 @@ "main": "index.js",

],
"scripts": {
"test": "jest"
},
"dependencies": {
"mkdirp": "^0.5.1",
"xml": "^1.0.1"
},
"devDependencies": {
"jest": "^19.0.2",
"libxmljs": "^0.18.4"
}
}

@@ -0,1 +1,3 @@

[![Build Status](https://travis-ci.org/palmerj3/jest-junit.svg?branch=master)](https://travis-ci.org/palmerj3/jest-junit)
# jest-junit

@@ -25,3 +27,3 @@ A Jest reporter that creates compatible junit xml files

jest-junit offers four configurations based on environment variables.
jest-junit offers five configurations based on environment variables. All are **string** values.

@@ -36,2 +38,4 @@ ```JEST_SUITE_NAME```: Default "jest tests"

```JEST_USE_PATH_FOR_SUITE_NAME```: Default "false"
Example:

@@ -43,3 +47,3 @@

You can also define a 'jest-junit' key in your package.json.
You can also define a `jest-junit` key in your package.json. All are **string** values.

@@ -53,3 +57,4 @@ ```

"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}"
"titleTemplate": "{classname}-{title}",
"usePathForSuiteName": "true"
}

@@ -56,0 +61,0 @@ }

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