An open API service indexing awesome lists of open source software.

https://github.com/gr2m/frontend-test-setup

reusable test setup for mocha, chai, browserify, webdriver, saucelabs & travis
https://github.com/gr2m/frontend-test-setup

Last synced: 9 months ago
JSON representation

reusable test setup for mocha, chai, browserify, webdriver, saucelabs & travis

Awesome Lists containing this project

README

          

# frontend-test-setup

> reusable test setup for mocha, chai, browserify, webdriver, saucelabs & travis

[![Build Status](https://travis-ci.org/gr2m/frontend-test-setup.svg?branch=master)](https://travis-ci.org/gr2m/frontend-test-setup)
[![Dependency Status](https://david-dm.org/gr2m/frontend-test-setup.svg)](https://david-dm.org/gr2m/frontend-test-setup)
[![devDependency Status](https://david-dm.org/gr2m/frontend-test-setup/dev-status.svg)](https://david-dm.org/gr2m/frontend-test-setup#info=devDependencies)

## Install

```
npm install --save @gr2m/frontend-test-setup
```

## Usage

Add a `"frontend-test-setup"` key to your package.json

```js
"frontend-test-setup": {
"server": {
// path to static files
"cwd": "demo",
// browserify: path: module
"browserify": {
"/bundle.js": "demo/vendor.js",
"/smartdate-input.js": "index.js"
}
}
// see more options below
}
```

Set your scripts to

```js
"scripts": {
"start": "frontend-test-server",
"test": "frontend-test-background mocha test/*.js",
}
```

Replace `mocha test/*.js` in `"test"` with whatever your mocha test command.

You must require `'@gr2m/frontend-test-setup'` in your tests

```js
require('@gr2m/frontend-test-setup')

describe('my demo page', function () {
this.timeout(90000)

it('loads successfully', function () {
return this.client
.url('/')
.getTitle().should.eventually.equal('foo')
})
})
```

`frontend-test-setup` plays nicely with [Travis](http://travis-ci.org/). If
you want to test using selenium, make sure to only test in Firefox as it's the
only supported browser, and add the following lines:

```
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
```

Set `SAUCELABS_USERNAME` & `SAUCELABS_ACCESS_KEY` as env variables, and test
as many different browser configurations using the `env.matrix` setting, e.g.

```
env:
matrix:
- CLIENT=selenium:firefox
- CLIENT=saucelabs:chrome
- CLIENT="saucelabs:internet explorer:10:Windows 8"
- CLIENT="saucelabs:iphone:8.4:OS X 10.11"
```

## Options

`frontend-test-setup` can be configured in your `package.json`, simply
add a `"frontend-test-setup"` with the options below. Options with a `.`
delimiter are nested, e.g. `log.level` means log: {level: '...'}.

All settings in package.json can be overwritten using ENV variables, listed
below the option name.



Setting (ENV)
Default / Example





client

(CLIENT)

(saucelabs|selenium):browserName:browserVerion:platform,
e.g. 'saucelabs:internet explorer:10:win10'

'selenium:chrome'



timeout

(TIMEOUT)

mocha test timeout in milli seconds

180000



log.level

(LOG_LEVEL)

one of the following: error, warn,
info, verbose, silly

'error'



server.host

(SERVER_HOST)

hostname for test server

'0.0.0.0'



server.port

(SERVER_HOST)

port number for test server

8080



server.cwd

path from where to server static assets. If server.cmd is
set, it runs the command in the given path (relative to repository’s root)

'.'



server.browserify

Map of assets to be browserified. The example below will browserify
index.js and at
http://<server.host>:<server.port>/my-lib.js</server>


"browserify": {
"/my-lib.js": "index.js"
}


{}



server.cmd

(SERVER_CMD)

Command to start custom server

e.g. 'npm start'



selenium.hub

(SELENIUM_HUB)

Url to selenium hub

'http://localhost:4444/wd/hub/status'



saucelabs.username

(SAUCELABS_USERNAME)

Saucelabs username for authentication

e.g. 'pat'



saucelabs.accessKey

(SAUCELABS_ACCESS_KEY)

Saucelabs access key for authentication

e.g. 'abcd5678-1234-1234-1234-abcd5678abcd'



saucelabs.desiredCapabilities.idle-timeout

(SAUCELABS_IDLE_TIMEOUT)

SauceLabs Idle Test Timeout

90, allowed maximum is 1000



saucelabs.desiredCapabilities.max-duration

(SAUCELABS_MAX_DURATION)

SauceLabs Maximum Test Duration

1800, allowed maximum is 10800



saucelabs.desiredCapabilities.max-duration

(SAUCELABS_COMMAND_TIMEOUT)

SauceLabs Command Timeout

300, allowed maximum is 600

## License

MIT