Skip to content

Commit

Permalink
Merge pull request #24 from stjohnjohnson/UsingScrewdriver
Browse files Browse the repository at this point in the history
feat: Switching to NYC
  • Loading branch information
stjohnjohnson authored Dec 14, 2016
2 parents 0180d62 + 7496d3e commit 2d3502e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 30 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Single command to run your Mocha unit tests with both XUnit and LCov output (for Jenkins).

[![Coverage Status](https://coveralls.io/repos/github/stjohnjohnson/jenkins-mocha/badge.svg?branch=master)](https://coveralls.io/github/stjohnjohnson/jenkins-mocha?branch=master)
[![Version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][status-image]][status-url] [![Open Issues][issues-image]][issues-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage][cov-image]][cov-url] [![Vulnerabilities][vul-image]][vul-url] ![License][license-image]

## Installation

Expand Down Expand Up @@ -41,7 +41,7 @@ jenkins-mocha should replace your mocha command in npm test
```

With coverage on (the default), you can pass a `--cobertura` option to the command
to have istanbul use the cobertura reporter
to have nyc use the cobertura reporter

```json
{
Expand All @@ -64,7 +64,7 @@ you need to pass a `--no-coverage` option to the command

Any other parameters added to the command will be passed directly to mocha.

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

When npm-test is invoked, the module will:
- Create XUnit test results in `$(TEST_DIR)`
Expand All @@ -75,10 +75,21 @@ Default values are:
- `$(TEST_DIR) = ./$(ARTIFACTS_DIR)/test`
- `$(COVERAGE_DIR) = ./$(ARTIFACTS_DIR)/coverage`

## Restrictions

jenkins-mocha *cannot work* if your package brings in spec-xunit-file or mocha and istanbul are included greater than two packages below jenkins-mocha. This is due to the relative path resolution of mocha/istanbul executables and mocha reporters.

## License

[MIT](http://opensource.org/licenses/MIT) © [St. John Johnson](http://stjohnjohnson.com)

[downloads-image]: https://img.shields.io/npm/dm/jenkins-mocha.svg
[license-image]: https://img.shields.io/npm/l/jenkins-mocha.svg
[npm-image]: https://img.shields.io/npm/v/jenkins-mocha.svg
[npm-url]: https://npmjs.org/package/jenkins-mocha
[cov-image]: https://coveralls.io/repos/github/stjohnjohnson/jenkins-mocha/badge.svg?branch=master
[cov-url]: https://coveralls.io/github/stjohnjohnson/jenkins-mocha?branch=master
[status-image]: https://cd.screwdriver.cd/pipelines/645af0ac1b2ed3cf24d3819d94e9af1b9007dfe8/badge
[status-url]: https://cd.screwdriver.cd/pipelines/645af0ac1b2ed3cf24d3819d94e9af1b9007dfe8
[vul-image]: https://snyk.io/test/github/stjohnjohnson/jenkins-mocha.git/badge.svg
[vul-url]: https://snyk.io/test/github/stjohnjohnson/jenkins-mocha.git
[issues-image]: https://img.shields.io/github/issues/stjohnjohnson/jenkins-mocha.svg
[issues-url]: https://github.com/stjohnjohnson/jenkins-mocha/issues
[daviddm-image]: https://david-dm.org/stjohnjohnson/jenkins-mocha.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/stjohnjohnson/jenkins-mocha
9 changes: 5 additions & 4 deletions lib/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ module.exports = function (args) {
var noCoverageIndex = args.indexOf('--no-coverage');
if (noCoverageIndex === -1) {
// we want coverage
command.push(getBin('istanbul'));
command.push('cover');
command.push(getBin('nyc'));

// .. but do we want cobertura?
var coberturaIndex = args.indexOf('--cobertura');
if (coberturaIndex !== -1) {
// remove the --cobertura option from args array
args.splice(coberturaIndex, 1);
command.push('--report cobertura');
command.push('--reporter cobertura');
} else {
command.push('--reporter lcov');
}

command.push('--dir ' + escape(directories.coverage) + ' --');
command.push('--report-dir ' + escape(directories.coverage) + ' --');
command.push(getBin('_mocha'));
} else {
// remove the --no-coverage option from args array
Expand Down
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "jenkins-mocha",
"version": "3.0.0",
"description": "Bin wrapper for Mocha + Istanbul + Xunit (for Jenkins)",
"version": "4.0.0",
"description": "Bin wrapper for Mocha + Nyc + Xunit (for Jenkins)",
"bin": {
"jenkins-mocha": "./bin/jenkins.js"
},
"scripts": {
"test": "node ./bin/jenkins.js"
"test": "node ./bin/jenkins.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"keywords": [
"mocha",
"istanbul",
"nyc",
"jenkins",
"xunit",
"junit",
Expand All @@ -24,18 +26,23 @@
"bugs": "https://github.com/stjohnjohnson/jenkins-mocha/issues",
"license": "MIT",
"dependencies": {
"istanbul": "^0.4.0",
"mocha": "^3.0.0",
"npm-which": "^3.0.0",
"shelljs": "^0.7.3",
"spec-xunit-file": "0.0.1-3",
"shell-escape": "^0.2.0"
"nyc": "^10.0.0",
"shell-escape": "^0.2.0",
"shelljs": "^0.7.5",
"spec-xunit-file": "0.0.1-3"
},
"devDependencies": {
"chai": "^3.0.0",
"coveralls": "^2.11.13",
"mockery": "^1.4.0",
"npm-auto-version": "^1.0.0",
"mockery": "^2.0.0",
"sinon": "^1.10.3"
},
"release": {
"debug": false,
"verifyConditions": {
"path": "./node_modules/semantic-release/src/lib/plugin-noop.js"
}
}
}
22 changes: 16 additions & 6 deletions screwdriver.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
workflow:
- publish

shared:
image: node:6

jobs:
main:
image: node:6
steps:
- setup: git clone https://gist.github.com/3d2388b2a7ba658cdcdaffa8cd874e50.git ci
- install: npm install
- test: npm test
- coverage: ./ci/coverage.sh
- publish: ./ci/publish.sh
secrets:
# Publishing to NPM
- NPM_TOKEN
# Pushing tags to Git
- GIT_KEY
# Uploading coverage information to coveralls
- COVERALLS_REPO_TOKEN

publish:
steps:
- install: npm install semantic-release
- publish: npm run semantic-release
secrets:
# Publishing to NPM
- NPM_TOKEN
# Pushing releases to Git
- GH_TOKEN
11 changes: 7 additions & 4 deletions test/jenkins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var A = require('chai').assert,
env: {}
},
node_modules = path.join(__dirname, '..', 'node_modules'),
istanbulPath = escape(path.join(node_modules, '.bin', 'istanbul')),
nycPath = escape(path.join(node_modules, '.bin', 'nyc')),
specXunitPath = escape(require.resolve('spec-xunit-file')),
mochaPath = escape(path.join(node_modules, '.bin', 'mocha')),
_mochaPath = escape(path.join(node_modules, '.bin', '_mocha')),
Expand All @@ -30,6 +30,9 @@ function escape(directory){
}

describe('Jenkins Mocha Test Case', function () {
// Bump timeout to 5 seconds
this.timeout(5000);

beforeEach(function () {
Object.keys(mocks).forEach(function (key) {
if (typeof mocks[key] === 'function') {
Expand Down Expand Up @@ -76,7 +79,7 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
istanbulPath + ' cover --dir ' +
nycPath + ' --reporter lcov --report-dir ' +
coverage +
' -- ' + _mochaPath + ' --reporter ' + specXunitPath + ' --colors --foo \'tests/*\''
], 'mocha was called correctly');
Expand All @@ -99,7 +102,7 @@ describe('Jenkins Mocha Test Case', function () {

// Check exec
A.equalObject(mocks.exec.args[0], [
istanbulPath + ' cover --dir ' +
nycPath + ' --reporter lcov --report-dir ' +
coverage +
' -- ' + _mochaPath + ' --reporter ' + specXunitPath + ' --foo \'tests/*\' --no-colors'
], 'mocha was called correctly');
Expand Down Expand Up @@ -143,7 +146,7 @@ describe('Jenkins Mocha Test Case', function () {

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

0 comments on commit 2d3502e

Please sign in to comment.