Skip to content

Commit

Permalink
feat: adding support for customizing node v8 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
stjohnjohnson committed Jan 4, 2017
1 parent 2d3502e commit 9619707
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ Any other parameters added to the command will be passed directly to mocha.

If you need to configure nyc, you may create a .nycrc configuration file. Run `nyc help config` for details.

If you want to configure how node is invoked (if you have a giant coverage file), you can set v8 arguments via `$(NODE_ARGS)`.

``` json
{
"scripts": {
"test": "NODE_ARGS='--max_old_space_size=4096' jenkins-mocha test/*"
}
}
```

When npm-test is invoked, the module will:
- Create XUnit test results in `$(TEST_DIR)`
- Create LCov coverage in `$(COVERAGE_DIR)` with a HTML report at `$(COVERAGE_DIR)\lcov-report`
Expand Down
7 changes: 4 additions & 3 deletions lib/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ module.exports = function (args) {
}

var command = [];
var nodeArgs = shell.env.NODE_ARGS || '';

var noCoverageIndex = args.indexOf('--no-coverage');
if (noCoverageIndex === -1) {
// we want coverage
command.push(getBin('nyc'));
command.push('node', nodeArgs, getBin('nyc'));

// .. but do we want cobertura?
var coberturaIndex = args.indexOf('--cobertura');
Expand All @@ -73,11 +74,11 @@ module.exports = function (args) {
}

command.push('--report-dir ' + escape(directories.coverage) + ' --');
command.push(getBin('_mocha'));
command.push('node', nodeArgs, getBin('_mocha'));
} else {
// remove the --no-coverage option from args array
args.splice(noCoverageIndex, 1);
command.push(getBin('mocha'));
command.push('node', nodeArgs, getBin('mocha'));
}

command.push('--reporter ' + escape(require.resolve('spec-xunit-file')));
Expand Down
39 changes: 32 additions & 7 deletions test/jenkins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
nycPath + ' --reporter lcov --report-dir ' +
'node ' + nycPath + ' --reporter lcov --report-dir ' +
coverage +
' -- ' + _mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
' -- node ' + _mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
], 'mocha was called correctly');
});

Expand All @@ -102,9 +102,9 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
nycPath + ' --reporter lcov --report-dir ' +
'node ' + nycPath + ' --reporter lcov --report-dir ' +
coverage +
' -- ' + _mochaPath + ' --reporter ' + specXunitPath + ' --foo \'tests/*\' --no-colors'
' -- node ' + _mochaPath + ' --reporter ' + specXunitPath + ' --foo \'tests/*\' --no-colors'
], 'mocha was called correctly');
});

Expand All @@ -125,7 +125,7 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
'node ' + mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
], 'mocha was called correctly');
});

Expand All @@ -146,9 +146,34 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
nycPath + ' --reporter cobertura --report-dir ' +
'node ' + nycPath + ' --reporter cobertura --report-dir ' +
coverage +
' -- ' + _mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
' -- node ' + _mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
], 'mocha was called correctly');
});

it('should support passing Node args', function () {
mocks.exec.returns({
code: 0
});
mocks.env.NODE_ARGS = '--flop=blop';

// Run
require('../lib/jenkins')(['--foo', 'tests/*', '--no-colors']);

assertMkDirCallsAreReceived();

// Check environment
A.equalObject(mocks.env, {
NODE_ARGS: '--flop=blop',
XUNIT_FILE: path.join(process.cwd(), 'artifacts', 'test', 'xunit.xml')
}, 'xunit file was set');

// Check exec
A.equalObject(mocks.exec.args[0], [
'node --flop=blop ' + nycPath + ' --reporter lcov --report-dir ' +
coverage +
' -- node --flop=blop ' + _mochaPath + ' --reporter ' + specXunitPath + ' --foo \'tests/*\' --no-colors'
], 'mocha was called correctly');
});
});
Expand Down

0 comments on commit 9619707

Please sign in to comment.