Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: promises #537

Merged
merged 12 commits into from Feb 28, 2016

Implement promise support for setup, teardown and test functions

  • Loading branch information
rluba committed Feb 27, 2016
commit 64d4928c06596f2fca4fdecff9703335a6034e68
@@ -134,7 +134,7 @@ internals.before = function (/* options, */ fn) {
const options = arguments.length === 2 ? arguments[0] : {};
fn = arguments.length === 2 ? arguments[1] : fn;

Hoek.assert(fn && fn.length === 1, 'Function for before in "' + this._current.title + '" should take exactly one argument');
Hoek.assert(fn, `before in "${this._current.title}" requires a function argument`);

const before = {
title: 'Before ' + this._titles.join(' '),
@@ -152,7 +152,7 @@ internals.after = function (/* options, */ fn) {
const options = arguments.length === 2 ? arguments[0] : {};
fn = arguments.length === 2 ? arguments[1] : fn;

Hoek.assert(fn && fn.length === 1, 'Function for after in "' + this._current.title + '" should take exactly one argument');
Hoek.assert(fn, `after in "${this._current.title}" requires a function argument`);

const after = {
title: 'After ' + this._titles.join(' '),
@@ -170,7 +170,7 @@ internals.beforeEach = function (/* options, */ fn) {
const options = arguments.length === 2 ? arguments[0] : {};
fn = arguments.length === 2 ? arguments[1] : fn;

Hoek.assert(fn && fn.length === 1, 'Function for beforeEach in "' + this._current.title + '" should take exactly one argument');
Hoek.assert(fn, `beforeEach in "${this._current.title}" requires a function argument`);

const beforeEach = {
title: 'Before each ' + this._titles.join(' '),
@@ -188,7 +188,7 @@ internals.afterEach = function (/* options, */ fn) {
const options = arguments.length === 2 ? arguments[0] : {};
fn = arguments.length === 2 ? arguments[1] : fn;

Hoek.assert(fn && fn.length === 1, 'Function for afterEach in "' + this._current.title + '" should take exactly one argument');
Hoek.assert(fn, `afterEach in "${this._current.title}" requires a function argument`);

const afterEach = {
title: 'After each ' + this._titles.join(' '),
@@ -206,10 +206,6 @@ internals.test = function (title /*, options, fn */) {
const options = arguments.length === 3 ? arguments[1] : {};
const fn = arguments.length === 3 ? arguments[2] : arguments[1];

if (fn) {
Hoek.assert(fn.length === 1, 'Function for test "' + title + '" should take exactly one argument');
}

const settings = Utils.mergeOptions(this._current.options, options, ['only']);

const test = {
@@ -564,10 +564,16 @@ internals.protect = function (item, state, callback) {
setImmediate(() => {

domain.enter();
item.fn.call(null, (err) => {
const itemResult = item.fn.call(null, (err) => {

finish(err, 'done');
});
if (itemResult && itemResult.then instanceof Function) {
itemResult.then(() => finish(null, 'done'), (err) => finish(err, 'done'));

This comment has been minimized.

Copy link
@Marsup

Marsup Feb 27, 2016

Member

2nd arg is only used in case of error.

This comment has been minimized.

Copy link
@rluba

rluba Feb 27, 2016

Author Contributor

Thx

}
if (item.fn.length !== 1 && !(itemResult && itemResult.then instanceof Function)) {
finish(new Error(`Function for "${item.title}" should either take a callback argument or return a promise`), 'function signature');
}
domain.exit();
});
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.