Skip to content

Commit

Permalink
Generate unique xml file by default
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcuns committed Oct 21, 2019
1 parent 43a8de6 commit 2a60ded
Show file tree
Hide file tree
Showing 6 changed files with 3,580 additions and 11 deletions.
5 changes: 2 additions & 3 deletions __tests__/testResultProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ jest.mock('fs', () => {

const fs = require('fs');
const libxmljs = require("libxmljs");
const path = require('path');

const testResultProcessor = require('../');

describe('jest-junit', () => {
it('should generate valid xml', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const result = testResultProcessor(noFailingTestsReport);
testResultProcessor(noFailingTestsReport);

// Ensure fs.writeFileSync is called
expect(fs.writeFileSync).toHaveBeenCalledTimes(1);

// Ensure file would have been generated
expect(fs.writeFileSync).toHaveBeenLastCalledWith(path.resolve('junit.xml'), expect.any(String));
expect(fs.writeFileSync).toHaveBeenLastCalledWith(expect.stringMatching(/junit-\S+\.xml/), expect.any(String));

// Ensure generated file is valid xml
const xmlDoc = libxmljs.parseXml(fs.writeFileSync.mock.calls[0][1]);
Expand Down
4 changes: 2 additions & 2 deletions constants/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const path = require('path');
const uuid = require('uuid/v1');

module.exports = {
ENVIRONMENT_CONFIG_MAP: {
Expand All @@ -18,7 +18,7 @@ module.exports = {
DEFAULT_OPTIONS: {
suiteName: 'jest tests',
outputDirectory: process.cwd(),
outputName: 'junit.xml',
outputName: () => `junit-${uuid()}.xml`,
classNameTemplate: '{classname} {title}',
suiteNameTemplate: '{title}',
titleTemplate: '{classname} {title}',
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);

// Set output to use new outputDirectory and fallback on original output
const output = path.join(options.outputDirectory, options.outputName);
const outputName = (typeof options.outputName === 'string') ? options.outputName : options.outputName()
const output = path.join(options.outputDirectory, outputName);

const finalOutput = getOptions.replaceRootDirInOutput(jestRootDir, output);

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ module.exports = {
"<rootDir>/integration-tests/testResultsProcessor/",
"<rootDir>/integration-tests/reporter/"
],
setupTestFrameworkScriptFile: "<rootDir>/__tests__/lib/setupTests.js"
setupFilesAfterEnv: ["<rootDir>/__tests__/lib/setupTests.js"]
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
"test:ci": "jest --ci"
},
"dependencies": {
"jest-validate": "^24.0.0",
"jest-validate": "^24.9.0",
"mkdirp": "^0.5.1",
"strip-ansi": "^4.0.0",
"strip-ansi": "^5.2.0",
"uuid": "^3.3.3",
"xml": "^1.0.1"
},
"devDependencies": {
"jest": "^24.0.0",
"libxmljs": "^0.18.4"
"jest": "^24.9.0",
"libxmljs": "^0.19.7"
}
}
Loading

0 comments on commit 2a60ded

Please sign in to comment.