1 | const Mocha = require('mocha')
|
2 | const fs = require('fs')
|
3 | const path = require('path')
|
4 |
|
5 | // Instantiate a Mocha instance.
|
6 | var mocha = new Mocha()
|
7 |
|
8 | var testDir = 'test'
|
9 |
|
10 | // Add each .js file to the mocha instance
|
11 | fs.readdirSync(testDir).filter(function (file) {
|
12 | // Only keep the .js files
|
13 | return file.substr(-3) === '.js'
|
14 | }).forEach(function (file) {
|
15 | mocha.addFile(path.join(testDir, file))
|
16 | })
|
17 |
|
18 | // Run the tests.
|
19 | mocha.run(function (failures) {
|
20 | process.on('exit', function () {
|
21 | process.exit(failures)
|
22 | })
|
23 | })
|