Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from jaredwray/upgrading-typescript-to-4.9.4
upgrading typescript to 4.9.4
- Loading branch information
Showing
5 changed files
with
70 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable */ | ||
'use strict'; | ||
|
||
import http from 'node:http'; | ||
import express from 'express'; | ||
import pify from 'pify'; | ||
import bodyParser from 'body-parser'; | ||
|
||
const createTestServer = (opts = {}) => { | ||
const server = express(); | ||
server.http = http.createServer(server); | ||
|
||
server.set('etag', false); | ||
|
||
if (opts.bodyParser !== false) { | ||
server.use(bodyParser.json(Object.assign({ limit: '1mb', type: 'application/json' }, opts.bodyParser))); | ||
server.use(bodyParser.text(Object.assign({ limit: '1mb', type: 'text/plain' }, opts.bodyParser))); | ||
server.use(bodyParser.urlencoded(Object.assign({ limit: '1mb', type: 'application/x-www-form-urlencoded', extended: true }, opts.bodyParser))); | ||
server.use(bodyParser.raw(Object.assign({ limit: '1mb', type: 'application/octet-stream' }, opts.bodyParser))); | ||
} | ||
|
||
const send = fn => (req, res, next) => { | ||
const cb = typeof fn === 'function' ? fn(req, res, next) : fn; | ||
|
||
Promise.resolve(cb).then(val => { | ||
if (val) { | ||
res.send(val); | ||
} | ||
}); | ||
}; | ||
|
||
const get = server.get.bind(server); | ||
server.get = function () { | ||
const [path, ...handlers] = [...arguments]; | ||
|
||
for (const handler of handlers) { | ||
get(path, send(handler)); | ||
} | ||
}; | ||
|
||
server.listen = () => Promise.all([ | ||
pify(server.http.listen.bind(server.http))().then(() => { | ||
server.port = server.http.address().port; | ||
server.url = `http://localhost:${server.port}`; | ||
}) | ||
]); | ||
|
||
server.close = () => Promise.all([ | ||
pify(server.http.close.bind(server.http))().then(() => { | ||
server.port = undefined; | ||
server.url = undefined; | ||
}) | ||
]); | ||
|
||
return server.listen().then(() => server); | ||
}; | ||
|
||
export default createTestServer; |
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