-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
32 lines (28 loc) · 871 Bytes
/
test.js
File metadata and controls
32 lines (28 loc) · 871 Bytes
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
import Mocha from 'mocha';
import fs from 'fs';
import path from 'path';
// Instantiate a Mocha instance.
const mocha = new Mocha({
ui: 'bdd',
timeout: 15000
});
function addDirectory(testDir, exclude, regex = /\.test\.jsx?$/) {
// Add each .js file to the mocha instance
fs.readdirSync(testDir)
.forEach((file) => {
const filePath = path.resolve(testDir, file);
if (exclude.test(filePath)) return true;
if (fs.statSync(filePath).isDirectory()) {
addDirectory(filePath, exclude, regex);
} else if (regex.test(file)) {
// Only add the test.js files
mocha.addFile(filePath);
}
return true;
});
}
addDirectory(path.resolve(__dirname, 'src'), /(templates|fixtures)/);
// Run the tests.
mocha.run((failures) => {
process.exit(failures); // exit with non-zero status if there were failures
});