diff --git a/lib/concurrent.js b/lib/concurrent.js index 679a5196e..43e842ea7 100644 --- a/lib/concurrent.js +++ b/lib/concurrent.js @@ -6,7 +6,7 @@ var BAIL_ERROR = new Error(); module.exports = Concurrent; function Concurrent(tests, bail) { - if (!this instanceof Concurrent) { + if (!(this instanceof Concurrent)) { throw new TypeError('Class constructor Concurrent cannot be invoked without \'new\''); } diff --git a/lib/sequence.js b/lib/sequence.js index 01ff36afe..f88aabf39 100644 --- a/lib/sequence.js +++ b/lib/sequence.js @@ -4,7 +4,7 @@ var isPromise = require('is-promise'); module.exports = Sequence; function Sequence(tests, bail) { - if (!this instanceof Sequence) { + if (!(this instanceof Sequence)) { throw new TypeError('Class constructor Sequence cannot be invoked without \'new\''); } diff --git a/test/api.js b/test/api.js index faa32e07e..146bcbfab 100644 --- a/test/api.js +++ b/test/api.js @@ -6,6 +6,14 @@ var fs = require('fs'); var test = require('tap').test; var Api = require('../api'); +test('must be called with new', function (t) { + t.throws(function () { + var api = Api; + api([path.join(__dirname, 'fixture/es2015.js')]); + }, {message: 'Class constructor Api cannot be invoked without \'new\''}); + t.end(); +}); + test('ES2015 support', function (t) { t.plan(1); diff --git a/test/ava-error.js b/test/ava-error.js new file mode 100644 index 000000000..dda19eda2 --- /dev/null +++ b/test/ava-error.js @@ -0,0 +1,11 @@ +'use strict'; +var test = require('tap').test; +var AvaError = require('../lib/ava-error'); + +test('must be called with new', function (t) { + t.throws(function () { + var avaError = AvaError; + avaError('test message'); + }, {message: 'Class constructor AvaError cannot be invoked without \'new\''}); + t.end(); +}); diff --git a/test/caching-precompiler.js b/test/caching-precompiler.js index 2e1a0edcb..27b972911 100644 --- a/test/caching-precompiler.js +++ b/test/caching-precompiler.js @@ -5,7 +5,6 @@ var test = require('tap').test; var uniqueTempDir = require('unique-temp-dir'); var CachingPrecompiler = require('../lib/caching-precompiler'); -var createCachingPrecompiler = CachingPrecompiler; function fixture(name) { return path.join(__dirname, 'fixture', name); @@ -26,10 +25,11 @@ test('creation with new', function (t) { t.end(); }); -test('creation without new throws', function (t) { +test('must be called with new', function (t) { t.throws(function () { - createCachingPrecompiler(uniqueTempDir()); - }); + var cachingPrecompiler = CachingPrecompiler; + cachingPrecompiler(uniqueTempDir()); + }, {message: 'Class constructor CachingPrecompiler cannot be invoked without \'new\''}); t.end(); }); diff --git a/test/concurrent.js b/test/concurrent.js index 377201dbd..8e48bcd95 100644 --- a/test/concurrent.js +++ b/test/concurrent.js @@ -610,9 +610,9 @@ test('rejections are just passed through - bail', function (t) { test('must be called with new', function (t) { t.throws(function () { - var c = Concurrent; - c([pass('a')]); - }); + var concurrent = Concurrent; + concurrent([pass('a')]); + }, {message: 'Class constructor Concurrent cannot be invoked without \'new\''}); t.end(); }); diff --git a/test/logger.js b/test/logger.js new file mode 100644 index 000000000..d1132efe7 --- /dev/null +++ b/test/logger.js @@ -0,0 +1,11 @@ +'use strict'; +var test = require('tap').test; +var Logger = require('../lib/logger'); + +test('must be called with new', function (t) { + t.throws(function () { + var logger = Logger; + logger(); + }, {message: 'Class constructor Logger cannot be invoked without \'new\''}); + t.end(); +}); diff --git a/test/runner.js b/test/runner.js index e405bd4f7..a95c30d7e 100644 --- a/test/runner.js +++ b/test/runner.js @@ -4,6 +4,14 @@ var Runner = require('../lib/runner'); var noop = function () {}; +test('must be called with new', function (t) { + t.throws(function () { + var runner = Runner; + runner(); + }, {message: 'Class constructor Runner cannot be invoked without \'new\''}); + t.end(); +}); + test('runner emits a "test" event', function (t) { var runner = new Runner(); diff --git a/test/sequence.js b/test/sequence.js index 21dde90b0..41c3d8b7a 100644 --- a/test/sequence.js +++ b/test/sequence.js @@ -609,7 +609,14 @@ test('must be called with new', function (t) { t.throws(function () { var sequence = Sequence; sequence([pass('a')]); - }); + }, {message: 'Class constructor Sequence cannot be invoked without \'new\''}); + t.end(); +}); + +test('needs at least one sequence item', function (t) { + t.throws(function () { + new Sequence().run(); + }, {message: 'Sequence items can\'t be undefined'}); t.end(); }); diff --git a/test/test-collection.js b/test/test-collection.js index f42eff1c3..c7d37e581 100644 --- a/test/test-collection.js +++ b/test/test-collection.js @@ -45,11 +45,11 @@ function serialize(collection) { return ret; } -test('requires new', function (t) { - var withoutNew = TestCollection; +test('must be called with new', function (t) { + var testCollection = TestCollection; t.throws(function () { - withoutNew(); - }); + testCollection(); + }, {message: 'Class constructor TestCollection cannot be invoked without \'new\''}); t.end(); }); diff --git a/test/test.js b/test/test.js index 194433b59..8d8a73c03 100644 --- a/test/test.js +++ b/test/test.js @@ -17,6 +17,14 @@ ava.cb = function (title, fn, contextRef, report) { return t; }; +test('must be called with new', function (t) { + t.throws(function () { + var test = Test; + test(); + }, {message: 'Class constructor Test cannot be invoked without \'new\''}); + t.end(); +}); + test('run test', function (t) { var result = ava('foo', function (a) { a.fail();