Skip to content

Commit b9ebced

Browse files
author
Vadim Demedes
committed
Merge pull request #299 from sindresorhus/missing-skipped-tests
Display skipped tests
2 parents 3f2e67a + cf471cb commit b9ebced

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function exit() {
6666
}
6767

6868
globals.setImmediate(function () {
69-
var numberOfTests = runner.select({type: 'test'}).length;
69+
var numberOfTests = runner.select({type: 'test', skipped: false}).length;
7070

7171
if (numberOfTests === 0) {
7272
send('no-tests', {avaRequired: true});

lib/runner.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ Runner.prototype._addFn = function (opts, title, fn) {
8787
};
8888

8989
Runner.prototype._runTestWithHooks = function (test) {
90-
if (test.skip) {
90+
if (test.metadata.skipped) {
9191
return this._addTestResult(test);
9292
}
9393

9494
function hookToTest(hook) {
9595
return hook.test(test.title);
9696
}
9797

98-
var tests = this.select({type: 'beforeEach', skipped: false}).map(hookToTest);
98+
var tests = this.select({type: 'beforeEach'}).map(hookToTest);
9999
tests.push(test);
100-
tests.push.apply(tests, this.select({type: 'afterEach', skipped: false}).map(hookToTest));
100+
tests.push.apply(tests, this.select({type: 'afterEach'}).map(hookToTest));
101101

102102
var context = {};
103103

@@ -120,6 +120,10 @@ Runner.prototype._runTest = function (test) {
120120

121121
// add test result regardless of state
122122
// but on error, don't execute next tests
123+
if (test.metadata.skipped) {
124+
return this._addTestResult(test);
125+
}
126+
123127
return test.run().finally(function () {
124128
self._addTestResult(test);
125129
});
@@ -147,7 +151,7 @@ Runner.prototype._addTestResult = function (test) {
147151
title: test.title,
148152
error: test.assertError,
149153
type: test.metadata.type,
150-
skip: test.skip
154+
skip: test.metadata.skipped
151155
};
152156

153157
this.results.push(props);
@@ -165,25 +169,28 @@ Runner.prototype.run = function () {
165169

166170
var serial = this.select({
167171
exclusive: hasExclusive,
168-
skipped: false,
169172
serial: true,
170173
type: 'test'
171174
});
172175

173176
var concurrent = this.select({
174177
exclusive: hasExclusive,
175-
skipped: false,
176178
serial: false,
177179
type: 'test'
178180
});
179181

182+
var skipped = this.select({
183+
type: 'test',
184+
skipped: true
185+
});
186+
180187
var stats = this.stats = {
181188
failCount: 0,
182189
passCount: 0,
183-
testCount: serial.length + concurrent.length
190+
testCount: serial.length + concurrent.length - skipped.length
184191
};
185192

186-
return eachSeries(this.select({type: 'before', skipped: false}), this._runTest, this)
193+
return eachSeries(this.select({type: 'before'}), this._runTest, this)
187194
.catch(noop)
188195
.then(function () {
189196
if (stats.failCount > 0) {
@@ -197,7 +204,7 @@ Runner.prototype.run = function () {
197204
return self._runConcurrent(concurrent);
198205
})
199206
.then(function () {
200-
return eachSeries(self.select({type: 'after', skipped: false}), self._runTest, self);
207+
return eachSeries(self.select({type: 'after'}), self._runTest, self);
201208
})
202209
.catch(noop)
203210
.then(function () {

test/runner.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,46 @@ test('anything can be skipped', function (t) {
218218
});
219219
});
220220

221+
test('include skipped tests in results', function (t) {
222+
var runner = new Runner();
223+
224+
runner.before('before', noop);
225+
runner.before.skip('before.skip', noop);
226+
227+
runner.beforeEach('beforeEach', noop);
228+
runner.beforeEach.skip('beforeEach.skip', noop);
229+
230+
runner.test.serial('test', noop);
231+
runner.test.serial.skip('test.skip', noop);
232+
233+
runner.after('after', noop);
234+
runner.after.skip('after.skip', noop);
235+
236+
runner.afterEach('afterEach', noop);
237+
runner.afterEach.skip('afterEach.skip', noop);
238+
239+
runner.run().then(function () {
240+
var titles = runner.results.map(function (result) {
241+
return result.title;
242+
});
243+
244+
t.same(titles, [
245+
'before',
246+
'before.skip',
247+
'beforeEach',
248+
'beforeEach.skip',
249+
'test',
250+
'afterEach',
251+
'afterEach.skip',
252+
'test.skip',
253+
'after',
254+
'after.skip'
255+
]);
256+
257+
t.end();
258+
});
259+
});
260+
221261
test('test types and titles', function (t) {
222262
t.plan(10);
223263

0 commit comments

Comments
 (0)