feather-test-browser
Lightweight test coverage for browser-ready code
Runs the easy-to-use feather-test suite in a Headless Chrome browser instance
Install
$ npm install feather-test-browser --save-dev
Write Some Tests
myProject/test/specs/one.spec.js
;
myProject/test/specs/two.spec.js
// example of an asynchronous test;
myProject/package.json
"scripts": "test": "node ./test/run"
myProject/
|--test/
| |--specs/
| | |--one.spec.js
| | |--two.spec.js
| |--run.js
|--src/
| |--etc.
|--package.json
Run Your Tests
myProject/test/run.js
var FeatherTestBrowser = ; // create a new test suite with your spec filesvar myTests = helpers: './helpers' specs: './specs'; // run your tests and get a link to run them again in any browser// (optional callback)myTests;
$ cd myProject
$ npm test
// You will be given a URL that you can open in any browser on your machine
Notes
- Your tests will automatically be run in command line using Headless Chrome as a background process
- NOTE: the optional callback only executes when your tests are run in command line, not in browser
ES6 with Babel
If you need to run modern code in older browsers you can pass options into the bundler. See bundl-pack for more options.
var FeatherTestBrowser = ;var babelProcessor = ; var myTests = specs: './specs' bundlPack: js: ;
Configuration and Options
See feather-test for full documentation on assertions, matchers, and other options that are available in feather-test-browser.
Additional Options
dirnameAvailable
If set to true
the global __dirname
variable will be available for use in specs and helpers. This is set to false
by default for privacy because this exposes your local machine's user path in the generated bundles.
networkIntercept
If set to any truthy value, all network requests will be intercepted and prevented from reaching outside of your test environment. This will also spin up a node server to handle network traffic according to your needs. Mocked responses from the intercept server can be created using the network Spec Object. Setting keepalive
to true will ensure that the server continues to run even after your tests have finished in the terminal so that you can still re-run the tests in any browser.
networkIntercept: true
or
networkIntercept: adminPort: 9877 port: 9876 rootPath: '/' keepalive: true
Additional Spec Objects
The following Objects are just available globally within your spec documents...
network
Used for capturing and mocking network activity. This is especially useful for isolating your test environment and reducing side effects.
network.startIntercept
Begin intercepting all network traffic.
- overrides fetch, XMLHttpRequest, sendBeacon, and appendChild(