Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JS for globbing integration test instead of bash shell #2918

Merged
merged 3 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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.

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