aldeed:browser-tests

v0.1.1Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

aldeed:browser-tests

This package exports a startBrowser function for server code, which runs your client tests within a headless browser page. Meteor test driver packages can depend on this package. See the example implementation here: https://github.com/DispatchMe/meteor-mocha

NOTE: This package replaces dispatch:phantomjs-tests. This package supports PhantomJS as well as others, and can be easily updated to support more.

Usage

In your test driver package package.js file, add

1api.use('aldeed:browser-tests@0.0.1', 'server');

Then in your server code, do something similar to this:

1import { startBrowser } from 'meteor/aldeed:browser-tests';
2
3function start() {
4  startBrowser({
5    stdout(data) {
6      console.log(data.toString());
7    },
8    stderr(data) {
9      console.log(data.toString());
10    },
11    done(failureCount) {
12      // Your code to run when client tests are done running
13    },
14  });
15}
16
17export { start };

And in your client code, you need to set some properties on window so that the browser script knows what is happening. Here is an example using Mocha:

1// Run the client tests. Meteor calls the `runTests` function exported by
2// the driver package on the client.
3function runTests() {
4  // These `window` properties are all used by the browser script to
5  // know what is happening.
6  window.testsAreRunning = true;
7  mocha.run((failures) => {
8    window.testsAreRunning = false;
9    window.testFailures = failures;
10    window.testsDone = true;
11  });
12}
13
14export { runTests };

Dependencies

When using your test driver package, you will need to install the necessary NPM package dependency and indicate which headless browser you want to use.

PhantomJS

$ npm i --save-dev phantomjs-prebuilt
$ TEST_BROWSER_DRIVER=phantomjs meteor test --once --driver-package <your package name>

Selenium ChromeDriver

$ npm i --save-dev selenium-webdriver@3.0.0-beta-2 chromedriver
$ TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package <your package name>

NOTE: Currently you must pin to exactly version 3.0.0-beta-2 of selenium-webdriver because the latest only works on Node 6.x

Nightmare/Electron

$ npm i --save-dev nightmare
$ TEST_BROWSER_DRIVER=nightmare meteor test --once --driver-package <your package name>

You can export TEST_BROWSER_VISIBLE=1 to show the Electron window while tests run.