Skip to content

Commit

Permalink
Merge pull request #2918 from mochajs/no-shell-test
Browse files Browse the repository at this point in the history
* Eliminate glob.sh

* Add tests for double-star behavior

* Work around Node 0.10 Windows flake when testing
  • Loading branch information
ScottFreeCode authored Aug 2, 2017
2 parents 13b8340 + 8710438 commit 075bd51
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 72 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -113,10 +113,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
Expand Down
66 changes: 0 additions & 66 deletions test/glob/glob.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
7 changes: 7 additions & 0 deletions test/integration/fixtures/glob/nested/glob.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('globbing test', function () {
it('should find this test', function () {
// see test/integration/glob.spec.js for details
});
});
101 changes: 101 additions & 0 deletions test/integration/glob.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'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);
});

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);
});
});
});
});

var testGlob = {
shouldSucceed: execMochaWith(function shouldNotError (error) { if (error) { throw error; } }),

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);
if (isFlakeyNode && error && (stderr === '')) {
execMocha(glob, assertOn, done);
} else {
assertOn({ stdout: stdout, stderr: stderr });
done();
}
} catch (assertion) {
done(assertion);
}
});
};
}

0 comments on commit 075bd51

Please sign in to comment.