Skip to content

Commit

Permalink
Merge pull request #28 from palmerj3/getOptionsTests
Browse files Browse the repository at this point in the history
Get options tests
  • Loading branch information
palmerj3 committed Sep 29, 2017
2 parents 9062061 + f5f9549 commit 49a67d2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
32 changes: 32 additions & 0 deletions __tests__/getOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');

const getOptions = require('../utils/getOptions.js');

jest.mock('fs', () => {
return Object.assign(
{},
require.requireActual('fs'),
{
existsSync: jest.fn().mockReturnValue(true)
}
)
});

// 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'
}
}
}, {virtual: true});

describe('getOptions', () => {
it ('should support package.json in /', () => {

});
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getOptions = require('./utils/getOptions');
http://help.catchsoftware.com/display/ET/JUnit+Format
*/
module.exports = (report) => {
const options = getOptions();
const options = getOptions.options();
const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);

// Ensure output path exists
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-junit",
"version": "3.0.0",
"version": "3.1.0",
"description": "A jest result processor that generates junit xml files",
"main": "index.js",
"repository": "https://github.com/palmerj3/jest-junit",
Expand Down
14 changes: 11 additions & 3 deletions utils/getOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ function getEnvOptions() {
function getAppOptions(pathToResolve) {
const initialPath = pathToResolve;

let traversing = true;

// Find nearest package.json by traversing up directories until /
while(pathToResolve !== path.sep) {
while(traversing) {
traversing = pathToResolve !== path.sep;

const pkgpath = path.join(pathToResolve, 'package.json');

if (fs.existsSync(pkgpath)) {
Expand All @@ -40,6 +44,10 @@ function getAppOptions(pathToResolve) {
throw new Error(`Unable to locate package.json starting at ${initialPath}`);
}

module.exports = function () {
return Object.assign({}, constants.DEFAULT_OPTIONS, getAppOptions(process.cwd()), getEnvOptions());
module.exports = {
options: function () {
return Object.assign({}, constants.DEFAULT_OPTIONS, getAppOptions(process.cwd()), getEnvOptions());
},
getAppOptions: getAppOptions,
getEnvOptions: getEnvOptions
};

0 comments on commit 49a67d2

Please sign in to comment.