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.
Improve hook pattern of 'this.skip()' in beforeAll (mochajs#4223)
- Loading branch information
Showing
6 changed files
with
188 additions
and
161 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 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
71 changes: 42 additions & 29 deletions
71
test/integration/fixtures/pending/skip-async-before-hooks.fixture.js
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 |
---|---|---|
@@ -1,59 +1,72 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('outer suite', function () { | ||
|
||
before(function () { | ||
console.log('outer before'); | ||
describe('outer suite', function() { | ||
var runOrder = []; | ||
before(function() { | ||
runOrder.push('outer before'); | ||
}); | ||
|
||
it('should run this test', function () { }); | ||
|
||
describe('inner suite', function () { | ||
it('should run test-1', function() { | ||
runOrder.push('should run test-1'); | ||
}); | ||
|
||
before(function (done) { | ||
console.log('inner before'); | ||
describe('inner suite', function() { | ||
before(function(done) { | ||
runOrder.push('inner before'); | ||
var self = this; | ||
setTimeout(function () { | ||
setTimeout(function() { | ||
self.skip(); // done() is not required | ||
}, 0); | ||
}); | ||
|
||
beforeEach(function () { | ||
throw new Error('beforeEach should not run'); | ||
before(function() { | ||
runOrder.push('inner before-2 should not run'); | ||
}); | ||
|
||
afterEach(function () { | ||
throw new Error('afterEach should not run'); | ||
beforeEach(function() { | ||
runOrder.push('beforeEach should not run'); | ||
}); | ||
|
||
it('should not run this test', function () { | ||
throw new Error('inner suite test should not run'); | ||
afterEach(function() { | ||
runOrder.push('afterEach should not run'); | ||
}); | ||
|
||
after(function() { | ||
runOrder.push('inner after'); | ||
}); | ||
|
||
after(function () { | ||
console.log('inner after'); | ||
it('should not run this test', function() { | ||
throw new Error('inner suite test should not run'); | ||
}); | ||
|
||
describe('skipped suite', function () { | ||
before(function () { | ||
console.log('skipped before'); | ||
describe('skipped suite', function() { | ||
before(function() { | ||
runOrder.push('skipped suite before should not run'); | ||
}); | ||
|
||
it('should not run this test', function () { | ||
it('should not run this test', function() { | ||
throw new Error('skipped suite test should not run'); | ||
}); | ||
|
||
after(function () { | ||
console.log('skipped after'); | ||
after(function() { | ||
runOrder.push('skipped suite after should not run'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
it('should run this test', function () { }); | ||
|
||
after(function () { | ||
console.log('outer after'); | ||
it('should run test-2', function() { | ||
runOrder.push('should run test-2'); | ||
}); | ||
|
||
after(function() { | ||
runOrder.push('outer after'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'outer before', | ||
'should run test-1', 'should run test-2', | ||
'inner before', 'inner after', | ||
'outer after' | ||
]); | ||
throw new Error('should throw this error'); | ||
}); | ||
}); |
66 changes: 39 additions & 27 deletions
66
test/integration/fixtures/pending/skip-sync-before-hooks.fixture.js
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 |
---|---|---|
@@ -1,57 +1,69 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('outer suite', function () { | ||
|
||
before(function () { | ||
console.log('outer before'); | ||
describe('outer suite', function() { | ||
var runOrder = []; | ||
before(function() { | ||
runOrder.push('outer before'); | ||
}); | ||
|
||
it('should run this test', function () { }); | ||
it('should run test-1', function() { | ||
runOrder.push('should run test-1'); | ||
}); | ||
|
||
describe('inner suite', function () { | ||
before(function () { | ||
describe('inner suite', function() { | ||
before(function() { | ||
runOrder.push('inner before'); | ||
this.skip(); | ||
}); | ||
|
||
before(function () { | ||
console.log('inner before'); | ||
before(function() { | ||
runOrder.push('inner before-2 should not run'); | ||
}); | ||
|
||
beforeEach(function () { | ||
throw new Error('beforeEach should not run'); | ||
beforeEach(function() { | ||
runOrder.push('beforeEach should not run'); | ||
}); | ||
|
||
afterEach(function () { | ||
throw new Error('afterEach should not run'); | ||
afterEach(function() { | ||
runOrder.push('afterEach should not run'); | ||
}); | ||
|
||
after(function () { | ||
console.log('inner after'); | ||
after(function() { | ||
runOrder.push('inner after'); | ||
}); | ||
|
||
it('should never run this test', function () { | ||
it('should never run this test', function() { | ||
throw new Error('inner suite test should not run'); | ||
}); | ||
|
||
describe('skipped suite', function () { | ||
before(function () { | ||
console.log('skipped before'); | ||
describe('skipped suite', function() { | ||
before(function() { | ||
runOrder.push('skipped suite before should not run'); | ||
}); | ||
|
||
it('should never run this test', function () { | ||
it('should never run this test', function() { | ||
throw new Error('skipped suite test should not run'); | ||
}); | ||
|
||
after(function () { | ||
console.log('skipped after'); | ||
after(function() { | ||
runOrder.push('skipped suite after should not run'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should run this test', function () { }); | ||
|
||
after(function () { | ||
console.log('outer after'); | ||
}) | ||
it('should run test-2', function() { | ||
runOrder.push('should run test-2'); | ||
}); | ||
|
||
after(function() { | ||
runOrder.push('outer after'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'outer before', | ||
'should run test-1', 'should run test-2', | ||
'inner before', 'inner after', | ||
'outer after' | ||
]); | ||
throw new Error('should throw this error'); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
test/integration/fixtures/pending/skip-sync-before-inner.fixture.js
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,38 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('outer suite', function() { | ||
var runOrder = []; | ||
before(function() { | ||
runOrder.push('outer before'); | ||
this.skip(); | ||
}); | ||
|
||
it('should never run this outer test', function() { | ||
throw new Error('outer suite test should not run'); | ||
}); | ||
|
||
describe('inner suite', function() { | ||
before(function() { runOrder.push('no inner before'); }); | ||
before(function(done) { runOrder.push('no inner before'); done(); }); | ||
before(async function() { runOrder.push('no inner before'); }); | ||
before(function() { return Promise.resolve(runOrder.push('no inner before')) }); | ||
|
||
after(function() { runOrder.push('no inner after'); }); | ||
after(function(done) { runOrder.push('no inner after'); done(); }); | ||
after(async function() { runOrder.push('no inner after'); }); | ||
after(function() { return Promise.resolve(runOrder.push('no inner after')) }); | ||
|
||
it('should never run this inner test', function() { | ||
throw new Error('inner suite test should not run'); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
runOrder.push('outer after'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'outer before', 'outer after' | ||
]); | ||
throw new Error('should throw this error'); | ||
}); | ||
}); |
Oops, something went wrong.