Skip to content

Commit

Permalink
Merge pull request #24 from palmerj3/supportMultiProject
Browse files Browse the repository at this point in the history
Support multi project
  • Loading branch information
palmerj3 committed Sep 1, 2017
2 parents 8e5a183 + 29396a3 commit 9062061
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ node_js:
- "5"
- "6"
- "7"
- "8"
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- g++-4.8
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ yarn add --dev jest-junit
In your jest config add the following entry:
```JSON
{
"testResultsProcessor": "./node_modules/jest-junit"
"testResultsProcessor": "jest-junit"
}
```

Expand All @@ -24,7 +24,7 @@ jest

For your Continuous Integration you can simply do:
```shell
jest --ci --testResultsProcessor="./node_modules/jest-junit
jest --ci --testResultsProcessor="jest-junit"
```

## Configuration
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": "2.1.0",
"version": "3.0.0",
"description": "A jest result processor that generates junit xml files",
"main": "index.js",
"repository": "https://github.com/palmerj3/jest-junit",
Expand Down
26 changes: 20 additions & 6 deletions utils/getOptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

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

const constants = require('../constants/index');

Expand All @@ -16,16 +17,29 @@ function getEnvOptions() {
return options;
}

function getAppOptions() {
let options = (require(path.join(process.cwd(), 'package.json')) || {})['jest-junit'];
function getAppOptions(pathToResolve) {
const initialPath = pathToResolve;

if (Object.prototype.toString.call(options) !== '[object Object]') {
options = {};
// Find nearest package.json by traversing up directories until /
while(pathToResolve !== path.sep) {
const pkgpath = path.join(pathToResolve, 'package.json');

if (fs.existsSync(pkgpath)) {
let options = (require(pkgpath) || {})['jest-junit'];

if (Object.prototype.toString.call(options) !== '[object Object]') {
options = {};
}

return options;
} else {
pathToResolve = path.dirname(pathToResolve);
}
}

return options;
throw new Error(`Unable to locate package.json starting at ${initialPath}`);
}

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

0 comments on commit 9062061

Please sign in to comment.