Skip to content

Commit

Permalink
helpful error when necessary suite callback omitted; closes #1744
Browse files Browse the repository at this point in the history
- works for QUnit as well
- renamed some files
- fixed unclear "only" tests
  • Loading branch information
boneskull committed Sep 19, 2016
1 parent e22c407 commit 3a2dae8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 55 deletions.
2 changes: 2 additions & 0 deletions lib/interfaces/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ module.exports = function(suites, context, mocha) {
if (typeof opts.fn === 'function') {
opts.fn.call(suite);
suites.shift();
} else if (typeof opts.fn === 'undefined' && !suite.pending) {
throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
}

return suite;
Expand Down
6 changes: 4 additions & 2 deletions lib/interfaces/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = function(suite) {
}
return common.suite.create({
title: title,
file: file
file: file,
fn: false
});
};

Expand All @@ -64,7 +65,8 @@ module.exports = function(suite) {
}
return common.suite.only({
title: title,
file: file
file: file,
fn: false
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xdescribe('a pending suite with a callback', function () {});
56 changes: 32 additions & 24 deletions test/integration/only.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@ var run = require('./helpers').runMochaJSON;
var assert = require('assert');

describe('.only()', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 11);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
describe('bdd', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 11);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
});
});
});

it('should run only tests that marked as `only`', function(done) {
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 8);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
describe('tdd', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 8);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
});
});
});

it('should run only tests that marked as `only`', function(done) {
run('options/only/qunit.fixture.js', ['--ui', 'qunit'], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 5);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
describe('qunit', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/qunit.fixture.js', ['--ui', 'qunit'], function(err, res) {
console.log(err);

assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 5);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
done();
});
});
});
});
29 changes: 0 additions & 29 deletions test/integration/suite.js

This file was deleted.

42 changes: 42 additions & 0 deletions test/integration/suite.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var assert = require('assert');
var run = require('./helpers').runMocha;
var args = [];

describe('suite w/no callback', function() {
this.timeout(1000);
it('should throw a helpful error message when a callback for suite is not supplied', function(done) {
run('suite/suite-no-callback.fixture.js', args, function(err, res) {
assert(!err);
var result = res.output.match(/no callback was supplied/) || [];
assert.equal(result.length, 1);
done();
});
});
});

describe('skipped suite w/no callback', function() {
this.timeout(1000);
it('should not throw an error when a callback for skipped suite is not supplied', function(done) {
run('suite/suite-skipped-no-callback.fixture.js', args, function(err, res) {
assert(!err);
pattern = new RegExp("Error", 'g');
var result = res.output.match(pattern) || [];
assert.equal(result.length, 0);
done();
});
});
});


describe('skipped suite w/ callback', function() {
this.timeout(1000);
it('should not throw an error when a callback for skipped suite is supplied', function(done) {
run('suite/suite-skipped-callback.fixture.js', args, function(err, res) {
assert(!err);
pattern = new RegExp("Error", 'g');
var result = res.output.match(pattern) || [];
assert.equal(result.length, 0);
done();
});
});
});

0 comments on commit 3a2dae8

Please sign in to comment.