Skip to content

Commit

Permalink
Eliminate glob.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottFreeCode committed Aug 1, 2017
1 parent 82d879f commit c0e6b68
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 72 deletions.
6 changes: 1 addition & 5 deletions Makefile
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 @@ -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
Expand Down
66 changes: 0 additions & 66 deletions test/glob/glob.sh

This file was deleted.

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
});
});
71 changes: 71 additions & 0 deletions 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);
}
});
};
}

0 comments on commit c0e6b68

Please sign in to comment.