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 Mocha = require('mocha')
|
17 |
|
18 |
|
19 | async function amocha(pattern, options = {}) {
|
20 | const {
|
21 | cwd = process.cwd(),
|
22 | reporter = 'spec',
|
23 | timeout = 3000
|
24 | } = options
|
25 | const mocha = new Mocha({
|
26 | reporter,
|
27 | timeout
|
28 | })
|
29 | const filenames = await aglob(pattern, { cwd })
|
30 | for (const filename of filenames) {
|
31 | mocha.addFile(path.resolve(cwd, filename))
|
32 | }
|
33 | const failures = await new Promise((resolve) => {
|
34 | mocha.run((failures) => resolve(failures)
|
35 | )
|
36 | })
|
37 | process.on('exit', () => process.exit(failures))
|
38 | return failures
|
39 | }
|
40 |
|
41 | module.exports = amocha
|