-
-
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.
- Loading branch information
1 parent
82d879f
commit c0e6b68
Showing
4 changed files
with
73 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,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); | ||
} | ||
}); | ||
}; | ||
} |