Skip to content

Commit

Permalink
test: add test description & change test require style & change case …
Browse files Browse the repository at this point in the history
…for esm test (#181)

* test: add test description &  change test require style & change case for esm test

* Update test/esm.test.js

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>

* test: change case for esm test

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
  • Loading branch information
xtx1130 and Eomm authored Mar 22, 2022
1 parent 1ef0e56 commit 74334bb
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 112 deletions.
2 changes: 1 addition & 1 deletion test/after-and-ready.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
44 changes: 23 additions & 21 deletions test/after-pass-through.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
30 changes: 16 additions & 14 deletions test/after-throw.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
2 changes: 1 addition & 1 deletion test/async-await.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('..')
Expand Down
3 changes: 1 addition & 2 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/callbacks.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')

test('reentrant', (t) => {
Expand Down
32 changes: 17 additions & 15 deletions test/catch-override-exception.test.js
Original file line number Diff line number Diff line change
@@ -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/)
})
})
2 changes: 1 addition & 1 deletion test/chainable.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')

test('chainable standalone', (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/close.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions test/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { test } = require('tap')
const { createError } = require('../lib/errors')

Expand Down
4 changes: 1 addition & 3 deletions test/esm.mjs
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
16 changes: 7 additions & 9 deletions test/esm.test.js
Original file line number Diff line number Diff line change
@@ -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
})
})
}
})
2 changes: 1 addition & 1 deletion test/events-listeners.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')
const noop = () => {}

Expand Down
68 changes: 35 additions & 33 deletions test/express.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
})
})
2 changes: 1 addition & 1 deletion test/override.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions test/plugin-name.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions test/plugin-timeout.test.js
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion test/pretty-print.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')

test('pretty print', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/reentrant.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')

test('one level', (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/to-json.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('tap').test
const { test } = require('tap')
const boot = require('..')

test('to json', (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/twice-done.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit 74334bb

Please sign in to comment.