Skip to content

Commit a1f0298

Browse files
committed
additional tests
1 parent 399d958 commit a1f0298

File tree

4 files changed

+164
-130
lines changed

4 files changed

+164
-130
lines changed
Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,72 @@
11
'use strict';
2+
var assert = require('assert');
23

3-
describe('outer suite', function () {
4-
5-
before(function () {
6-
console.log('outer before');
4+
describe('outer suite', function() {
5+
var runOrder = [];
6+
before(function() {
7+
runOrder.push('outer before');
78
});
89

9-
it('should run this test', function () { });
10-
11-
describe('inner suite', function () {
10+
it('should run test-1', function() {
11+
runOrder.push('should run test-1');
12+
});
1213

13-
before(function (done) {
14-
console.log('inner before');
14+
describe('inner suite', function() {
15+
before(function(done) {
16+
runOrder.push('inner before');
1517
var self = this;
16-
setTimeout(function () {
18+
setTimeout(function() {
1719
self.skip(); // done() is not required
1820
}, 0);
1921
});
2022

21-
beforeEach(function () {
22-
throw new Error('beforeEach should not run');
23+
before(function() {
24+
runOrder.push('inner before-2 should not run');
2325
});
2426

25-
afterEach(function () {
26-
throw new Error('afterEach should not run');
27+
beforeEach(function() {
28+
runOrder.push('beforeEach should not run');
2729
});
2830

29-
it('should not run this test', function () {
30-
throw new Error('inner suite test should not run');
31+
afterEach(function() {
32+
runOrder.push('afterEach should not run');
33+
});
34+
35+
after(function() {
36+
runOrder.push('inner after');
3137
});
3238

33-
after(function () {
34-
console.log('inner after');
39+
it('should not run this test', function() {
40+
throw new Error('inner suite test should not run');
3541
});
3642

37-
describe('skipped suite', function () {
38-
before(function () {
39-
console.log('skipped before');
43+
describe('skipped suite', function() {
44+
before(function() {
45+
runOrder.push('skipped suite before should not run');
4046
});
4147

42-
it('should not run this test', function () {
48+
it('should not run this test', function() {
4349
throw new Error('skipped suite test should not run');
4450
});
4551

46-
after(function () {
47-
console.log('skipped after');
52+
after(function() {
53+
runOrder.push('skipped suite after should not run');
4854
});
4955
});
50-
5156
});
5257

53-
it('should run this test', function () { });
54-
55-
after(function () {
56-
console.log('outer after');
58+
it('should run test-2', function() {
59+
runOrder.push('should run test-2');
5760
});
5861

62+
after(function() {
63+
runOrder.push('outer after');
64+
assert.deepStrictEqual(runOrder, [
65+
'outer before',
66+
'should run test-1', 'should run test-2',
67+
'inner before', 'inner after',
68+
'outer after'
69+
]);
70+
throw new Error('should throw this error');
71+
});
5972
});
Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
11
'use strict';
2+
var assert = require('assert');
23

3-
describe('outer suite', function () {
4-
5-
before(function () {
6-
console.log('outer before');
4+
describe('outer suite', function() {
5+
var runOrder = [];
6+
before(function() {
7+
runOrder.push('outer before');
78
});
89

9-
it('should run this test', function () { });
10+
it('should run test-1', function() {
11+
runOrder.push('should run test-1');
12+
});
1013

11-
describe('inner suite', function () {
12-
before(function () {
14+
describe('inner suite', function() {
15+
before(function() {
16+
runOrder.push('inner before');
1317
this.skip();
1418
});
1519

16-
before(function () {
17-
console.log('inner before');
20+
before(function() {
21+
runOrder.push('inner before-2 should not run');
1822
});
1923

20-
beforeEach(function () {
21-
throw new Error('beforeEach should not run');
24+
beforeEach(function() {
25+
runOrder.push('beforeEach should not run');
2226
});
2327

24-
afterEach(function () {
25-
throw new Error('afterEach should not run');
28+
afterEach(function() {
29+
runOrder.push('afterEach should not run');
2630
});
2731

28-
after(function () {
29-
console.log('inner after');
32+
after(function() {
33+
runOrder.push('inner after');
3034
});
3135

32-
it('should never run this test', function () {
36+
it('should never run this test', function() {
3337
throw new Error('inner suite test should not run');
3438
});
3539

36-
describe('skipped suite', function () {
37-
before(function () {
38-
console.log('skipped before');
40+
describe('skipped suite', function() {
41+
before(function() {
42+
runOrder.push('skipped suite before should not run');
3943
});
4044

41-
it('should never run this test', function () {
45+
it('should never run this test', function() {
4246
throw new Error('skipped suite test should not run');
4347
});
4448

45-
after(function () {
46-
console.log('skipped after');
49+
after(function() {
50+
runOrder.push('skipped suite after should not run');
4751
});
4852
});
4953
});
5054

51-
it('should run this test', function () { });
52-
53-
after(function () {
54-
console.log('outer after');
55-
})
55+
it('should run test-2', function() {
56+
runOrder.push('should run test-2');
57+
});
5658

59+
after(function() {
60+
runOrder.push('outer after');
61+
assert.deepStrictEqual(runOrder, [
62+
'outer before',
63+
'should run test-1', 'should run test-2',
64+
'inner before', 'inner after',
65+
'outer after'
66+
]);
67+
throw new Error('should throw this error');
68+
});
5769
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
var assert = require('assert');
3+
4+
describe('outer suite', function() {
5+
var runOrder = [];
6+
before(function() {
7+
runOrder.push('outer before');
8+
this.skip();
9+
});
10+
11+
it('should never run this outer test', function() {
12+
throw new Error('outer suite test should not run');
13+
});
14+
15+
describe('inner suite', function() {
16+
before(function() { runOrder.push('no inner before'); });
17+
before(function(done) { runOrder.push('no inner before'); done(); });
18+
before(async function() { runOrder.push('no inner before'); });
19+
before(function() { return new Promise(runOrder.push('no inner before')); });
20+
21+
after(function() { runOrder.push('no inner after'); });
22+
after(function(done) { runOrder.push('no inner after'); done(); });
23+
after(async function() { runOrder.push('no inner after'); });
24+
after(function() { return new Promise(runOrder.push('no inner after')); });
25+
26+
it('should never run this inner test', function() {
27+
throw new Error('inner suite test should not run');
28+
});
29+
});
30+
31+
after(function() {
32+
runOrder.push('outer after');
33+
assert.deepStrictEqual(runOrder, [
34+
'outer before', 'outer after'
35+
]);
36+
throw new Error('should throw this error');
37+
});
38+
});

test/integration/pending.spec.js

Lines changed: 45 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
var assert = require('assert');
44
var helpers = require('./helpers');
55
var run = helpers.runMochaJSON;
6-
var runMocha = helpers.runMocha;
7-
var splitRegExp = helpers.splitRegExp;
86
var invokeNode = helpers.invokeNode;
97
var toJSONRunResult = helpers.toJSONRunResult;
108
var args = [];
@@ -111,43 +109,38 @@ describe('pending', function() {
111109
});
112110
});
113111
it('should run before and after hooks', function(done) {
114-
runMocha(
115-
'pending/skip-sync-before-hooks.fixture.js',
116-
args.concat(['--reporter', 'dot']),
117-
function(err, res) {
118-
if (err) {
119-
done(err);
120-
return;
121-
}
122-
123-
var lines = res.output
124-
.split(splitRegExp)
125-
.map(function(line) {
126-
return line.trim();
127-
})
128-
.filter(function(line) {
129-
return line.length;
130-
})
131-
.slice(0, -1);
132-
133-
var expected = [
134-
'outer before',
135-
'inner before',
136-
'inner after',
137-
'outer after'
138-
];
139-
140-
assert.strictEqual(res.pending, 2);
141-
assert.strictEqual(res.passing, 2);
142-
assert.strictEqual(res.failing, 0);
143-
assert.strictEqual(res.code, 0);
144-
expected.forEach(function(line, i) {
145-
assert.strictEqual(true, lines[i].includes(line));
146-
});
147-
148-
done();
112+
run('pending/skip-sync-before-hooks.fixture.js', function(err, res) {
113+
if (err) {
114+
return done(err);
149115
}
150-
);
116+
expect(res, 'to have failed with error', 'should throw this error')
117+
.and('to have failed test count', 1)
118+
.and('to have pending test count', 2)
119+
.and('to have passed test count', 2)
120+
.and(
121+
'to have passed test order',
122+
'should run test-1',
123+
'should run test-2'
124+
);
125+
done();
126+
});
127+
});
128+
it('should skip all sync/async inner before/after hooks', function(done) {
129+
run('pending/skip-sync-before-inner.fixture.js', function(err, res) {
130+
if (err) {
131+
return done(err);
132+
}
133+
expect(res, 'to have failed with error', 'should throw this error')
134+
.and('to have failed test count', 1)
135+
.and('to have pending test count', 2)
136+
.and('to have passed test count', 0)
137+
.and(
138+
'to have pending test order',
139+
'should never run this outer test',
140+
'should never run this inner test'
141+
);
142+
done();
143+
});
151144
});
152145
});
153146

@@ -245,43 +238,21 @@ describe('pending', function() {
245238
});
246239
});
247240
it('should run before and after hooks', function(done) {
248-
runMocha(
249-
'pending/skip-async-before-hooks.fixture.js',
250-
args.concat(['--reporter', 'dot']),
251-
function(err, res) {
252-
if (err) {
253-
done(err);
254-
return;
255-
}
256-
257-
var lines = res.output
258-
.split(splitRegExp)
259-
.map(function(line) {
260-
return line.trim();
261-
})
262-
.filter(function(line) {
263-
return line.length;
264-
})
265-
.slice(0, -1);
266-
267-
var expected = [
268-
'outer before',
269-
'inner before',
270-
'inner after',
271-
'outer after'
272-
];
273-
274-
assert.strictEqual(res.pending, 2);
275-
assert.strictEqual(res.passing, 2);
276-
assert.strictEqual(res.failing, 0);
277-
assert.strictEqual(res.code, 0);
278-
expected.forEach(function(line, i) {
279-
assert.strictEqual(true, lines[i].includes(line));
280-
});
281-
282-
done();
241+
run('pending/skip-async-before-hooks.fixture.js', function(err, res) {
242+
if (err) {
243+
return done(err);
283244
}
284-
);
245+
expect(res, 'to have failed with error', 'should throw this error')
246+
.and('to have failed test count', 1)
247+
.and('to have pending test count', 2)
248+
.and('to have passed test count', 2)
249+
.and(
250+
'to have passed test order',
251+
'should run test-1',
252+
'should run test-2'
253+
);
254+
done();
255+
});
285256
});
286257
});
287258

0 commit comments

Comments
 (0)