This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorder cmdline options top-level test suites lexically (mochajs#3674)
* refactor(integration/options.spec.js): Reorder top-level test suites lexically Reordered each cmdline option's test suite alphabetically. No code changes. * test(integration/options): Break out tests into option-specific spec files Made individual spec files for various options from the original. * test(options/opts.spec.js): Fix issue on Windows [skip travis] Removed cwd setting as (hopefully) unneeded since the test deals with generating error from nonexistent file. * test(options/help.spec.js): Windows bughunt [skip travis][skip netlify] * test(options/help.spec.js): Fix spawnOpts cwd Must use platform-specific `path.join` for `spawnOpts.cwd`, or it fails on Windows. * test: Modify describe titles for consistency Updated a couple suite descriptions for consistency.
- Loading branch information
Showing
17 changed files
with
989 additions
and
854 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
var path = require('path').posix; | ||
var helpers = require('../helpers'); | ||
var runMochaJSON = helpers.runMochaJSON; | ||
|
||
describe('--async-only', function() { | ||
var args = []; | ||
|
||
before(function() { | ||
args = ['--async-only']; | ||
}); | ||
|
||
it('should fail synchronous specs', function(done) { | ||
var fixture = path.join('options', 'async-only-sync'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should allow asynchronous specs', function(done) { | ||
var fixture = path.join('options', 'async-only-async'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have passed'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,128 @@ | ||
'use strict'; | ||
|
||
var path = require('path').posix; | ||
var helpers = require('../helpers'); | ||
var runMochaJSON = helpers.runMochaJSON; | ||
|
||
describe('--bail', function() { | ||
var args = []; | ||
|
||
before(function() { | ||
args = ['--bail']; | ||
}); | ||
|
||
it('should stop after the first error', function(done) { | ||
var fixture = path.join('options', 'bail'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have passed test', 'should display this spec') | ||
.and('to have failed test', 'should only display this error') | ||
.and('to have passed test count', 1) | ||
.and('to have failed test count', 1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop after the first error - async', function(done) { | ||
var fixture = path.join('options', 'bail-async'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have passed test', 'should display this spec') | ||
.and('to have failed test', 'should only display this error') | ||
.and('to have passed test count', 1) | ||
.and('to have failed test count', 1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop all tests after failing "before" hook', function(done) { | ||
var fixture = path.join('options', 'bail-with-before'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have failed test count', 1) | ||
.and('to have failed test', '"before all" hook: before suite1') | ||
.and('to have passed test count', 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop all tests after failing "beforeEach" hook', function(done) { | ||
var fixture = path.join('options', 'bail-with-beforeEach'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have failed test count', 1) | ||
.and( | ||
'to have failed test', | ||
'"before each" hook: beforeEach suite1 for "test suite1"' | ||
) | ||
.and('to have passed test count', 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop all tests after failing test', function(done) { | ||
var fixture = path.join('options', 'bail-with-test'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have failed test count', 1) | ||
.and('to have failed test', 'test suite1') | ||
.and('to have passed test count', 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop all tests after failing "after" hook', function(done) { | ||
var fixture = path.join('options', 'bail-with-after'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have failed test count', 1) | ||
.and('to have failed test', '"after all" hook: after suite1A') | ||
.and('to have passed test count', 2) | ||
.and('to have passed test order', 'test suite1', 'test suite1A'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should stop all tests after failing "afterEach" hook', function(done) { | ||
var fixture = path.join('options', 'bail-with-afterEach'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed') | ||
.and('to have failed test count', 1) | ||
.and( | ||
'to have failed test', | ||
'"after each" hook: afterEach suite1A for "test suite1A"' | ||
) | ||
.and('to have passed test count', 2) | ||
.and('to have passed test order', 'test suite1', 'test suite1A'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,23 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'); | ||
var invokeMocha = helpers.invokeMocha; | ||
|
||
describe('--compilers', function() { | ||
var args = []; | ||
|
||
before(function() { | ||
args = ['--compilers', 'coffee:coffee-script/register']; | ||
}); | ||
|
||
it('should fail', function(done) { | ||
invokeMocha(args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res.code, 'to be', 1); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,58 @@ | ||
'use strict'; | ||
|
||
var path = require('path').posix; | ||
var helpers = require('../helpers'); | ||
var runMochaJSON = helpers.runMochaJSON; | ||
|
||
describe('--delay', function() { | ||
var args = []; | ||
|
||
before(function() { | ||
args = ['--delay']; | ||
}); | ||
|
||
it('should run the generated test suite', function(done) { | ||
var fixture = path.join('options', 'delay'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have passed').and('to have passed test count', 1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should execute exclusive tests only', function(done) { | ||
var fixture = path.join('options', 'delay-only'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have passed') | ||
.and('to have passed test count', 2) | ||
.and( | ||
'to have passed test order', | ||
'should run this', | ||
'should run this, too' | ||
); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should throw an error if the test suite failed to run', function(done) { | ||
var fixture = path.join('options', 'delay-fail'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res, 'to have failed').and( | ||
'to have failed test', | ||
'Uncaught error outside test suite' | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,75 @@ | ||
'use strict'; | ||
|
||
var path = require('path').posix; | ||
var helpers = require('../helpers'); | ||
var runMochaJSON = helpers.runMochaJSON; | ||
var resolvePath = helpers.resolveFixturePath; | ||
|
||
describe('--exclude', function() { | ||
/* | ||
* Runs mocha in {path} with the given args. | ||
* Calls handleResult with the result. | ||
* | ||
* @param {string} fixture | ||
* @param {string[]} args | ||
* @param {function} handleResult | ||
* @param {function} done | ||
*/ | ||
function runMochaTest(fixture, args, handleResult, done) { | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
handleResult(res); | ||
done(); | ||
}); | ||
} | ||
|
||
it('should exclude specific files', function(done) { | ||
var fixtures = path.join('options', 'exclude', '*'); | ||
runMochaTest( | ||
fixtures, | ||
['--exclude', resolvePath(path.join('options', 'exclude', 'fail'))], | ||
function(res) { | ||
expect(res, 'to have passed') | ||
.and('to have run test', 'should find this test') | ||
.and('not to have pending tests'); | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should exclude globbed files', function(done) { | ||
var fixtures = path.join('options', 'exclude', '**', '*'); | ||
runMochaTest( | ||
fixtures, | ||
['--exclude', '**/fail.fixture.js'], | ||
function(res) { | ||
expect(res, 'to have passed') | ||
.and('not to have pending tests') | ||
.and('to have passed test count', 2); | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should exclude multiple patterns', function(done) { | ||
var fixtures = path.join('options', 'exclude', '**', '*'); | ||
runMochaTest( | ||
fixtures, | ||
[ | ||
'--exclude', | ||
resolvePath(path.join('options', 'exclude', 'fail')), | ||
'--exclude', | ||
resolvePath(path.join('options', 'exclude', 'nested', 'fail')) | ||
], | ||
function(res) { | ||
expect(res, 'to have passed') | ||
.and('not to have pending tests') | ||
.and('to have passed test count', 2); | ||
}, | ||
done | ||
); | ||
}); | ||
}); |
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,68 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'); | ||
var runMochaJSON = helpers.runMochaJSON; | ||
|
||
describe('--exit', function() { | ||
var behaviors = { | ||
enabled: '--exit', | ||
disabled: '--no-exit' | ||
}; | ||
|
||
/** | ||
* Returns a test that executes Mocha in a subprocess with either | ||
* `--exit`, `--no-exit`, or default behavior. | ||
* | ||
* @param {boolean} shouldExit - Expected result; `true` if Mocha should | ||
* have force-killed the process. | ||
* @param {string} [behavior] - 'enabled' or 'disabled' | ||
* @returns {Function} async function implementing the test | ||
*/ | ||
var runExit = function(shouldExit, behavior) { | ||
return function(done) { | ||
var timeout = this.timeout(); | ||
this.timeout(0); | ||
this.slow(Infinity); | ||
|
||
var didExit = true; | ||
var timeoutObj; | ||
var fixture = 'exit.fixture.js'; | ||
var args = behaviors[behavior] ? [behaviors[behavior]] : []; | ||
|
||
var mocha = runMochaJSON(fixture, args, function postmortem(err) { | ||
clearTimeout(timeoutObj); | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(didExit, 'to be', shouldExit); | ||
done(); | ||
}); | ||
|
||
// If this callback happens, then Mocha didn't automatically exit. | ||
timeoutObj = setTimeout(function() { | ||
didExit = false; | ||
// This is the only way to kill the child, afaik. | ||
// After the process ends, the callback to `run()` above is handled. | ||
mocha.kill('SIGINT'); | ||
}, timeout - 500); | ||
}; | ||
}; | ||
|
||
describe('default behavior', function() { | ||
it('should force exit after root suite completion', runExit(false)); | ||
}); | ||
|
||
describe('when enabled', function() { | ||
it( | ||
'should force exit after root suite completion', | ||
runExit(true, 'enabled') | ||
); | ||
}); | ||
|
||
describe('when disabled', function() { | ||
it( | ||
'should not force exit after root suite completion', | ||
runExit(false, 'disabled') | ||
); | ||
}); | ||
}); |
Oops, something went wrong.