Coder Social home page Coder Social logo

linguahouse / meteor-mocha-phantomjs-junit Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 11 KB

Meteor package for running Mocha tests with PhantomJS and outputting results to JUnit format

License: MIT License

JavaScript 100.00%
meteor testing mocha-phantomjs-junit mocha-tests mocha junit phantomjs

meteor-mocha-phantomjs-junit's Introduction

linguahouse:mocha-phantomjs-junit

A Mocha test driver package for Meteor 1.3. This package reports server and client results in the server console and can be used for running tests on a CI server. This achieves what spacejam does but without the need for a separate Node package.

This package runs your client tests within a PhantomJS page. If you prefer a different solution, it should be possible to fork this package to make a variation that runs in Chrome or any other headless browser. If you do so, we can add a link to your package here.

Includes a JUnit XML format reporter. Run with "junit" reporter to enable junit output

SERVER_TEST_REPORTER="junit" MOCHA_FILE=./test-reports.xml

Additionally, if you wish to route client test reports to junit too, set the reporter to "json".

SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json meteor test --once --driver-package linguahouse:mocha-phantomjs-junit

Installation

In a Meteor 1.3+ app directory:

meteor add linguahouse:mocha-phantomjs-junit

Run app unit tests

meteor test --once --driver-package linguahouse:mocha-phantomjs-junit

Run app unit tests in watch mode

TEST_WATCH=1 meteor test --driver-package linguahouse:mocha-phantomjs-junit

Run with a different server reporter

The default Mocha reporter for server tests is the "spec" reporter. You can set the SERVER_TEST_REPORTER environment variable to change it.

SERVER_TEST_REPORTER="dot" meteor test --once --driver-package linguahouse:mocha-phantomjs-junit

Run with a different client reporter

The default Mocha reporter for client tests is the "spec" reporter. You can set the CLIENT_TEST_REPORTER environment variable to change it.

CLIENT_TEST_REPORTER="tap" meteor test --once --driver-package linguahouse:mocha-phantomjs-junit

Because of the differences between client and server code, not all reporters will work as client reporters. "spec" and "tap" are confirmed to work.

Output file

To specify the output file for server tests, use option MOCHA_FILE

SERVER_TEST_REPORTER=junit MOCHA_FILE=test-reports/server.xml meteor test --once  --driver-package linguahouse:mocha-phantomjs-junit

To specify the output file for client tests, use option MOCHA_FILE_CLIENT

SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json MOCHA_FILE=test-reports/server.xml MOCHA_FILE_CLIENT=test-reports/client.xml meteor test --once  --driver-package linguahouse:mocha-phantomjs-junit

NPM Scripts

A good best practice is to define these commands as run scripts in your app's package.json file. For example:

"scripts": {
  "test": "SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json meteor test --once --driver-package linguahouse:mocha-phantomjs-junit",
  "test:watch": "TEST_WATCH=1 SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json meteor test --driver-package linguahouse:mocha-phantomjs-junit",
  "test:fullapp": "SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json meteor test --once --driver-package linguahouse:mocha-phantomjs-junit",
  "start": "meteor run"
}

And then run npm test for one-time/CI mode or npm run test:watch to rerun the tests whenever you change a file.

meteor-mocha-phantomjs-junit's People

Contributors

javascriptlove avatar

Watchers

James Cloos avatar  avatar Lukasz Dutka avatar

Forkers

opstarts

meteor-mocha-phantomjs-junit's Issues

'Invalid time value' when gathering JUnit results

I get this error both locally and in Circle CI.

RangeError: Invalid time value

image

Here are the stats JSON:

"stats": {
   "suites": 4,
   "tests": 9,
   "passes": 6,
   "pending": 3,
   "failures": 0,
   "start": "2016-06-01T11:55:54.440Z",
   "end": "2016-06-01T11:55:57.947Z",
   "duration": 3507
 }

The command used:

SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json meteor test --full-app --once --driver-package linguahouse:mocha-phantomjs-junit --settings settings-test.json

Error: invalid reporter "json"

I am trying to send both client and server tests to an xml result file.

As mentioned in the readme I specified a client test reporter of json and invoke my test as follows:

SERVER_TEST_REPORTER=junit CLIENT_TEST_REPORTER=json MOCHA_FILE=./unit-test-reports.xml meteor test-packages --once --driver-package=linguahouse:mocha-phantomjs-junit mypkg

The server tests run fine but I get an error when the client tests run indicating json is not a valid reporter:

[[[[[ Tests ]]]]]                             
=> Started proxy.                             
=> Started MongoDB.                           
W20161010-12:50:28.362(-5)? (STDERR) Debugger listening on port 47977
I20161010-12:50:30.533(-5)? 
I20161010-12:50:30.534(-5)? --------------------------------
I20161010-12:50:30.535(-5)? ----- RUNNING SERVER TESTS -----
I20161010-12:50:30.535(-5)? --------------------------------
I20161010-12:50:30.535(-5)? 
I20161010-12:50:30.536(-5)? Mocha: Using JUnit reporter
I20161010-12:50:30.537(-5)? 
I20161010-12:50:30.537(-5)? --------------------------------
I20161010-12:50:30.537(-5)? ----- RUNNING CLIENT TESTS -----
I20161010-12:50:30.537(-5)? --------------------------------
I20161010-12:50:30.537(-5)? 
=> Started your app.

=> App running at: http://localhost:3000/
I20161010-12:50:32.423(-5)? "json" reporter not found
I20161010-12:50:32.424(-5)? Error: invalid reporter "json"

Note I am trying to test a package and thus I am pulling this package in through our packages onTest code.

Package.onTest(function (api) {
    ...
    api.use('linguahouse:mocha-phantomjs-junit', ['client', 'server']);

I also tried adding the package directly to the outer application but got the same results.

Do I need to include another package to pick up the json reporter?

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.