Giter Club home page Giter Club logo

jenkins-mocha's Introduction

jenkins-mocha

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

Version Downloads Build Status Open Issues Dependency Status Coverage Vulnerabilities License

Installation

jenkins-mocha should be added to your test codebase as a dev dependency. You can do this with:

$ npm install --save-dev jenkins-mocha

Alternatively you can manually add it to your package.json file:

{
  "devDependencies" : {
    "jenkins-mocha": "latest"
  }
}

then install with:

$ npm install --dev

Run

jenkins-mocha should replace your mocha command in npm test

{
    "scripts": {
        "test": "jenkins-mocha test/*"
    }
}

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

{
    "scripts": {
        "devtest": "jenkins-mocha --cobertura test/*"
    }
}

If you want to turn coverage reporting off entirely, and just run unit tests with mocha, you need to pass a --no-coverage option to the command

{
    "scripts": {
        "devtest": "jenkins-mocha --no-coverage test/*"
    }
}

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).

{
    "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

Default values are:

  • $(ARTIFACTS_DIR) = ./artifacts
  • $(TEST_DIR) = ./$(ARTIFACTS_DIR)/test
  • $(COVERAGE_DIR) = ./$(ARTIFACTS_DIR)/coverage

License

MIT © St. John Johnson

jenkins-mocha's People

Contributors

ajcrews avatar bengl avatar jimbly avatar juandopazo avatar legobeat avatar redonkulus avatar roderickhsiao avatar stjohnjohnson avatar zaky7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jenkins-mocha's Issues

Fails with debug on

I'm not sure exactly what is the contributing factor, may be when the underlying test is killed with a signal. But it's annoying enough since it kills the rest of the test execution.

/tmp/shelljs_67e6b2ac42f07ecaa8c5:4
fs.writeFileSync("/tmp/shelljs_2d310a64fef8dfba8311", err ? err.code.toString() : '0');
^

TypeError: Cannot read property 'toString' of undefined
at /tmp/shelljs_67e6b2ac42f07ecaa8c5:4:71
at ChildProcess.exithandler (child_process.js:220:5)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:827:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
exec: internal error
/usr/lib/node_modules/jenkins-mocha/lib/jenkins.js:86
shell.exit(shell.exec(command.join(' ')).code);
^

TypeError: Cannot read property 'code' of null
at module.exports (/usr/lib/node_modules/jenkins-mocha/lib/jenkins.js:86:45)
at Object. (/usr/lib/node_modules/jenkins-mocha/bin/jenkins.js:2:26)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

The failing script is removed before the process exits.

Does not work with babel-register/polyfill

In this example test-babel uses code that has been transpiled via babel, and test uses ES6.

I think that it's because it needs to use _mocha, instead of mocha, but I'm still a NodeNoob.

[tfalgout@beyondinto-lm necs]$ jenkins-mocha test-babel/integration/db_test.js


  DB Integration Tests
    ✓ should create or update an entity (57ms)


  1 passing (592ms)

=============================================================================
Writing coverage object [/tmp/coverage.json]
Writing coverage reports at [/tmp]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 40.05% ( 161/402 )
Branches     : 18.18% ( 20/110 )
Functions    : 19.23% ( 25/130 )
Lines        : 32.29% ( 114/353 )
================================================================================
[tfalgout@beyondinto-lm necs]$ jenkins-mocha test/integration/db_test.js --compilers js:babel-register --require babel-polyfill


  DB Integration Tests
    ✓ should create or update an entity (65ms)


  1 passing (589ms)

No coverage information was collected, exit without writing coverage information

where is the xml with the test report ?

I want to publish jUnit report postbuild in my Jenkins job. But all i can do is publish html report. there is no xml file
(if I use xunit seperately it does work when i do mocha -R xunit test/* | grep "<" > test-reports.xml )..

how can i get an xml file as well ?

jenkins-mocha fails with multiple reporters?

@stjohnjohnson

It seems there is some incompatibility with Mocha 6.

This works:

mocha --recursive --reporter mocha-multi-reporters --reporter-options configFile=config/mocha-config.json --exit

This fails:

jenkins-mocha --recursive --reporter mocha-multi-reporters --reporter-options configFile=config/mocha-config.json --exit

The mocha-config.json:

{
   "reporterEnabled": "list,mocha-junit-reporter",
    "mochaJunitReporterReporterOptions": {
	"mochaFile": "testResults/results.xml"
    }
}

Spaces in directory name(s) causes failure

Issue mainly rises when jenkins has project name with spaces.

vagrant@vagrant-ubuntu-trusty-64:~/jenkins mocha$ npm test

> [email protected] test /home/vagrant/jenkins mocha
> node ./bin/jenkins.js

/bin/sh: 1: /home/vagrant/jenkins: not found
npm ERR! Test failed.  See above for more details.

Bump Mocha

Hi,

Getting a vulnerability warning through jenkins-mocha's older Mocha dependency. Mocha until recently was using an older mkdirp which was in turn using a vulnerable minimist. Could you bump your dep. version to the latest Mocha release which, though still targeting a version of mkdirp that is deprecated (given mkdirp's 1.x series adding a breaking change to a newer Promise-based API which Mocha is not yet using), is at least pointing to a version without security vulnerabilities?

Thanks!

Vulnerability in minimatch version 0.3.4

jenkins-mocha has a dependency on mocha ^7.1.1, the latest available version of mocha with major version 7 has a dependency on minimatch version 3.0.4

ReDOS vulnerability has been identified in minimatch 3.0.4
GHSA-f8q6-p94x-37v3

Ask is to upgrade mocha to resolve this issue.

Does not run on windows

I've tried running jenkins-mocha on a windows platform as our application supports both windows and mac and we are getting the following error message:

The filename, directory name, or volume label syntax is incorrect

Test never kill

Hello,

When I my tests, with :

NODE_ENV='test' NO_PROXY=* jenkins-mocha test.js

The command:

shell.exit(shell.exec(command.join(' ')).code);

execute :

node '/.../node_modules/.bin/nyc' --reporter lcov --reporter text-summary --report-dir /.../artifacts/coverage -- node '/.../node_modules/jenkins-mocha/node_modules/.bin/_mocha' --reporter '/.../node_modules/spec-xunit-file/index.js' --colors 'test.js'

My tests are ok, I've got this message :

X passing (Xs)

artifacts folder and files are weel created

But Test are never kill, Jenkins cannot pass to next step.

Here ar my devDependencies :

"devDependencies": {
   "bunyan": "^1.8.1",
   "chai": "3.5.0",
   "chai-as-promised": "5.3.0",
   "eslint": "^3.0.1",
   "gulp": "^3.9.0",
   "istanbul": "^0.4.3",
   "jenkins-mocha": "6.0.0",
   "mocha": "^2.5.3",
   "mocha-jenkins-reporter": "0.3.10",
   "nock": "9.1.0",
   "node-dev": "3.1.3",
   "portfinder": "1.0.3",
   "uuid": "2.0.2"
 }

If I launch my tests :

NODE_ENV='test' NO_PROXY=* istanbul cover _mocha test.js

Tests are good and script was kill automaticly at the end.

Do you know why ?

Thx

Vulnerability in ShellJS subpackage

Vulnerability in Shelljs Sub Package

Hi Everyone,

I got a message from Git for Vulnerability in Shelljs sub dependency of Jenkins-mocha. After searching
I found out this shelljs/shelljs@7a9f8e5#commitcomment-34212214

The Developer of Shelljs is clarifying that, it is not an issue but misuse of shell.exec(). My
query is that whether in the Jenkins-mocha, we are taking the required precautions https://github.com/shelljs/shelljs/wiki/Security-guidelines to make sure that command Injection vulnerability could not be reproduced. So that I can safely ignore the vulnerability warning.

Appear the vulnerability by npm audit

Because the version of nyc module described in package.json is low, npm audit warns of the vulnerability.
I would be happy if you could correct it.🙇‍♂️

                       === npm audit security report ===                        
                                                                                
# Run  npm install [email protected]  to resolve 1 vulnerability
SEMVER WARNING: Recommended action is a potentially breaking change
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ handlebars                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ nyc                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ nyc > istanbul-reports > handlebars                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/755                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


found 1 high severity vulnerability in 2556 scanned packages
  1 vulnerability requires semver-major dependency updates.

NYC dependency causes tests to fail.

There is a new version NYC which solves an issue where function.name isn't recognised. See nyc issue here: istanbuljs/nyc#489
And
Can you please update your nyc dependency to version 10.1.2?

Thank you.

I tried to fork the repo and make the change myself, but when testing I ran into the following error:

node_modules/jenkins-mocha/node_modules/.bin/nyc:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3

npm ERR! Linux 4.2.0-42-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "test_jenkins"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE

Cannot find module nyc.CMD when running jenkins-mocha

Mocha works when called on its own but fails when called via jenkins-mocha. In other words:

.\node_modules\.bin\mocha .\test\test-unit\*.js
.\node_modules\.bin\jenkins-mocha .\test\test-unit\*.js      <--- BOOM

The problem is that node cannot resolve nyc.CMD, because it is blurring relative and absolute paths.

module.js:457
    throw err; 
    ^ 

Error: Cannot find module 'C:\srcbd\'C:\srcbd\node_modules\.bin\nyc.CMD''  
    at Function.Module._resolveFilename (module.js:455:15) 
    at Function.Module._load (module.js:403:25)          
    at Module.runMain (module.js:590:10)                    
    at run (bootstrap_node.js:394:7)           
    at startup (bootstrap_node.js:149:9)                
    at bootstrap_node.js:509:3       

Environment

Windows 10
node v6.6.0
jenkins-mocha: 4.1.2

Windows support

So the problem with Windows support is really simple: node_modules/.bin/_mocha doesn´t work on Windows. The one that works in all platforms is node_modules/mocha/bin/_mocha.

So instead of...

shell.exec(
        path.join(directories.base, 'istanbul') +
        ' cover --dir ' + directories.coverage + ' -- ' +
        path.join(directories.base, '_mocha') +
        ' --reporter spec-xunit-file ' + args.join(' ')
    )

You'd just need to do...

shell.exec(
        path.join(directories.base, 'istanbul') +
        ' cover --dir ' + directories.coverage + ' -- ' +
        path.join('node_modules', 'mocha', 'bin', '_mocha') +
        ' --reporter spec-xunit-file ' + args.join(' ')
    )

Would you be up for changing it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.