From 43369f2c3fdc466c60d7622f2af2f9f29029a5a9 Mon Sep 17 00:00:00 2001
From: ScottFreeCode <ScottFreeCode@users.noreply.github.com>
Date: Sat, 8 Jul 2017 22:01:14 -0400
Subject: [PATCH 1/3] Eliminate glob.sh

---
 Makefile                                      |  6 +-
 test/glob/glob.sh                             | 66 -----------------
 .../fixtures}/glob/glob.spec.js               |  2 +-
 test/integration/glob.spec.js                 | 71 +++++++++++++++++++
 4 files changed, 73 insertions(+), 72 deletions(-)
 delete mode 100755 test/glob/glob.sh
 rename test/{ => integration/fixtures}/glob/glob.spec.js (67%)
 create mode 100644 test/integration/glob.spec.js

diff --git a/Makefile b/Makefile
index 2fa367e8ff..13c50b8643 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ lint:
 	@printf "==> [Test :: Lint]\n"
 	npm run lint
 
-test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only test-global-only
+test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-requires test-reporters test-only test-global-only
 
 test-browser: clean BUILDTMP/mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports
 
@@ -107,10 +107,6 @@ test-exports:
 	$(call test_node,exports) --ui exports \
 		test/interfaces/exports.spec
 
-test-glob:
-	@printf "==> [Test :: Glob]\n"
-	bash ./test/glob/glob.sh
-
 test-reporters:
 	@printf "==> [Test :: Reporters]\n"
 	$(call test_node,reporters) test/reporters/*.spec.js
diff --git a/test/glob/glob.sh b/test/glob/glob.sh
deleted file mode 100755
index c0cb21d3f8..0000000000
--- a/test/glob/glob.sh
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/bash
-REL_SCRIPT_DIR="`dirname \"$0\"`"
-SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
-
-cd $SCRIPT_DIR || {
-    echo Could not cd to $SCRIPT_DIR from `pwd`
-    exit 1
-}
-
-../../bin/mocha -R json-stream  ./*.js > /tmp/mocha-glob.txt || {
-    echo Globbing ./*.js in `pwd` failed.
-    exit 1
-}
-
-cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' || {
-    echo Globbing ./*.js in `pwd` should match glob.js with one test inside.
-    exit 1
-}
-
-../../bin/mocha -R json-stream ./*-none.js 2> /tmp/mocha-glob.txt && {
-    echo Globbing './*-none.js' in `pwd` failed.
-    exit 1
-}
-
-cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
-    echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
-    exit 1
-}
-
-../../bin/mocha -R json-stream  ./*.js ./*-none.js >& /tmp/mocha-glob.txt || {
-    echo Globbing ./*.js ./*-none.js in `pwd` failed.
-    exit 1
-}
-
-cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' &&
-cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
-    echo Globbing ./*.js ./*-none.js in `pwd` should match glob.js with one test inside and display one warning for the non-existing file.
-    exit 1
-}
-
-# Globbing in windows command-shell differs completely from unix-style globbing.
-# In bash, the shell expands globs and passes the result to executables.
-# In windows, the shell passes globs unexpanded, executables do expansion if they support it.
-# Adding single-quotes around the glob below makes bash pass glob unexpanded,
-#     allowing us to test windows-style globbing in bash.
-../../bin/mocha -R json-stream  './*.js' > /tmp/mocha-glob.txt || {
-    echo Globbing './*.js' in `pwd` failed.
-    exit 1
-}
-
-cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' || {
-    echo Globbing './*.js' in `pwd` should match glob.js with one test inside.
-    exit 1
-}
-
-../../bin/mocha -R json-stream  './*-none.js' 2> /tmp/mocha-glob.txt && {
-    echo Globbing './*-none.js' in `pwd` failed.
-    exit 1
-}
-
-cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
-    echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
-    exit 1
-}
-
-echo Glob-test passed.
diff --git a/test/glob/glob.spec.js b/test/integration/fixtures/glob/glob.spec.js
similarity index 67%
rename from test/glob/glob.spec.js
rename to test/integration/fixtures/glob/glob.spec.js
index eca3733898..235c2f8417 100644
--- a/test/glob/glob.spec.js
+++ b/test/integration/fixtures/glob/glob.spec.js
@@ -2,6 +2,6 @@
 
 describe('globbing test', function () {
   it('should find this test', function () {
-    // see glob.sh for details
+    // see test/integration/glob.spec.js for details
   });
 });
diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js
new file mode 100644
index 0000000000..fb2bbf4353
--- /dev/null
+++ b/test/integration/glob.spec.js
@@ -0,0 +1,71 @@
+'use strict';
+
+var expect = require('expect.js');
+var exec = require('child_process').exec;
+var path = require('path');
+
+var node = '"' + process.execPath + '"';
+
+describe('globbing', function () {
+  describe('by the shell', function () {
+    it('should find the first level test', function (done) {
+      testGlob.shouldSucceed('./*.js', function (results) {
+        expect(results.stdout).to.contain('["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,');
+      }, done);
+    });
+
+    it('should not find a non-matching pattern', function (done) {
+      testGlob.shouldFail('./*-none.js', function (results) {
+        expect(results.stderr).to.contain('Could not find any test files matching pattern');
+      }, done);
+    });
+
+    it('should handle both matching and non-matching patterns in the same command', function (done) {
+      testGlob.shouldSucceed('./*.js ./*-none.js', function (results) {
+        expect(results.stdout).to.contain('["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,');
+        expect(results.stderr).to.contain('Could not find any test files matching pattern');
+      }, done);
+    });
+  });
+
+  describe('by Mocha', function () {
+    it('should find the first level test', function (done) {
+      testGlob.shouldSucceed('"./*.js"', function (results) {
+        expect(results.stdout).to.contain('["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,');
+      }, done);
+    });
+
+    it('should not find a non-matching pattern', function (done) {
+      testGlob.shouldFail('"./*-none.js"', function (results) {
+        expect(results.stderr).to.contain('Could not find any test files matching pattern');
+      }, done);
+    });
+
+    it('should handle both matching and non-matching patterns in the same command', function (done) {
+      testGlob.shouldSucceed('"./*.js" "./*-none.js"', function (results) {
+        expect(results.stdout).to.contain('["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,');
+        expect(results.stderr).to.contain('Could not find any test files matching pattern');
+      }, done);
+    });
+  });
+});
+
+var testGlob = {
+  shouldSucceed: execMochaWith(function shouldNotError (error) { if (error) { throw error; } }),
+
+  shouldFail: execMochaWith(function shouldFailWithStderr (error, stderr) { expect(error && error.message).to.contain(stderr); })
+};
+
+function execMochaWith (validate) {
+  return function execMocha (glob, assertOn, done) {
+    exec(node + ' "' + path.join('..', '..', '..', '..', 'bin', 'mocha') + '" -R json-stream ' + glob, { cwd: path.join(__dirname, 'fixtures', 'glob') }, function (error, stdout, stderr) {
+      try {
+        validate(error, stderr);
+        assertOn({ stdout: stdout, stderr: stderr });
+        done();
+      } catch (assertion) {
+        done(assertion);
+      }
+    });
+  };
+}

From c2aca713b6200de871baf28e3e7a7e6bc1600463 Mon Sep 17 00:00:00 2001
From: ScottFreeCode <ScottFreeCode@users.noreply.github.com>
Date: Sat, 8 Jul 2017 22:33:26 -0400
Subject: [PATCH 2/3] Add tests for double-star behavior

---
 .../fixtures/glob/nested/glob.spec.js         |  7 +++++++
 test/integration/glob.spec.js                 | 21 +++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 test/integration/fixtures/glob/nested/glob.spec.js

diff --git a/test/integration/fixtures/glob/nested/glob.spec.js b/test/integration/fixtures/glob/nested/glob.spec.js
new file mode 100644
index 0000000000..235c2f8417
--- /dev/null
+++ b/test/integration/fixtures/glob/nested/glob.spec.js
@@ -0,0 +1,7 @@
+'use strict';
+
+describe('globbing test', function () {
+  it('should find this test', function () {
+    // see test/integration/glob.spec.js for details
+  });
+});
diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js
index fb2bbf4353..df16d28283 100644
--- a/test/integration/glob.spec.js
+++ b/test/integration/glob.spec.js
@@ -47,6 +47,27 @@ describe('globbing', function () {
         expect(results.stderr).to.contain('Could not find any test files matching pattern');
       }, done);
     });
+
+    describe('double-starred', function () {
+      it('should find the tests on multiple levels', function (done) {
+        testGlob.shouldSucceed('"./**/*.js"', function (results) {
+          expect(results.stdout).to.contain('["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,');
+        }, done);
+      });
+
+      it('should not find a non-matching pattern', function (done) {
+        testGlob.shouldFail('"./**/*-none.js"', function (results) {
+          expect(results.stderr).to.contain('Could not find any test files matching pattern');
+        }, done);
+      });
+
+      it('should handle both matching and non-matching patterns in the same command', function (done) {
+        testGlob.shouldSucceed('"./**/*.js" "./**/*-none.js"', function (results) {
+          expect(results.stdout).to.contain('["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,');
+          expect(results.stderr).to.contain('Could not find any test files matching pattern');
+        }, done);
+      });
+    });
   });
 });
 

From 6d0859e644bcd80f52b59d2ed1a3ea7a5d7c7927 Mon Sep 17 00:00:00 2001
From: ScottFreeCode <ScottFreeCode@users.noreply.github.com>
Date: Tue, 1 Aug 2017 23:09:51 -0400
Subject: [PATCH 3/3] Work around Node 0.10 Windows flake when testing

---
 test/integration/glob.spec.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js
index df16d28283..4d1c5a52f4 100644
--- a/test/integration/glob.spec.js
+++ b/test/integration/glob.spec.js
@@ -77,13 +77,22 @@ var testGlob = {
   shouldFail: execMochaWith(function shouldFailWithStderr (error, stderr) { expect(error && error.message).to.contain(stderr); })
 };
 
+var isFlakeyNode = (function () {
+  var version = process.versions.node.split('.');
+  return version[0] === '0' && version[1] === '10' && process.platform === 'win32';
+}());
+
 function execMochaWith (validate) {
   return function execMocha (glob, assertOn, done) {
     exec(node + ' "' + path.join('..', '..', '..', '..', 'bin', 'mocha') + '" -R json-stream ' + glob, { cwd: path.join(__dirname, 'fixtures', 'glob') }, function (error, stdout, stderr) {
       try {
         validate(error, stderr);
-        assertOn({ stdout: stdout, stderr: stderr });
-        done();
+        if (isFlakeyNode && error && (stderr === '')) {
+          execMocha(glob, assertOn, done);
+        } else {
+          assertOn({ stdout: stdout, stderr: stderr });
+          done();
+        }
       } catch (assertion) {
         done(assertion);
       }