This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
executable file
·69 lines (63 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
'use strict'
const DEFAULT_PORT = 9011
const argv = require('yargs')
.option('c', {
alias: 'config',
default: 'webpack.config.test-bed.js',
describe: 'Specify the configuration file',
nargs: 1,
type: 'string'
})
.option('p', {
alias: 'port',
describe: `Specify the port (defaults to ${DEFAULT_PORT})`,
nargs: 1,
type: 'number'
})
.option('b', {
alias: 'browser',
default: undefined,
describe: 'Specify if the system\'s default browser should be opened automatically (overrides settings in webpack config)',
nargs: 1,
type: 'boolean'
})
.help()
.argv
const config = require(require('path').resolve(process.cwd(), argv.config))
const shouldOpenBrowser = getShouldOpenBrowser(argv, config)
const port = getPort(argv, config)
const server = require('./createServer')(config)
server.listen(port, function () {
const actualPort = server.address().port
const portNumberPadding = ' '.repeat(5 - String(actualPort).length)
console.log('')
console.log('++=====================================================++')
console.log('|| test-bed is now running ||')
console.log('|| ||')
if (shouldOpenBrowser) {
console.log('|| If your browser does not open automatically, visit ||')
console.log(`|| http://localhost:${actualPort}/ in order to run tests. ${portNumberPadding}||`)
} else {
console.log(`|| Please open http://localhost:${actualPort}/ in your browser ${portNumberPadding}||`)
console.log('|| in order to run tests. ||')
}
console.log('++=====================================================++')
console.log('')
shouldOpenBrowser && require('opn')(`http://localhost:${actualPort}/`)
})
function getPort(argv, config) {
if (argv.port !== undefined) {
return argv.port
}
if (config.testBed && (config.testBed.port !== undefined)) {
return config.testBed.port
}
return DEFAULT_PORT
}
function getShouldOpenBrowser(argv, config) {
if (argv.browser !== undefined) {
return argv.browser
}
return config.testBed && config.testBed.openBrowser
}