Comparing version 7.2.1 to 7.2.2
24
boot.js
@@ -298,3 +298,3 @@ 'use strict' | ||
Boot.prototype.close = function (func) { | ||
var promise | ||
let promise | ||
@@ -401,4 +401,4 @@ if (func) { | ||
context = this._server | ||
var err = this._error | ||
var res | ||
const err = this._error | ||
let res | ||
@@ -468,5 +468,5 @@ // with this the error will appear just in the next after/ready callback | ||
context = this._server | ||
var isOnCloseHandler = func[this._isOnCloseHandlerKey] | ||
const isOnCloseHandler = func[this._isOnCloseHandlerKey] | ||
if (func.length === 0 || func.length === 1) { | ||
var promise | ||
let promise | ||
if (isOnCloseHandler) { | ||
@@ -503,6 +503,12 @@ promise = func(context) | ||
function _encapsulateTwoParam (context, cb) { | ||
var res | ||
let res | ||
if (func.length === 0) { | ||
func() | ||
process.nextTick(cb) | ||
res = func() | ||
if (res && res.then) { | ||
res.then(function () { | ||
process.nextTick(cb) | ||
}, cb) | ||
} else { | ||
process.nextTick(cb) | ||
} | ||
} else if (func.length === 1) { | ||
@@ -527,3 +533,3 @@ res = func(this) | ||
function _encapsulateThreeParam (err, cb) { | ||
var res | ||
let res | ||
if (!func) { | ||
@@ -530,0 +536,0 @@ process.nextTick(cb) |
@@ -28,3 +28,3 @@ import { EventEmitter } from "events"; | ||
interface Plugin<O, I> { | ||
(server: context<I>, options: O, done: (err?: Error) => void): void; | ||
(server: context<I>, options: O, done: (err?: Error) => void): unknown; | ||
} | ||
@@ -31,0 +31,0 @@ |
{ | ||
"name": "avvio", | ||
"version": "7.2.1", | ||
"version": "7.2.2", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
"main": "boot.js", | ||
"scripts": { | ||
"typescript": "tsc --project ./test/types/tsconfig.json", | ||
"test": "standard && tap -J test/*test.js && npm run typescript" | ||
"test": "standard && tap -J test/*test.js && npm run typescript", | ||
"typescript": "tsc --project ./test/types/tsconfig.json" | ||
}, | ||
@@ -13,3 +13,3 @@ "precommit": "test", | ||
"type": "git", | ||
"url": "git+https://github.com/mcollina/avvio.git" | ||
"url": "git+https://github.com/fastify/avvio.git" | ||
}, | ||
@@ -31,7 +31,7 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/mcollina/avvio/issues" | ||
"url": "https://github.com/fastify/avvio/issues" | ||
}, | ||
"homepage": "https://github.com/mcollina/avvio#readme", | ||
"homepage": "https://github.com/fastify/avvio#readme", | ||
"devDependencies": { | ||
"@types/node": "^14.0.1", | ||
"@types/node": "^15.0.0", | ||
"express": "^4.17.1", | ||
@@ -41,3 +41,3 @@ "pre-commit": "^1.2.2", | ||
"standard": "^16.0.1", | ||
"tap": "^14.0.0", | ||
"tap": "^15.0.0", | ||
"then-sleep": "^1.0.1", | ||
@@ -44,0 +44,0 @@ "typescript": "^4.0.2" |
@@ -16,2 +16,3 @@ 'use strict' | ||
// eslint-disable-next-line no-var | ||
for (var i = 0; i < keys.length; i++) { | ||
@@ -68,4 +69,4 @@ if (cache[keys[i]].exports === func) { | ||
const func = this.func | ||
var completed = false | ||
var name = this.name | ||
let completed = false | ||
const name = this.name | ||
@@ -94,3 +95,3 @@ if (this.parent._error && !this.isAfter) { | ||
var timer | ||
let timer | ||
@@ -134,3 +135,3 @@ const done = (err) => { | ||
this.emit('start', this.server ? this.server.name : null, this.name, Date.now()) | ||
var promise = func(this.server, this.opts, done) | ||
const promise = func(this.server, this.opts, done) | ||
@@ -137,0 +138,0 @@ if (promise && typeof promise.then === 'function') { |
# avvio | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI](https://github.com/fastify/avvio/workflows/CI/badge.svg) | ||
![CI](https://github.com/fastify/avvio/workflows/CI/badge.svg) | ||
[![NPM version](https://img.shields.io/npm/v/avvio.svg?style=flat)](https://www.npmjs.com/package/avvio) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/avvio/badge.svg)](https://snyk.io/test/github/fastify/avvio) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
@@ -94,3 +97,3 @@ Asynchronous bootstrapping is hard, different things can go wrong, *error handling* and *load order* just to name a few. The aim of this module is to make it simple. | ||
Starts the avvio sequence. | ||
As the name suggest, `instance` is the object representing your application. | ||
As the name suggests, `instance` is the object representing your application. | ||
Avvio will add the functions `use`, `after` and `ready` to the instance. | ||
@@ -120,3 +123,3 @@ | ||
a call to [`.start()`](#start) or [`.ready()`](#ready). | ||
* `timeout`: the number of millis to wait a plugin to load after which | ||
* `timeout`: the number of millis to wait for a plugin to load after which | ||
it will error with code `ERR_AVVIO_PLUGIN_TIMEOUT`. Default | ||
@@ -294,3 +297,3 @@ `0` (disabled). | ||
The callback changes basing on the parameters your are giving: | ||
The callback changes based on the parameters you give: | ||
1. If no parameter is given to the callback and there is an error, that error will be passed to the next error handler. | ||
@@ -301,4 +304,3 @@ 2. If one parameter is given to the callback, that parameter will be the `error` object. | ||
In the "no parameter" and "one parameter" variants, the callback can also | ||
return a `Promise`. | ||
In the "no parameter" and "one parameter" variants, the callback can return a `Promise`. | ||
@@ -351,3 +353,3 @@ ```js | ||
Calling after with no function argument loads any plugins previously registered via `use` and returns a promise which resolves when all plugins registered so far have loaded. | ||
Calling after with no function argument loads any plugins previously registered via `use` and returns a promise, which resolves when all plugins registered so far have loaded. | ||
@@ -386,3 +388,3 @@ ```js | ||
The callback changes basing on the parameters your are giving: | ||
The callback changes based on the parameters you give: | ||
1. If no parameter is given to the callback and there is an error, that error will be passed to the next error handler. | ||
@@ -475,3 +477,3 @@ 2. If one parameter is given to the callback, that parameter will be the `error` object. | ||
Allows to override the instance of the server for each loading plugin. | ||
Allows overriding the instance of the server for each loading plugin. | ||
It allows the creation of an inheritance chain for the server instances. | ||
@@ -518,3 +520,3 @@ The first parameter is the server instance and the second is the plugin function while the third is the options object that you give to use. | ||
The callback changes basing on the parameters your are giving: | ||
The callback changes basing on the parameters you give: | ||
1. If one parameter is given to the callback, that parameter will be the `context`. | ||
@@ -554,3 +556,3 @@ 2. If zero or one parameter is given, the callback may return a promise | ||
If the callback returns a promise, the next onClose callback and the close callback won't run until the promise is either resolved or rejected. | ||
If the callback returns a promise, the next onClose callback and the close callback will not run until the promise is either resolved or rejected. | ||
@@ -567,3 +569,3 @@ `done` must be called only once. | ||
The callback changes based on the parameters your are giving: | ||
The callback changes based on the parameters you give: | ||
1. If one parameter is given to the callback, that parameter will be the `error` object. | ||
@@ -615,3 +617,3 @@ 2. If two parameters are given to the callback, the first will be the `error` object, the second will be the `done` callback. | ||
Return a JSON tree rappresenting the state of the plugins and the loading time. | ||
Return a JSON tree representing the state of the plugins and the loading time. | ||
Call it on `preReady` to get the complete tree. | ||
@@ -626,3 +628,3 @@ | ||
The ouput is like this: | ||
The output is like this: | ||
```json | ||
@@ -692,3 +694,3 @@ { | ||
This project was kindly sponsored by [nearForm](http://nearform.com). | ||
This project was kindly sponsored by [nearForm](https://nearform.com). | ||
@@ -695,0 +697,0 @@ ## License |
@@ -210,10 +210,10 @@ 'use strict' | ||
s.use(function (s, opts, done) { | ||
s.ready().then(itself => t.deepEqual(itself, s, 'deep deep')) | ||
s.ready().then(itself => t.same(itself, s, 'deep deep')) | ||
done() | ||
}) | ||
s.ready().then(itself => t.deepEqual(itself, s, 'deep')) | ||
s.ready().then(itself => t.same(itself, s, 'deep')) | ||
done() | ||
}) | ||
app.ready().then(itself => t.deepEqual(itself, server, 'outer')) | ||
app.ready().then(itself => t.same(itself, server, 'outer')) | ||
}) | ||
@@ -233,3 +233,3 @@ | ||
s.ready((_, itself, done) => { | ||
t.deepEqual(itself, s, 'deep deep') | ||
t.same(itself, s, 'deep deep') | ||
done() | ||
@@ -240,3 +240,3 @@ }) | ||
s.ready((_, itself, done) => { | ||
t.deepEqual(itself, s, 'deep') | ||
t.same(itself, s, 'deep') | ||
done() | ||
@@ -248,3 +248,3 @@ }) | ||
app.ready((_, itself, done) => { | ||
t.deepEqual(itself, server, 'outer') | ||
t.same(itself, server, 'outer') | ||
done() | ||
@@ -266,3 +266,3 @@ }) | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
}) | ||
@@ -287,3 +287,3 @@ | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
cb() | ||
@@ -309,3 +309,3 @@ }) | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
t.equal(context, server) | ||
@@ -332,3 +332,3 @@ cb() | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
}) | ||
@@ -349,3 +349,3 @@ }) | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
cb() | ||
@@ -367,3 +367,3 @@ }) | ||
t.ok(err instanceof Error) | ||
t.is(err.message, 'err') | ||
t.equal(err.message, 'err') | ||
t.equal(context, server) | ||
@@ -412,3 +412,3 @@ cb() | ||
t.equal(s, server, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
done() | ||
@@ -425,3 +425,3 @@ }).after((err, done) => { | ||
server.ready(err => { | ||
t.is(err.message, 'some error') | ||
t.equal(err.message, 'some error') | ||
}) | ||
@@ -716,7 +716,7 @@ | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
app.ready(() => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
@@ -742,15 +742,15 @@ }) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 3) | ||
t.equal(order.shift(), 3) | ||
}) | ||
app.ready(() => { | ||
t.is(order.shift(), 4) | ||
t.equal(order.shift(), 4) | ||
}) | ||
@@ -774,3 +774,3 @@ }) | ||
server.on('preReady', () => { | ||
t.is(order.shift(), 3) | ||
t.equal(order.shift(), 3) | ||
}) | ||
@@ -782,11 +782,11 @@ | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
app.ready(() => { | ||
t.is(order.shift(), 4) | ||
t.equal(order.shift(), 4) | ||
}) | ||
@@ -811,7 +811,7 @@ }) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
app.on('preReady', () => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
@@ -821,3 +821,3 @@ | ||
t.ok(err) | ||
t.is(order.shift(), 3) | ||
t.equal(order.shift(), 3) | ||
}) | ||
@@ -824,0 +824,0 @@ }) |
@@ -16,3 +16,3 @@ 'use strict' | ||
}).after(function (err, cb) { | ||
t.is(err, e) | ||
t.equal(err, e) | ||
cb(err) | ||
@@ -22,3 +22,3 @@ }).after(function () { | ||
}).after(function (err, cb) { | ||
t.is(err, e) | ||
t.equal(err, e) | ||
cb(err) | ||
@@ -31,3 +31,3 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, 'kaboom') | ||
t.equal(err.message, 'kaboom') | ||
}) |
@@ -137,3 +137,3 @@ 'use strict' | ||
} catch (err) { | ||
t.is(err.message, 'kaboom') | ||
t.equal(err.message, 'kaboom') | ||
} | ||
@@ -140,0 +140,0 @@ }) |
@@ -24,3 +24,3 @@ 'use strict' | ||
t.pass('reachable') | ||
t.is(secondLoaded, true) | ||
t.equal(secondLoaded, true) | ||
@@ -46,3 +46,3 @@ await app.ready() | ||
t.pass('reachable') | ||
t.is(secondLoaded, true) | ||
t.equal(secondLoaded, true) | ||
@@ -106,3 +106,3 @@ await app.ready() | ||
const instance = await app.after() | ||
t.is(instance, undefined) | ||
t.equal(instance, undefined) | ||
}) | ||
@@ -127,6 +127,6 @@ t.pass('reachable') | ||
}).then((f2) => { | ||
t.is(f2, f) | ||
t.equal(f2, f) | ||
return 'test' | ||
}).then((val) => { | ||
t.is(val, 'test') | ||
t.equal(val, 'test') | ||
}) | ||
@@ -303,4 +303,4 @@ }) | ||
await app.after() | ||
t.is(firstLoaded, true) | ||
t.is(secondLoaded, true) | ||
t.equal(firstLoaded, true) | ||
t.equal(secondLoaded, true) | ||
@@ -311,3 +311,3 @@ await app.use(async () => { | ||
t.is(thirdLoaded, true) | ||
t.equal(thirdLoaded, true) | ||
@@ -330,5 +330,5 @@ await app.ready() | ||
app.use(async function first (app) { | ||
t.is(app.count, 1) | ||
t.equal(app.count, 1) | ||
app.use(async (app) => { | ||
t.is(app.count, 2) | ||
t.equal(app.count, 2) | ||
await app.after() | ||
@@ -341,3 +341,3 @@ }) | ||
await app.use(async (app) => { | ||
t.is(app.count, 3) | ||
t.equal(app.count, 3) | ||
}) | ||
@@ -359,4 +359,4 @@ | ||
} catch (e) { | ||
t.is(e.message, 'kaboom') | ||
t.equal(e.message, 'kaboom') | ||
} | ||
}) |
@@ -10,3 +10,3 @@ 'use strict' | ||
t.is(await app, app) | ||
t.equal(await app, app) | ||
}) | ||
@@ -18,5 +18,5 @@ | ||
t.is(await app, app) | ||
t.is(await app, app) | ||
t.is(await app, app) | ||
t.equal(await app, app) | ||
t.equal(await app, app) | ||
t.equal(await app, app) | ||
}) | ||
@@ -29,6 +29,6 @@ | ||
app.use(async (f) => { | ||
t.is(await f, f) | ||
t.equal(await f, f) | ||
}) | ||
t.is(await app, app) | ||
t.equal(await app, app) | ||
}) |
@@ -80,3 +80,3 @@ 'use strict' | ||
}).then((val) => { | ||
t.is(val, 'test') | ||
t.equal(val, 'test') | ||
}) | ||
@@ -83,0 +83,0 @@ }) |
@@ -29,7 +29,7 @@ 'use strict' | ||
const app = boot() | ||
var after = false | ||
let after = false | ||
app.use(function (server, opts, done) { | ||
t.equal(server, app, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
t.ok(after, 'delayed execution') | ||
@@ -50,7 +50,7 @@ done() | ||
const app = boot() | ||
var after = false | ||
let after = false | ||
app.use(function (server, opts) { | ||
t.equal(server, app, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
t.ok(after, 'delayed execution') | ||
@@ -88,3 +88,3 @@ return Promise.resolve() | ||
t.equal(s, server, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
done() | ||
@@ -112,3 +112,3 @@ }) | ||
t.equal(s, server, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
done() | ||
@@ -145,3 +145,3 @@ }).after(() => { | ||
t.equal(s, server, 'the first argument is the server') | ||
t.deepEqual(opts, myOpts, 'passed options') | ||
t.same(opts, myOpts, 'passed options') | ||
done() | ||
@@ -164,3 +164,3 @@ }, myOpts) | ||
const myOptsAsFunc = parent => { | ||
t.strictEqual(parent, server) | ||
t.equal(parent, server) | ||
return parent.myOpts | ||
@@ -176,3 +176,3 @@ } | ||
t.equal(s, server, 'the first argument is the server') | ||
t.deepEqual(opts, myOpts, 'passed options via function accessing parent injected variable') | ||
t.same(opts, myOpts, 'passed options via function accessing parent injected variable') | ||
done() | ||
@@ -221,3 +221,3 @@ }, myOptsAsFunc) | ||
var second = false | ||
let second = false | ||
@@ -286,3 +286,3 @@ app.use(function (s, opts, done) { | ||
var startCalled = false | ||
let startCalled = false | ||
const app = boot(null, { | ||
@@ -330,3 +330,3 @@ autostart: false | ||
app.on('start', function () { | ||
t.is(ready, true) | ||
t.equal(ready, true) | ||
}) | ||
@@ -390,3 +390,3 @@ }) | ||
const app = boot() | ||
var after = false | ||
let after = false | ||
@@ -398,3 +398,3 @@ // Faux modules are modules built with TypeScript | ||
t.equal(server, app, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
t.same(opts, {}, 'no options') | ||
t.ok(after, 'delayed execution') | ||
@@ -401,0 +401,0 @@ done() |
@@ -57,3 +57,3 @@ 'use strict' | ||
} catch (err) { | ||
t.is(err.message, 'root plugin has already booted') | ||
t.equal(err.message, 'root plugin has already booted') | ||
} | ||
@@ -60,0 +60,0 @@ }, 500) |
@@ -10,3 +10,3 @@ 'use strict' | ||
const app = boot() | ||
var last = false | ||
let last = false | ||
@@ -186,3 +186,3 @@ app.use(function (server, opts, done) { | ||
app.close(err => { | ||
t.is(err.message, 'some error') | ||
t.equal(err.message, 'some error') | ||
t.pass('Closed in the correct order') | ||
@@ -204,3 +204,3 @@ }) | ||
app.close((err, done) => { | ||
t.is(err, null) | ||
t.equal(err, null) | ||
t.pass('Closed in the correct order') | ||
@@ -210,7 +210,7 @@ setImmediate(done) | ||
app.close(err => { | ||
t.is(err, null) | ||
t.equal(err, null) | ||
t.pass('Closed in the correct order') | ||
}) | ||
app.close(err => { | ||
t.is(err, null) | ||
t.equal(err, null) | ||
t.pass('Closed in the correct order') | ||
@@ -241,3 +241,3 @@ }) | ||
app.close(err => { | ||
t.is(err.message, 'some error') | ||
t.equal(err.message, 'some error') | ||
t.pass('Closed in the correct order') | ||
@@ -275,3 +275,3 @@ }) | ||
const app = boot() | ||
var last = false | ||
let last = false | ||
@@ -295,7 +295,7 @@ app.on('start', () => { | ||
const app = boot() | ||
var order = [1, 2, 3, 4] | ||
const order = [1, 2, 3, 4] | ||
app.use(function (server, opts, done) { | ||
app.onClose(() => { | ||
t.is(order.shift(), 3) | ||
t.equal(order.shift(), 3) | ||
}) | ||
@@ -305,3 +305,3 @@ | ||
app.onClose(() => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
@@ -315,3 +315,3 @@ done() | ||
app.onClose(() => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
@@ -323,3 +323,3 @@ done() | ||
app.close(() => { | ||
t.is(order.shift(), 4) | ||
t.equal(order.shift(), 4) | ||
t.pass('Closed in the correct order') | ||
@@ -352,3 +352,3 @@ }) | ||
t.ok('called') | ||
t.is(arguments.length, 0) | ||
t.equal(arguments.length, 0) | ||
}) | ||
@@ -372,3 +372,3 @@ next() | ||
instance.onClose(function (context) { | ||
t.is(arguments.length, 1) | ||
t.equal(arguments.length, 1) | ||
}) | ||
@@ -465,7 +465,7 @@ next() | ||
const app = boot() | ||
var order = [1, 2, 3, 4, 5, 6] | ||
const order = [1, 2, 3, 4, 5, 6] | ||
app.onClose(() => { | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.is(order.shift(), 5) | ||
t.equal(order.shift(), 5) | ||
}) | ||
@@ -475,3 +475,3 @@ }) | ||
app.onClose(() => { | ||
t.is(order.shift(), 4) | ||
t.equal(order.shift(), 4) | ||
}) | ||
@@ -481,3 +481,3 @@ | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.is(order.shift(), 3) | ||
t.equal(order.shift(), 3) | ||
}) | ||
@@ -488,3 +488,3 @@ }) | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.is(order.shift(), 2) | ||
t.equal(order.shift(), 2) | ||
}) | ||
@@ -495,3 +495,3 @@ }) | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.is(order.shift(), 1) | ||
t.equal(order.shift(), 1) | ||
}) | ||
@@ -502,3 +502,3 @@ }) | ||
app.close(() => { | ||
t.is(order.shift(), 6) | ||
t.equal(order.shift(), 6) | ||
t.pass('Closed in the correct order') | ||
@@ -519,1 +519,44 @@ }) | ||
}) | ||
test('close custom server with async onClose handlers', t => { | ||
t.plan(7) | ||
const server = {} | ||
const app = boot(server) | ||
const order = [1, 2, 3, 4, 5, 6] | ||
server.onClose(() => { | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.equal(order.shift(), 5) | ||
}) | ||
}) | ||
server.onClose(() => { | ||
t.equal(order.shift(), 4) | ||
}) | ||
server.onClose(instance => { | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.equal(order.shift(), 3) | ||
}) | ||
}) | ||
server.onClose(async instance => { | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.equal(order.shift(), 2) | ||
}) | ||
}) | ||
server.onClose(async () => { | ||
return new Promise(resolve => setTimeout(resolve, 500)).then(() => { | ||
t.equal(order.shift(), 1) | ||
}) | ||
}) | ||
app.on('start', () => { | ||
app.close(() => { | ||
t.equal(order.shift(), 6) | ||
t.pass('Closed in the correct order') | ||
}) | ||
}) | ||
}) |
@@ -15,2 +15,3 @@ 'use strict' | ||
const app = boot() | ||
// eslint-disable-next-line no-var | ||
for (var i = 0; i < 12; i++) { | ||
@@ -17,0 +18,0 @@ app.on('preReady', noop) |
@@ -35,3 +35,3 @@ 'use strict' | ||
const server = app.listen(3000, cb) | ||
t.tearDown(server.close.bind(server)) | ||
t.teardown(server.close.bind(server)) | ||
}) | ||
@@ -38,0 +38,0 @@ |
@@ -24,3 +24,3 @@ 'use strict' | ||
app.use(function first (s, opts, cb) { | ||
t.notEqual(s, server) | ||
t.not(s, server) | ||
t.ok(server.isPrototypeOf(s)) | ||
@@ -45,3 +45,3 @@ cb() | ||
app.use(function first (s1, opts, cb) { | ||
t.notEqual(s1, server) | ||
t.not(s1, server) | ||
t.ok(server.isPrototypeOf(s1)) | ||
@@ -54,3 +54,3 @@ t.equal(s1.count, 1) | ||
function second (s2, opts, cb) { | ||
t.notEqual(s2, s1) | ||
t.not(s2, s1) | ||
t.ok(s1.isPrototypeOf(s2)) | ||
@@ -77,3 +77,3 @@ t.equal(s2.count, 2) | ||
app.use(function first (s1, opts, cb) { | ||
t.notEqual(s1, server) | ||
t.not(s1, server) | ||
t.ok(server.isPrototypeOf(s1)) | ||
@@ -83,3 +83,3 @@ t.equal(s1.count, 1) | ||
s1.use(third) | ||
var prev | ||
let prev | ||
@@ -90,3 +90,3 @@ cb() | ||
prev = s2 | ||
t.notEqual(s2, s1) | ||
t.not(s2, s1) | ||
t.ok(s1.isPrototypeOf(s2)) | ||
@@ -98,3 +98,3 @@ t.equal(s2.count, 2) | ||
function third (s3, opts, cb) { | ||
t.notEqual(s3, s1) | ||
t.not(s3, s1) | ||
t.ok(s1.isPrototypeOf(s3)) | ||
@@ -122,3 +122,3 @@ t.notOk(prev.isPrototypeOf(s3)) | ||
app.use(function first (s1, opts, cb) { | ||
t.notEqual(s1, server) | ||
t.not(s1, server) | ||
t.ok(server.isPrototypeOf(s1)) | ||
@@ -131,3 +131,3 @@ t.equal(s1.count, 1) | ||
function second (s2, opts, cb) { | ||
t.notEqual(s2, s1) | ||
t.not(s2, s1) | ||
t.ok(s1.isPrototypeOf(s2)) | ||
@@ -140,3 +140,3 @@ t.equal(s2.count, 2) | ||
app.use(function third (s1, opts, cb) { | ||
t.notEqual(s1, server) | ||
t.not(s1, server) | ||
t.ok(server.isPrototypeOf(s1)) | ||
@@ -149,3 +149,3 @@ t.equal(s1.count, 1) | ||
function fourth (s2, opts, cb) { | ||
t.notEqual(s2, s1) | ||
t.not(s2, s1) | ||
t.ok(s1.isPrototypeOf(s2)) | ||
@@ -189,3 +189,3 @@ t.equal(s2.count, 2) | ||
instance.use((i, opts, cb) => { | ||
t.notEqual(i, instance) | ||
t.not(i, instance) | ||
t.ok(instance.isPrototypeOf(i)) | ||
@@ -257,3 +257,3 @@ | ||
t.equal(s, server) | ||
t.deepEqual(opts, options) | ||
t.same(opts, options) | ||
@@ -267,3 +267,3 @@ const res = Object.create(s) | ||
app.use(function first (s, opts, cb) { | ||
t.notEqual(s, server) | ||
t.not(s, server) | ||
t.ok(server.isPrototypeOf(s)) | ||
@@ -284,3 +284,3 @@ cb() | ||
if (typeof opts !== 'function') { | ||
t.deepEqual(opts, options) | ||
t.same(opts, options) | ||
} | ||
@@ -296,3 +296,3 @@ | ||
app.use(function first (s, opts, cb) { | ||
t.notEqual(s, server) | ||
t.not(s, server) | ||
t.ok(server.isPrototypeOf(s)) | ||
@@ -305,3 +305,3 @@ s.foo = 'bar' | ||
t.notOk(s.foo) | ||
t.deepEqual(opts, { hello: 'world' }) | ||
t.same(opts, { hello: 'world' }) | ||
t.ok(server.isPrototypeOf(s)) | ||
@@ -328,15 +328,15 @@ cb() | ||
.use(function first (s, opts, cb) { | ||
t.equals(s.count, 1, 'should trigger override') | ||
t.equal(s.count, 1, 'should trigger override') | ||
cb() | ||
}) | ||
.after(function () { | ||
t.equals(overrideCalls, 1, 'after with 0 parameter should not trigger override') | ||
t.equal(overrideCalls, 1, 'after with 0 parameter should not trigger override') | ||
}) | ||
.after(function (err) { | ||
if (err) throw err | ||
t.equals(overrideCalls, 1, 'after with 1 parameter should not trigger override') | ||
t.equal(overrideCalls, 1, 'after with 1 parameter should not trigger override') | ||
}) | ||
.after(function (err, done) { | ||
if (err) throw err | ||
t.equals(overrideCalls, 1, 'after with 2 parameters should not trigger override') | ||
t.equal(overrideCalls, 1, 'after with 2 parameters should not trigger override') | ||
done() | ||
@@ -346,15 +346,15 @@ }) | ||
if (err) throw err | ||
t.equals(overrideCalls, 1, 'after with 3 parameters should not trigger override') | ||
t.equal(overrideCalls, 1, 'after with 3 parameters should not trigger override') | ||
done() | ||
}) | ||
.after(async function () { | ||
t.equals(overrideCalls, 1, 'async after with 0 parameter should not trigger override') | ||
t.equal(overrideCalls, 1, 'async after with 0 parameter should not trigger override') | ||
}) | ||
.after(async function (err) { | ||
if (err) throw err | ||
t.equals(overrideCalls, 1, 'async after with 1 parameter should not trigger override') | ||
t.equal(overrideCalls, 1, 'async after with 1 parameter should not trigger override') | ||
}) | ||
.after(async function (err, context) { | ||
if (err) throw err | ||
t.equals(overrideCalls, 1, 'async after with 2 parameters should not trigger override') | ||
t.equal(overrideCalls, 1, 'async after with 2 parameters should not trigger override') | ||
}) | ||
@@ -377,3 +377,3 @@ }) | ||
app.use(function first (s1, opts, cb) { | ||
t.notEqual(s1, server) | ||
t.not(s1, server) | ||
t.ok(server.isPrototypeOf(s1)) | ||
@@ -388,3 +388,3 @@ t.equal(s1.count, 1) | ||
function second (s2, opts, cb) { | ||
t.notEqual(s2, s1) | ||
t.not(s2, s1) | ||
t.ok(s1.isPrototypeOf(s2)) | ||
@@ -391,0 +391,0 @@ t.equal(s2.count, 2) |
@@ -20,5 +20,5 @@ 'use strict' | ||
t.ok(err) | ||
t.strictEqual(err.fn, one) | ||
t.strictEqual(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'one')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
t.equal(err.fn, one) | ||
t.equal(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'one')) | ||
t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
}) | ||
@@ -40,5 +40,5 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.fn, two) | ||
t.strictEqual(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'two')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
t.equal(err.fn, two) | ||
t.equal(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'two')) | ||
t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
}) | ||
@@ -55,4 +55,4 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', require.resolve('./fixtures/plugin-no-next'))) | ||
t.strictEqual(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
t.equal(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', require.resolve('./fixtures/plugin-no-next'))) | ||
t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
}) | ||
@@ -72,4 +72,4 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'function (app, opts, next) { -- // do not call next on purpose - code as name')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
t.equal(err.message, message('ERR_AVVIO_PLUGIN_TIMEOUT', 'function (app, opts, next) { -- // do not call next on purpose - code as name')) | ||
t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') | ||
}) | ||
@@ -88,3 +88,3 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, 'kaboom') | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
@@ -113,3 +113,3 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, 'kaboom') | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
@@ -156,4 +156,4 @@ }, 20) | ||
t.ok(err) | ||
t.strictEqual(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
t.equal(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.equal(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
// don't rethrow the error | ||
@@ -176,4 +176,4 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
t.equal(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.equal(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
done(err) | ||
@@ -200,4 +200,4 @@ }) | ||
t.ok(err) | ||
t.strictEqual(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.strictEqual(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
t.equal(err.message, message('ERR_AVVIO_READY_TIMEOUT', 'onReadyWithoutDone')) | ||
t.equal(err.code, 'ERR_AVVIO_READY_TIMEOUT') | ||
done(err) | ||
@@ -204,0 +204,0 @@ }) |
@@ -42,3 +42,3 @@ 'use strict' | ||
t.equals(lines.length, linesExpected.length) | ||
t.equal(lines.length, linesExpected.length) | ||
lines.forEach((l, i) => { | ||
@@ -45,0 +45,0 @@ t.match(l, linesExpected[i]) |
@@ -26,3 +26,3 @@ 'use strict' | ||
outJson.diff = /\d*/ | ||
t.like(json, outJson) | ||
t.match(json, outJson) | ||
}) | ||
@@ -38,3 +38,3 @@ | ||
}) | ||
t.like(json, outJson) | ||
t.match(json, outJson) | ||
done() | ||
@@ -50,3 +50,3 @@ } | ||
}) | ||
t.like(json, outJson) | ||
t.match(json, outJson) | ||
done() | ||
@@ -62,3 +62,3 @@ } | ||
}) | ||
t.like(json, outJson) | ||
t.match(json, outJson) | ||
done() | ||
@@ -124,3 +124,3 @@ } | ||
const json = app.toJSON() | ||
t.like(json, outJson) | ||
t.match(json, outJson) | ||
}) | ||
@@ -127,0 +127,0 @@ |
@@ -372,1 +372,8 @@ import * as avvio from "../../"; | ||
} | ||
{ | ||
const app = avvio(); | ||
const plugin: avvio.Plugin<any, any> = async (): Promise<void> => {}; | ||
const promise = plugin(app, {}, undefined as any); | ||
(promise instanceof Promise); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137091
4640
690