2019-05-31 19:33:56 +03:00
|
|
|
const Mocha = require('mocha');
|
|
|
|
const fs = require('fs-plus');
|
|
|
|
const { assert } = require('chai');
|
2016-05-24 09:23:27 +03:00
|
|
|
|
2019-05-31 19:33:56 +03:00
|
|
|
module.exports = function(testPaths) {
|
|
|
|
global.assert = assert;
|
2016-05-24 09:23:27 +03:00
|
|
|
|
2017-08-01 16:02:44 +03:00
|
|
|
let reporterOptions = {
|
|
|
|
reporterEnabled: 'list'
|
2019-05-31 19:33:56 +03:00
|
|
|
};
|
2017-08-01 16:02:44 +03:00
|
|
|
|
|
|
|
if (process.env.TEST_JUNIT_XML_PATH) {
|
|
|
|
reporterOptions = {
|
|
|
|
reporterEnabled: 'list, mocha-junit-reporter',
|
|
|
|
mochaJunitReporterReporterOptions: {
|
|
|
|
mochaFile: process.env.TEST_JUNIT_XML_PATH
|
|
|
|
}
|
2019-05-31 19:33:56 +03:00
|
|
|
};
|
2017-08-01 16:02:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const mocha = new Mocha({
|
|
|
|
reporter: 'mocha-multi-reporters',
|
|
|
|
reporterOptions
|
2019-05-31 19:33:56 +03:00
|
|
|
});
|
2018-08-24 22:00:44 +03:00
|
|
|
|
2016-05-24 09:23:27 +03:00
|
|
|
for (let testPath of testPaths) {
|
|
|
|
if (fs.isDirectorySync(testPath)) {
|
|
|
|
for (let testFilePath of fs.listTreeSync(testPath)) {
|
2016-08-11 17:16:18 +03:00
|
|
|
if (/\.test\.(coffee|js)$/.test(testFilePath)) {
|
2019-05-31 19:33:56 +03:00
|
|
|
mocha.addFile(testFilePath);
|
2016-05-24 09:23:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-31 19:33:56 +03:00
|
|
|
mocha.addFile(testPath);
|
2016-05-24 09:23:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 22:00:44 +03:00
|
|
|
mocha.run(failures => {
|
2016-05-24 09:23:27 +03:00
|
|
|
if (failures === 0) {
|
2019-05-31 19:33:56 +03:00
|
|
|
process.exit(0);
|
2016-05-24 09:23:27 +03:00
|
|
|
} else {
|
2019-05-31 19:33:56 +03:00
|
|
|
process.exit(1);
|
2016-05-24 09:23:27 +03:00
|
|
|
}
|
2019-05-31 19:33:56 +03:00
|
|
|
});
|
|
|
|
};
|