☕️ Classic, reliable, trusted test framework for Node.js and the browser
Eliminate glob.sh
ScottFreeCodec0e6b68847e5
diff --git a/Makefile b/Makefileindex 2fa367e8..13c50b86 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-onlytest-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.jsdiff --git a/test/glob/glob.sh b/test/glob/glob.shdeleted file mode 100755index c0cb21d3..00000000--- 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.jssimilarity index 67%rename from test/glob/glob.spec.jsrename to test/integration/fixtures/glob/glob.spec.jsindex eca37338..235c2f84 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.jsnew file mode 100644index 00000000..fb2bbf43--- /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);+ }+ });+ };+}