-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
74 lines (61 loc) · 1.81 KB
/
test.js
File metadata and controls
74 lines (61 loc) · 1.81 KB
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
70
71
72
73
74
// Inbuilt
const path = require('path')
const fs = require('fs')
const liveServer = require('live-server')
require('chai/register-assert') // Adds `assert` to the global object so tests can depend on it
let Mocha = require('mocha')
const { parseConfigs, envs } = require('./build-config.js')
console.info(`Running tests simultaneously in Node (in this command line process), and in the browser (at localhost:8083/test) \n\n`)
let config = parseConfigs({
NODE_VERBOSE: 1,
NODE_ENV: envs.development,
LOCAL_SERVER_PORT: 8083,
LOCAL_SERVER_HOSTNAME: 'localhost'
})
let projectRoot = path.join(__dirname)
let paths = {
temp: path.join(projectRoot, '.tmp'),
dist: path.join(projectRoot, 'dist'),
src: path.join(projectRoot, 'src'),
nodeModules: path.join(projectRoot, 'node_modules'),
tests: path.join(projectRoot, 'test')
}
/*
Browser tests
*/
let port = config.LOCAL_SERVER_PORT
let hostname = config.LOCAL_SERVER_HOSTNAME
console.info(`Starting local server at ${hostname ? hostname : ''}:${port}`)
liveServer.start({
root: projectRoot,
host: hostname,
mount: [ // Mount a directory to a route, allowing browser clients to see "higher" in FS than the root
['/n', paths.nodeModules],
['/src', paths.src]
],
port: port,
open: false, // '/test',
logLevel: 2
})
/*
Node tests
*/
let freshMochaRun = () => {
let mocha = new Mocha({
ui: 'bdd'
})
mocha.checkLeaks()
// Add each .spec.js file to the mocha instance
let files = fs.readdirSync(paths.tests).filter(filename => filename.match(/spec\.js$/))
files.forEach(filename => {
mocha.addFile(
path.join(paths.tests, filename)
)
})
// Run the tests.
mocha.run(failures => {
process.exitCode = failures ? 1 : 0 // exit with non-zero status if there were failures
})
}
freshMochaRun()
// TODO: automatically re-run freshMochaRun on changes to watched files