Flaska: If http server supports listenAsync (service-core for example) then use that instead of callback listen()
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
b97e34c1eb
commit
975646d336
3 changed files with 53 additions and 2 deletions
|
@ -1066,6 +1066,10 @@ ctx.state.nonce = nonce;
|
||||||
this.compile()
|
this.compile()
|
||||||
this.server = this.http.createServer(this.requestStart.bind(this))
|
this.server = this.http.createServer(this.requestStart.bind(this))
|
||||||
|
|
||||||
|
if (this.server.listenAsync && typeof(this.server.listenAsync) === 'function') {
|
||||||
|
return this.server.listenAsync(port, ip)
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
this.server.listen(port, ip, function(err) {
|
this.server.listen(port, ip, function(err) {
|
||||||
if (err) return rej(err)
|
if (err) return rej(err)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "flaska",
|
"name": "flaska",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.",
|
"description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.",
|
||||||
"main": "flaska.mjs",
|
"main": "flaska.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -925,7 +925,7 @@ t.describe('#listenAsync()', function() {
|
||||||
assert.strictEqual(checkIp, assertIp)
|
assert.strictEqual(checkIp, assertIp)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('call http correctly if only port specified', async function() {
|
t.test('call http and listen correctly if only port specified', async function() {
|
||||||
const assertPort = 325897235
|
const assertPort = 325897235
|
||||||
let checkPort = null
|
let checkPort = null
|
||||||
let checkIp = null
|
let checkIp = null
|
||||||
|
@ -946,6 +946,53 @@ t.describe('#listenAsync()', function() {
|
||||||
assert.strictEqual(checkIp, '::')
|
assert.strictEqual(checkIp, '::')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.test('call http and listenAsync correctly if supported', async function() {
|
||||||
|
const assertPort = 4632
|
||||||
|
const assertIp = 'asdf'
|
||||||
|
const assertReturns = { a: 1 }
|
||||||
|
const stubListenAsync = stub().resolves(assertReturns)
|
||||||
|
|
||||||
|
let flaska = new Flaska({}, {
|
||||||
|
createServer: function() {
|
||||||
|
return {
|
||||||
|
listenAsync: stubListenAsync,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert.ok(flaska.requestStart)
|
||||||
|
flaska.requestStart = function() {
|
||||||
|
checkInternalThis = this
|
||||||
|
checkIsTrue = true
|
||||||
|
}
|
||||||
|
let res = await flaska.listenAsync(assertPort, assertIp)
|
||||||
|
assert.strictEqual(res, assertReturns)
|
||||||
|
assert.strictEqual(stubListenAsync.firstCall[0], assertPort)
|
||||||
|
assert.strictEqual(stubListenAsync.firstCall[1], assertIp)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.test('call http and listenAsync correctly if supported and ip is null', async function() {
|
||||||
|
const assertPort = 325897235
|
||||||
|
const assertReturns = { a: 1 }
|
||||||
|
const stubListenAsync = stub().resolves(assertReturns)
|
||||||
|
|
||||||
|
let flaska = new Flaska({}, {
|
||||||
|
createServer: function() {
|
||||||
|
return {
|
||||||
|
listenAsync: stubListenAsync,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert.ok(flaska.requestStart)
|
||||||
|
flaska.requestStart = function() {
|
||||||
|
checkInternalThis = this
|
||||||
|
checkIsTrue = true
|
||||||
|
}
|
||||||
|
let res = await flaska.listenAsync(assertPort)
|
||||||
|
assert.strictEqual(res, assertReturns)
|
||||||
|
assert.strictEqual(stubListenAsync.firstCall[0], assertPort)
|
||||||
|
assert.strictEqual(stubListenAsync.firstCall[1], '::')
|
||||||
|
})
|
||||||
|
|
||||||
t.test('register requestStart if no async', async function() {
|
t.test('register requestStart if no async', async function() {
|
||||||
let checkIsTrue = false
|
let checkIsTrue = false
|
||||||
let checkInternalThis = null
|
let checkInternalThis = null
|
||||||
|
|
Loading…
Reference in a new issue