Skip to content

Commit 9062061

Browse files
authored
Merge pull request #24 from palmerj3/supportMultiProject
Support multi project
2 parents 8e5a183 + 29396a3 commit 9062061

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ node_js:
33
- "5"
44
- "6"
55
- "7"
6+
- "8"
67
env:
78
- CXX=g++-4.8
89
addons:
910
apt:
1011
sources:
1112
- ubuntu-toolchain-r-test
1213
packages:
13-
- g++-4.8
14+
- g++-4.8

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ yarn add --dev jest-junit
1212
In your jest config add the following entry:
1313
```JSON
1414
{
15-
"testResultsProcessor": "./node_modules/jest-junit"
15+
"testResultsProcessor": "jest-junit"
1616
}
1717
```
1818

@@ -24,7 +24,7 @@ jest
2424

2525
For your Continuous Integration you can simply do:
2626
```shell
27-
jest --ci --testResultsProcessor="./node_modules/jest-junit
27+
jest --ci --testResultsProcessor="jest-junit"
2828
```
2929

3030
## Configuration

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-junit",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"description": "A jest result processor that generates junit xml files",
55
"main": "index.js",
66
"repository": "https://github.com/palmerj3/jest-junit",

utils/getOptions.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const fs = require('fs');
45

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

@@ -16,16 +17,29 @@ function getEnvOptions() {
1617
return options;
1718
}
1819

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

22-
if (Object.prototype.toString.call(options) !== '[object Object]') {
23-
options = {};
23+
// Find nearest package.json by traversing up directories until /
24+
while(pathToResolve !== path.sep) {
25+
const pkgpath = path.join(pathToResolve, 'package.json');
26+
27+
if (fs.existsSync(pkgpath)) {
28+
let options = (require(pkgpath) || {})['jest-junit'];
29+
30+
if (Object.prototype.toString.call(options) !== '[object Object]') {
31+
options = {};
32+
}
33+
34+
return options;
35+
} else {
36+
pathToResolve = path.dirname(pathToResolve);
37+
}
2438
}
2539

26-
return options;
40+
throw new Error(`Unable to locate package.json starting at ${initialPath}`);
2741
}
2842

2943
module.exports = function () {
30-
return Object.assign({}, constants.DEFAULT_OPTIONS, getAppOptions(), getEnvOptions());
44+
return Object.assign({}, constants.DEFAULT_OPTIONS, getAppOptions(process.cwd()), getEnvOptions());
3145
};

0 commit comments

Comments
 (0)