UNPKG

6.44 kBMarkdownView Raw
1# frontend-test-setup
2
3> reusable test setup for mocha, chai, browserify, webdriver, saucelabs & travis
4
5[![Build Status](https://travis-ci.org/gr2m/frontend-test-setup.svg?branch=master)](https://travis-ci.org/gr2m/frontend-test-setup)
6[![Dependency Status](https://david-dm.org/gr2m/frontend-test-setup.svg)](https://david-dm.org/gr2m/frontend-test-setup)
7[![devDependency Status](https://david-dm.org/gr2m/frontend-test-setup/dev-status.svg)](https://david-dm.org/gr2m/frontend-test-setup#info=devDependencies)
8
9## Install
10
11```
12npm install --save @gr2m/frontend-test-setup
13```
14
15## Usage
16
17Add a `"frontend-test-setup"` key to your package.json
18
19```js
20 "frontend-test-setup": {
21 "server": {
22 // path to static files
23 "cwd": "demo",
24 // browserify: path: module
25 "browserify": {
26 "/bundle.js": "demo/vendor.js",
27 "/smartdate-input.js": "index.js"
28 }
29 }
30 // see more options below
31 }
32```
33
34Set your scripts to
35
36```js
37 "scripts": {
38 "start": "frontend-test-server",
39 "test": "frontend-test-background mocha test/*.js",
40 }
41```
42
43Replace `mocha test/*.js` in `"test"` with whatever your mocha test command.
44
45You must require `'@gr2m/frontend-test-setup'` in your tests
46
47```js
48require('@gr2m/frontend-test-setup')
49
50describe('my demo page', function () {
51 this.timeout(90000)
52
53 it('loads successfully', function () {
54 return this.client
55 .url('/')
56 .getTitle().should.eventually.equal('foo')
57 })
58})
59```
60
61`frontend-test-setup` plays nicely with [Travis](http://travis-ci.org/). If
62you want to test using selenium, make sure to only test in Firefox as it's the
63only supported browser, and add the following lines:
64
65```
66before_install:
67 - export DISPLAY=:99.0
68 - sh -e /etc/init.d/xvfb start
69```
70
71Set `SAUCELABS_USERNAME` & `SAUCELABS_ACCESS_KEY` as env variables, and test
72as many different browser configurations using the `env.matrix` setting, e.g.
73
74```
75env:
76 matrix:
77 - CLIENT=selenium:firefox
78 - CLIENT=saucelabs:chrome
79 - CLIENT="saucelabs:internet explorer:10:Windows 8"
80 - CLIENT="saucelabs:iphone:8.4:OS X 10.11"
81```
82
83## Options
84
85`frontend-test-setup` can be configured in your `package.json`, simply
86add a `"frontend-test-setup"` with the options below. Options with a `.`
87delimiter are nested, e.g. `log.level` means log: {level: '...'}.
88
89All settings in package.json can be overwritten using ENV variables, listed
90below the option name.
91
92<table>
93 <thead>
94 <tr>
95 <th>Setting (ENV)</th>
96 <th>Default / Example</th>
97 </tr>
98 </thead>
99 <tbody>
100 <tr>
101 <td>
102 <strong>client</strong><br>
103 (<code>CLIENT</code>)<br><br>
104
105 (saucelabs|selenium):browserName:browserVerion:platform,
106 e.g. 'saucelabs:internet explorer:10:win10'
107 </td>
108 <td><code>'selenium:chrome'</code></td>
109 </tr>
110 <tr>
111 <td>
112 <strong>timeout</strong><br>
113 (<code>TIMEOUT</code>)<br><br>
114
115 mocha test timeout in milli seconds
116 </td>
117 <td><code>180000</code></td>
118 </tr>
119 <tr>
120 <td>
121 <strong>log.level</strong><br>
122 (<code>LOG_LEVEL</code>)<br><br>
123
124 one of the following: <code>error</code>, <code>warn</code>,
125 <code>info</code>, <code>verbose</code>, <code>silly</code>
126 </td>
127 <td><code>'error'</code></td>
128 </tr>
129 <tr>
130 <td>
131 <strong>server.host</strong><br>
132 (<code>SERVER_HOST</code>)<br><br>
133
134 hostname for test server
135 </td>
136 <td><code>'0.0.0.0'</code></td>
137 </tr>
138 <tr>
139 <td>
140 <strong>server.port</strong><br>
141 (<code>SERVER_HOST</code>)<br><br>
142
143 port number for test server
144 </td>
145 <td><code>8080</code></td>
146 </tr>
147 <tr>
148 <td>
149 <strong>server.cwd</strong><br><br>
150
151 path from where to server static assets. If <code>server.cmd</code> is
152 set, it runs the command in the given path (relative to repository’s root)
153 </td>
154 <td><code>'.'</code></td>
155 </tr>
156 <tr>
157 <td>
158 <strong>server.browserify</strong><br><br>
159
160 Map of assets to be browserified. The example below will browserify
161 <code>index.js</code> and at
162 <code>http://&lt;server.host&gt;:&lt;server.port&gt;/my-lib.js&lt;/server&gt;</code>
163
164<pre>
165"browserify": {
166 "/my-lib.js": "index.js"
167}
168</pre>
169 </td>
170 <td><code>{}</code></td>
171 </tr>
172 <tr>
173 <td>
174 <strong>server.cmd</strong><br>
175 (<code>SERVER_CMD</code>)<br><br>
176
177 Command to start custom server
178 </td>
179 <td>e.g. <code>'npm start'</code></td>
180 </tr>
181 <tr>
182 <td>
183 <strong>selenium.hub</strong><br>
184 (<code>SELENIUM_HUB</code>)<br><br>
185
186 Url to selenium hub
187 </td>
188 <td><code>'http://localhost:4444/wd/hub/status'</code></td>
189 </tr>
190 <tr>
191 <td>
192 <strong>saucelabs.username</strong><br>
193 (<code>SAUCELABS_USERNAME</code>)<br><br>
194
195 Saucelabs username for authentication
196 </td>
197 <td>e.g. <code>'pat'</code></td>
198 </tr>
199 <tr>
200 <td>
201 <strong>saucelabs.accessKey</strong><br>
202 (<code>SAUCELABS_ACCESS_KEY</code>)<br><br>
203
204 Saucelabs access key for authentication
205 </td>
206 <td>e.g. <code>'abcd5678-1234-1234-1234-abcd5678abcd'</code></td>
207 </tr>
208 <tr>
209 <td>
210 <strong>saucelabs.desiredCapabilities.idle-timeout</strong><br>
211 (<code>SAUCELABS_IDLE_TIMEOUT</code>)<br><br>
212
213 <a href="https://docs.saucelabs.com/reference/test-configuration/#idle-test-timeout">SauceLabs Idle Test Timeout</a>
214 </td>
215 <td><code>90</code>, allowed maximum is <code>1000</code></td>
216 </tr>
217 <tr>
218 <td>
219 <strong>saucelabs.desiredCapabilities.max-duration</strong><br>
220 (<code>SAUCELABS_MAX_DURATION</code>)<br><br>
221
222 <a href="https://docs.saucelabs.com/reference/test-configuration/#maximum-test-duration">SauceLabs Maximum Test Duration</a>
223 </td>
224 <td><code>1800</code>, allowed maximum is <code>10800</code></td>
225 </tr>
226 <tr>
227 <td>
228 <strong>saucelabs.desiredCapabilities.max-duration</strong><br>
229 (<code>SAUCELABS_COMMAND_TIMEOUT</code>)<br><br>
230
231 <a href="https://docs.saucelabs.com/reference/test-configuration/#command-timeout">SauceLabs Command Timeout</a>
232 </td>
233 <td><code>300</code>, allowed maximum is <code>600</code></td>
234 </tr>
235 </tbody>
236</table>
237
238## License
239
240MIT