Archived
1
0

plugin: Test endpoints via supertest

Unfortunately we can't use node-mocks-http to test a express.Router
that has async routes. See https://github.com/howardabrams/node-mocks-http/issues/225

router will just return undefined if the executing handler is async and
so the test will have no way to wait for it to complete. Thus, we have
to use supertest which starts an actual HTTP server in the background
and uses a HTTP client to send requests.
This commit is contained in:
Anmol Sethi
2020-11-06 09:51:46 -05:00
parent 9453f891df
commit 197a09f0c1
4 changed files with 132 additions and 32 deletions

View File

@ -8,19 +8,24 @@ export const plugin: pluginapi.Plugin = {
homepageURL: "https://example.com",
description: "Plugin used in code-server tests.",
init: (config) => {
init(config) {
config.logger.debug("test-plugin loaded!")
},
router: () => {
router() {
const r = express.Router()
r.get("/test-app", (req, res) => {
res.json({
date: new Date("2000/02/05"),
})
})
r.get("/goland/icon.svg", (req, res) => {
res.sendFile(fspath.resolve(__dirname, "../public/icon.svg"))
})
return r
},
applications: () => {
applications() {
return [
{
name: "Test App",