diff --git a/test/after-and-ready.test.js b/test/after-and-ready.test.js index db1fd44..ff3d730 100644 --- a/test/after-and-ready.test.js +++ b/test/after-and-ready.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('boot a plugin and then execute a call after that', (t) => { diff --git a/test/after-pass-through.test.js b/test/after-pass-through.test.js index 1fb61fa..9f1f54a 100644 --- a/test/after-pass-through.test.js +++ b/test/after-pass-through.test.js @@ -1,30 +1,32 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const boot = require('..') -const app = {} -boot(app) +test('proper support for after with a passed async function in wrapped mode', (t) => { + const app = {} + boot(app) -t.plan(5) + t.plan(5) -const e = new Error('kaboom') + const e = new Error('kaboom') -app.use(function (f, opts) { - return Promise.reject(e) -}).after(function (err, cb) { - t.equal(err, e) - cb(err) -}).after(function () { - t.pass('this is just called') -}).after(function (err, cb) { - t.equal(err, e) - cb(err) -}) + app.use(function (f, opts) { + return Promise.reject(e) + }).after(function (err, cb) { + t.equal(err, e) + cb(err) + }).after(function () { + t.pass('this is just called') + }).after(function (err, cb) { + t.equal(err, e) + cb(err) + }) -app.ready().then(() => { - t.fail('this should not be called') -}).catch(err => { - t.ok(err) - t.equal(err.message, 'kaboom') + app.ready().then(() => { + t.fail('this should not be called') + }).catch(err => { + t.ok(err) + t.equal(err.message, 'kaboom') + }) }) diff --git a/test/after-throw.test.js b/test/after-throw.test.js index 42a901c..c06e725 100644 --- a/test/after-throw.test.js +++ b/test/after-throw.test.js @@ -1,22 +1,24 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const boot = require('..') -const app = boot() -t.plan(2) +test('catched error by Promise.reject', (t) => { + const app = boot() + t.plan(2) -t.threw = function (err) { - t.equal(err.message, 'kaboom2') -} + t.threw = function (err) { + t.equal(err.message, 'kaboom2') + } -app.use(function (f, opts) { - return Promise.reject(new Error('kaboom')) -}).after(function (err) { - t.equal(err.message, 'kaboom') - throw new Error('kaboom2') -}) + app.use(function (f, opts) { + return Promise.reject(new Error('kaboom')) + }).after(function (err) { + t.equal(err.message, 'kaboom') + throw new Error('kaboom2') + }) -app.ready(function () { - t.fail('the ready callback should never be called') + app.ready(function () { + t.fail('the ready callback should never be called') + }) }) diff --git a/test/async-await.test.js b/test/async-await.test.js index a7b236d..9ab874b 100644 --- a/test/async-await.test.js +++ b/test/async-await.test.js @@ -2,7 +2,7 @@ /* eslint no-prototype-builtins: off */ -const test = require('tap').test +const { test } = require('tap') const sleep = require('then-sleep') const boot = require('..') diff --git a/test/basic.test.js b/test/basic.test.js index 5554bb7..f7892f1 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('tap') const boot = require('..') test('boot an empty app', (t) => { diff --git a/test/callbacks.test.js b/test/callbacks.test.js index ab5dbb5..2e7ac1c 100644 --- a/test/callbacks.test.js +++ b/test/callbacks.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('reentrant', (t) => { diff --git a/test/catch-override-exception.test.js b/test/catch-override-exception.test.js index 6ab5fcf..fdcd58a 100644 --- a/test/catch-override-exception.test.js +++ b/test/catch-override-exception.test.js @@ -1,24 +1,26 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const boot = require('..') -t.plan(2) +test('catch exceptions in parent.override', (t) => { + t.plan(2) -const server = {} + const server = {} -const app = boot(server, { - autostart: false -}) -app.override = function () { - throw Error('catch it') -} + const app = boot(server, { + autostart: false + }) + app.override = function () { + throw Error('catch it') + } -app - .use(function () {}) - .start() + app + .use(function () {}) + .start() -app.ready(function (err) { - t.type(err, Error) - t.match(err, /catch it/) + app.ready(function (err) { + t.type(err, Error) + t.match(err, /catch it/) + }) }) diff --git a/test/chainable.test.js b/test/chainable.test.js index ebe45a6..67ecc6d 100644 --- a/test/chainable.test.js +++ b/test/chainable.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('chainable standalone', (t) => { diff --git a/test/close.test.js b/test/close.test.js index 177c948..021ea9f 100644 --- a/test/close.test.js +++ b/test/close.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('boot an app with a plugin', (t) => { diff --git a/test/errors.test.js b/test/errors.test.js index 1981549..40cc9cc 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,3 +1,5 @@ +'use strict' + const { test } = require('tap') const { createError } = require('../lib/errors') diff --git a/test/esm.mjs b/test/esm.mjs index a44dbea..df53d64 100644 --- a/test/esm.mjs +++ b/test/esm.mjs @@ -1,8 +1,6 @@ -import tap from 'tap' +import { test } from 'tap' import boot from '../boot.js' -const { test } = tap - test('support import', async (t) => { const app = boot() diff --git a/test/esm.test.js b/test/esm.test.js index f3c88fe..7ae4322 100644 --- a/test/esm.test.js +++ b/test/esm.test.js @@ -1,17 +1,15 @@ 'use strict' -const tap = require('tap') +const { test } = require('tap') const semver = require('semver') -if (semver.lt(process.versions.node, '13.3.0')) { - tap.pass('Skip because Node version <= 13.3.0') - tap.end() -} else { - // Import is not allowed syntax in Node 8 - // eslint-disable-next-line - new Function('module', 'return import(module)')('./esm.mjs').catch((err) => { +test('support import', { skip: semver.lt(process.versions.node, '13.3.0') }, (t) => { + import('./esm.mjs').then(() => { + t.pass('esm is supported') + t.end() + }).catch((err) => { process.nextTick(() => { throw err }) }) -} +}) diff --git a/test/events-listeners.test.js b/test/events-listeners.test.js index 0647372..810d43b 100644 --- a/test/events-listeners.test.js +++ b/test/events-listeners.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') const noop = () => {} diff --git a/test/express.test.js b/test/express.test.js index 706720a..eb223cd 100644 --- a/test/express.test.js +++ b/test/express.test.js @@ -1,50 +1,52 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const express = require('express') const http = require('http') const boot = require('..') -const app = express() +test('express support', (t) => { + const app = express() -boot.express(app) -// It does: -// -// boot(app, { -// expose: { -// use: 'load' -// } -// }) + boot.express(app) + // It does: + // + // boot(app, { + // expose: { + // use: 'load' + // } + // }) -t.plan(2) + t.plan(2) -let loaded = false -let server + let loaded = false + let server -app.load(function (app, opts, done) { - loaded = true - app.use(function (req, res) { - res.end('hello world') - }) + app.load(function (app, opts, done) { + loaded = true + app.use(function (req, res) { + res.end('hello world') + }) - done() -}) + done() + }) -app.after((cb) => { - t.ok(loaded, 'plugin loaded') - server = app.listen(0, cb) - t.teardown(server.close.bind(server)) -}) + app.after((cb) => { + t.ok(loaded, 'plugin loaded') + server = app.listen(0, cb) + t.teardown(server.close.bind(server)) + }) -app.ready(() => { - http.get(`http://localhost:${server.address().port}`).on('response', function (res) { - let data = '' - res.on('data', function (chunk) { - data += chunk - }) + app.ready(() => { + http.get(`http://localhost:${server.address().port}`).on('response', function (res) { + let data = '' + res.on('data', function (chunk) { + data += chunk + }) - res.on('end', function () { - t.equal(data, 'hello world') + res.on('end', function () { + t.equal(data, 'hello world') + }) }) }) }) diff --git a/test/override.test.js b/test/override.test.js index 896b497..e8aa545 100644 --- a/test/override.test.js +++ b/test/override.test.js @@ -2,7 +2,7 @@ /* eslint no-prototype-builtins: off */ -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('custom inheritance', (t) => { diff --git a/test/plugin-name.test.js b/test/plugin-name.test.js index e268d06..4c81643 100644 --- a/test/plugin-name.test.js +++ b/test/plugin-name.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('tap') const boot = require('..') test('plugins get a name from the plugin metadata if it is set', async (t) => { diff --git a/test/plugin-timeout.test.js b/test/plugin-timeout.test.js index 614dc2e..7cadc55 100644 --- a/test/plugin-timeout.test.js +++ b/test/plugin-timeout.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('tap') const boot = require('..') const message = (name) => `Plugin did not start in time: '${name}'. You may have forgotten to call 'done' function or to resolve a Promise` diff --git a/test/pretty-print.test.js b/test/pretty-print.test.js index 4e6d505..9089f6a 100644 --- a/test/pretty-print.test.js +++ b/test/pretty-print.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('pretty print', t => { diff --git a/test/reentrant.test.js b/test/reentrant.test.js index bdec7cf..184be9c 100644 --- a/test/reentrant.test.js +++ b/test/reentrant.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('one level', (t) => { diff --git a/test/to-json.test.js b/test/to-json.test.js index 148e9b7..d1b66ed 100644 --- a/test/to-json.test.js +++ b/test/to-json.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('to json', (t) => { diff --git a/test/twice-done.test.js b/test/twice-done.test.js index 5451164..ecff9c5 100644 --- a/test/twice-done.test.js +++ b/test/twice-done.test.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const { test } = require('tap') const boot = require('..') test('calling done twice does not throw error', (t) => {