-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test description & change test require style & change case …
…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
Showing
21 changed files
with
115 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters