Skip to content

Commit 7bb0885

Browse files
committed
Consistently require new for classes
To be forward compatible with ES2015 classes.
1 parent ffef6d6 commit 7bb0885

File tree

10 files changed

+20
-27
lines changed

10 files changed

+20
-27
lines changed

api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var CachingPrecompiler = require('./lib/caching-precompiler');
2020

2121
function Api(files, options) {
2222
if (!(this instanceof Api)) {
23-
return new Api(files, options);
23+
throw new TypeError('Class constructor Api cannot be invoked without \'new\'');
2424
}
2525

2626
EventEmitter.call(this);

lib/ava-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function AvaError(message) {
44
if (!(this instanceof AvaError)) {
5-
return new AvaError(message);
5+
throw new TypeError('Class constructor AvaError cannot be invoked without \'new\'');
66
}
77

88
this.message = message;

lib/hook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = Hook;
44

55
function Hook(title, fn) {
66
if (!(this instanceof Hook)) {
7-
return new Hook(title, fn);
7+
throw new TypeError('Class constructor Hook cannot be invoked without \'new\'');
88
}
99

1010
if (typeof title === 'function') {

lib/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function Logger() {
44
if (!(this instanceof Logger)) {
5-
return new Logger();
5+
throw new TypeError('Class constructor Logger cannot be invoked without \'new\'');
66
}
77

88
Object.keys(Logger.prototype).forEach(function (key) {

lib/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var chainableMethods = {
2929

3030
function Runner() {
3131
if (!(this instanceof Runner)) {
32-
return new Runner();
32+
throw new TypeError('Class constructor Runner cannot be invoked without \'new\'');
3333
}
3434

3535
EventEmitter.call(this);

lib/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var globals = require('./globals');
1313

1414
function Test(title, fn, contextRef, report) {
1515
if (!(this instanceof Test)) {
16-
return new Test(title, fn, contextRef, report);
16+
throw new TypeError('Class constructor Test cannot be invoked without \'new\'');
1717
}
1818

1919
if (typeof title === 'function') {

test/observable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict';
22
var test = require('tap').test;
3-
var _ava = require('../lib/test');
3+
var Test = require('../lib/test');
44
var Observable = require('./fixture/observable');
55

66
function ava(fn) {
7-
var a = _ava(fn);
7+
var a = new Test(fn);
88
a.metadata = {callback: false};
99
return a;
1010
}
1111

1212
ava.cb = function (fn) {
13-
var a = _ava(fn);
13+
var a = new Test(fn);
1414
a.metadata = {callback: true};
1515
return a;
1616
};

test/promise.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict';
22
var Promise = require('bluebird');
33
var test = require('tap').test;
4-
var _ava = require('../lib/test');
4+
var Test = require('../lib/test');
55

66
function ava(fn) {
7-
var a = _ava(fn);
7+
var a = new Test(fn);
88
a.metadata = {callback: false};
99
return a;
1010
}
1111

1212
ava.cb = function (fn) {
13-
var a = _ava(fn);
13+
var a = new Test(fn);
1414
a.metadata = {callback: true};
1515
return a;
1616
};

test/runner.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
'use strict';
22
var test = require('tap').test;
3-
var runner = require('../lib/runner');
4-
// var Test = require('../lib/test');
5-
var Runner = runner;
6-
// var mockTitle = 'mock title';
7-
var noop = function () {};
3+
var Runner = require('../lib/runner');
84

9-
test('returns new instance of runner without "new"', function (t) {
10-
t.ok(runner({}) instanceof runner);
11-
t.end();
12-
});
5+
var noop = function () {};
136

147
test('runner emits a "test" event', function (t) {
158
var runner = new Runner();

test/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ var test = require('tap').test;
33
var Promise = global.Promise = require('bluebird');
44
var delay = require('delay');
55
var isPromise = require('is-promise');
6-
var _ava = require('../lib/test');
6+
var Test = require('../lib/test');
77

8-
function ava() {
9-
var t = _ava.apply(null, arguments);
8+
function ava(title, fn, contextRef, report) {
9+
var t = new Test(title, fn, contextRef, report);
1010
t.metadata = {callback: false};
1111
return t;
1212
}
1313

14-
ava.cb = function () {
15-
var t = _ava.apply(null, arguments);
14+
ava.cb = function (title, fn, contextRef, report) {
15+
var t = new Test(title, fn, contextRef, report);
1616
t.metadata = {callback: true};
1717
return t;
1818
};
@@ -513,7 +513,7 @@ test('assertions return promises', function (t) {
513513
});
514514

515515
test('contextRef', function (t) {
516-
new _ava('foo',
516+
new Test('foo',
517517
function (a) {
518518
t.same(a.context, {foo: 'bar'});
519519
t.end();

0 commit comments

Comments
 (0)