-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2918 from mochajs/no-shell-test
* Eliminate glob.sh * Add tests for double-star behavior * Work around Node 0.10 Windows flake when testing
- Loading branch information
Showing
5 changed files
with
110 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}; | ||
} |