From 7102e75600ffc629494a7f378b7f9fef98b8e35f Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 24 May 2022 13:08:22 -0700 Subject: [PATCH 1/7] updated. --- utils/buildJsonResults.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index d851b5f..ebc9690 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -161,6 +161,44 @@ module.exports = function (report, appDirectory, options, rootDir = null) { testSuite.testsuite.push(testSuitePropertyMain); } + if (suite.numFailingTests === 0 && suite.testExecError !== undefined) { + try { + let testVariables = {}; + testVariables[constants.FILEPATH_VAR] = filepath; + testVariables[constants.FILENAME_VAR] = filename; + testVariables[constants.SUITENAME_VAR] = suiteTitle; + testVariables[constants.CLASSNAME_VAR] = "testHookFailure"; + testVariables[constants.TITLE_VAR] = "testHookFailure"; + testVariables[constants.DISPLAY_NAME_VAR] = displayName; + + let testCase = { + testcase: [ + { + _attr: { + classname: replaceVars( + suiteOptions.classNameTemplate, + testVariables + ), + name: replaceVars(suiteOptions.titleTemplate, testVariables), + file: filepath, + time: 0, + }, + }, + ], + }; + + testCase.testcase.push({ + failure: stripAnsi(JSON.stringify(suite.testExecError)), + }); + + testSuite.testsuite.push(testCase); + } catch (error) { + console.log( + `Unable to add junit result for test hook failure : ${suite.testExecError}` + ); + } + } + // Iterate through test cases suite.testResults.forEach((tc) => { const classname = tc.ancestorTitles.join(suiteOptions.ancestorSeparator); From 3c6c15e8c12ba17f0f6f99541fbbb84d3d5c81e9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 Jun 2022 13:18:08 -0700 Subject: [PATCH 2/7] bumped. --- __tests__/getOptions.test.js | 27 +++++++++++++++++---------- utils/getOptions.js | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/__tests__/getOptions.test.js b/__tests__/getOptions.test.js index be44020..4b215af 100644 --- a/__tests__/getOptions.test.js +++ b/__tests__/getOptions.test.js @@ -3,6 +3,18 @@ const path = require('path'); const getOptions = require('../utils/getOptions.js'); + +const rootPath = path.parse(process.cwd()).root +const rootPackageJsonMock = path.join(rootPath, "package.json"); + +const mockPackageJson = { + name: 'foo', + version: '1.0.0', + 'jest-junit': { + suiteName: 'test suite' + } +} + jest.mock('fs', () => { return Object.assign( {}, @@ -15,19 +27,14 @@ jest.mock('fs', () => { // Mock return of require('/package.json') // Virtual because it doesn't actually exist -jest.mock('/package.json', () => { - return { - name: 'foo', - version: '1.0.0', - 'jest-junit': { - suiteName: 'test suite' - } - } +jest.doMock(rootPackageJsonMock, () => { + return mockPackageJson }, {virtual: true}); describe('getOptions', () => { - it ('should support package.json in /', () => { - + it ('should support package.json in root directory', () => { + const options = getOptions.getAppOptions(rootPath) + expect(options).toBe(mockPackageJson['jest-junit']) }); }); diff --git a/utils/getOptions.js b/utils/getOptions.js index 98da615..b7e5a5a 100644 --- a/utils/getOptions.js +++ b/utils/getOptions.js @@ -23,14 +23,23 @@ function getEnvOptions() { function getAppOptions(pathToResolve) { let traversing = true; - // 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; 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]') { options = {}; From 9c1ae9f10e58e89d36f9500c680c4851c206993d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 Jun 2022 13:19:24 -0700 Subject: [PATCH 3/7] fsdafsd --- utils/buildJsonResults.js | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index ebc9690..d851b5f 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -161,44 +161,6 @@ module.exports = function (report, appDirectory, options, rootDir = null) { testSuite.testsuite.push(testSuitePropertyMain); } - if (suite.numFailingTests === 0 && suite.testExecError !== undefined) { - try { - let testVariables = {}; - testVariables[constants.FILEPATH_VAR] = filepath; - testVariables[constants.FILENAME_VAR] = filename; - testVariables[constants.SUITENAME_VAR] = suiteTitle; - testVariables[constants.CLASSNAME_VAR] = "testHookFailure"; - testVariables[constants.TITLE_VAR] = "testHookFailure"; - testVariables[constants.DISPLAY_NAME_VAR] = displayName; - - let testCase = { - testcase: [ - { - _attr: { - classname: replaceVars( - suiteOptions.classNameTemplate, - testVariables - ), - name: replaceVars(suiteOptions.titleTemplate, testVariables), - file: filepath, - time: 0, - }, - }, - ], - }; - - testCase.testcase.push({ - failure: stripAnsi(JSON.stringify(suite.testExecError)), - }); - - testSuite.testsuite.push(testCase); - } catch (error) { - console.log( - `Unable to add junit result for test hook failure : ${suite.testExecError}` - ); - } - } - // Iterate through test cases suite.testResults.forEach((tc) => { const classname = tc.ancestorTitles.join(suiteOptions.ancestorSeparator); From 25840eca068bb3f0a3955b9ee07de47b317f7351 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 Jun 2022 13:22:57 -0700 Subject: [PATCH 4/7] bugfix. --- pacfkage.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pacfkage.json diff --git a/pacfkage.json b/pacfkage.json new file mode 100644 index 0000000..06ebe47 --- /dev/null +++ b/pacfkage.json @@ -0,0 +1,31 @@ +{ + "name": "jest-junit", + "version": "13.2.1", + "description": "A jest reporter that generates junit xml files", + "main": "index.js", + "repository": "https://github.com/jest-community/jest-junit", + "author": "Jason Palmer", + "license": "Apache-2.0", + "engines": { + "node": ">=10.12.0" + }, + "files": [ + "index.js", + "utils", + "constants" + ], + "scripts": { + "test": "jest" + }, + "dependencies": { + "mkdirp": "^1.0.4", + "strip-ansi": "^6.0.1", + "uuid": "^8.3.2", + "xml": "^1.0.1" + }, + "devDependencies": { + "jest": "^27.2.3", + "libxmljs2": "^0.29.0", + "slash": "^3.0.0" + } +} From 8a2566a219a38748f355877382a25aba29aca646 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 Jun 2022 13:23:39 -0700 Subject: [PATCH 5/7] delete unused. --- pacfkage.json | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 pacfkage.json diff --git a/pacfkage.json b/pacfkage.json deleted file mode 100644 index 06ebe47..0000000 --- a/pacfkage.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "jest-junit", - "version": "13.2.1", - "description": "A jest reporter that generates junit xml files", - "main": "index.js", - "repository": "https://github.com/jest-community/jest-junit", - "author": "Jason Palmer", - "license": "Apache-2.0", - "engines": { - "node": ">=10.12.0" - }, - "files": [ - "index.js", - "utils", - "constants" - ], - "scripts": { - "test": "jest" - }, - "dependencies": { - "mkdirp": "^1.0.4", - "strip-ansi": "^6.0.1", - "uuid": "^8.3.2", - "xml": "^1.0.1" - }, - "devDependencies": { - "jest": "^27.2.3", - "libxmljs2": "^0.29.0", - "slash": "^3.0.0" - } -} From 24a1293d6f5947fdf129efc6a667e86326e2c76d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 Jun 2022 13:23:58 -0700 Subject: [PATCH 6/7] version bump. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f81c20..06ebe47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-junit", - "version": "13.2.0", + "version": "13.2.1", "description": "A jest reporter that generates junit xml files", "main": "index.js", "repository": "https://github.com/jest-community/jest-junit", From d73935888b55e78fc068f0a74fb4415da32539df Mon Sep 17 00:00:00 2001 From: Marcin Strzyz <37447884+mastrzyz@users.noreply.github.com> Date: Sun, 5 Jun 2022 21:23:51 -0700 Subject: [PATCH 7/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 06ebe47..4f81c20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-junit", - "version": "13.2.1", + "version": "13.2.0", "description": "A jest reporter that generates junit xml files", "main": "index.js", "repository": "https://github.com/jest-community/jest-junit",