1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict'
|
13 |
|
14 | const aglob = require('aglob')
|
15 | const path = require('path')
|
16 | const co = require('co')
|
17 | const Mocha = require('mocha')
|
18 | const coverage = require('./coverage')
|
19 |
|
20 |
|
21 | function amocha (pattern, options = {}) {
|
22 | let {
|
23 | cwd = process.cwd(),
|
24 | reporter = 'spec',
|
25 | timeout = 3000
|
26 | } = options
|
27 | return co(function * () {
|
28 | const mocha = new Mocha({
|
29 | reporter,
|
30 | timeout
|
31 | })
|
32 | let filenames = yield aglob(pattern, { cwd })
|
33 | for (let filename of filenames) {
|
34 | mocha.addFile(path.resolve(cwd, filename))
|
35 | }
|
36 | let failures = yield new Promise((resolve) => {
|
37 | mocha.run((failures) => resolve(failures)
|
38 | )
|
39 | })
|
40 | process.on('exit', () => process.exit(failures))
|
41 | return failures
|
42 | })
|
43 | }
|
44 |
|
45 | Object.assign(amocha, { coverage })
|
46 |
|
47 | module.exports = amocha
|