improve `mocha` tests (#2797)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 16 Jan 2018 09:51:25 +0000 (17:51 +0800)
committerGitHub <noreply@github.com>
Tue, 16 Jan 2018 09:51:25 +0000 (17:51 +0800)
- workaround sporadic delays from Travis CI

test/mocha.js

index 411f52c..fb8c384 100644 (file)
@@ -1,29 +1,24 @@
-var Mocha = require('mocha'),
-    fs = require('fs'),
-    path = require('path');
+var fs = require("fs");
+var Mocha = require("mocha");
+var path = require("path");
 
-// Instantiate a Mocha instance.
-var mocha = new Mocha({});
-
-var testDir = __dirname + '/mocha/';
-
-// Add each .js file to the mocha instance
-fs.readdirSync(testDir).filter(function(file){
-    // Only keep the .js files
-    return file.substr(-3) === '.js';
+// Instantiate a Mocha instance
+var mocha = new Mocha({
+    timeout: 5000
+});
+var testDir = __dirname + "/mocha/";
 
-}).forEach(function(file){
-    mocha.addFile(
-        path.join(testDir, file)
-    );
+// Add each .js file to the Mocha instance
+fs.readdirSync(testDir).filter(function(file) {
+    return /\.js$/.test(file);
+}).forEach(function(file) {
+    mocha.addFile(path.join(testDir, file));
 });
 
 module.exports = function() {
     mocha.run(function(failures) {
-        if (failures !== 0) {
-            process.on('exit', function () {
-                process.exit(failures);
-            });
-        }
+        if (failures) process.on("exit", function() {
+            process.exit(failures);
+        });
     });
-};
\ No newline at end of file
+};