提交 | 用户 | age
|
36e1de
|
1 |
// 1. start the dev server using production config |
L |
2 |
process.env.NODE_ENV = 'testing' |
|
3 |
|
|
4 |
const webpack = require('webpack') |
|
5 |
const DevServer = require('webpack-dev-server') |
|
6 |
|
|
7 |
const webpackConfig = require('../../build/webpack.prod.conf') |
|
8 |
const devConfigPromise = require('../../build/webpack.dev.conf') |
|
9 |
|
|
10 |
let server |
|
11 |
|
|
12 |
devConfigPromise.then(devConfig => { |
|
13 |
const devServerOptions = devConfig.devServer |
|
14 |
const compiler = webpack(webpackConfig) |
|
15 |
server = new DevServer(compiler, devServerOptions) |
|
16 |
const port = devServerOptions.port |
|
17 |
const host = devServerOptions.host |
|
18 |
return server.listen(port, host) |
|
19 |
}) |
|
20 |
.then(() => { |
|
21 |
// 2. run the nightwatch test suite against it |
|
22 |
// to run in additional browsers: |
|
23 |
// 1. add an entry in test/e2e/nightwatch.conf.js under "test_settings" |
|
24 |
// 2. add it to the --env flag below |
|
25 |
// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` |
|
26 |
// For more information on Nightwatch's config file, see |
|
27 |
// http://nightwatchjs.org/guide#settings-file |
|
28 |
let opts = process.argv.slice(2) |
|
29 |
if (opts.indexOf('--config') === -1) { |
|
30 |
opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) |
|
31 |
} |
|
32 |
if (opts.indexOf('--env') === -1) { |
|
33 |
opts = opts.concat(['--env', 'chrome']) |
|
34 |
} |
|
35 |
|
|
36 |
const spawn = require('cross-spawn') |
|
37 |
const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) |
|
38 |
|
|
39 |
runner.on('exit', function (code) { |
|
40 |
server.close() |
|
41 |
process.exit(code) |
|
42 |
}) |
|
43 |
|
|
44 |
runner.on('error', function (err) { |
|
45 |
server.close() |
|
46 |
throw err |
|
47 |
}) |
|
48 |
}) |