Skip to content

Commit e026aee

Browse files
committed
plugin.test.ts: Switch to testutil.HttpServer
1 parent 0ebf0fa commit e026aee

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

test/plugin.test.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
import { logger } from "@coder/logger"
22
import * as express from "express"
3-
import * as fs from "fs"
43
import { describe } from "mocha"
5-
import * as path from "path"
6-
import * as supertest from "supertest"
74
import { PluginAPI } from "../src/node/plugin"
5+
import * as testutil from "./testutil"
6+
import * as path from "path"
7+
import * as assert from "assert"
88
import * as apps from "../src/node/routes/apps"
9+
import * as fs from "fs"
910
const fsp = fs.promises
1011

1112
/**
1213
* Use $LOG_LEVEL=debug to see debug logs.
1314
*/
1415
describe("plugin", () => {
1516
let papi: PluginAPI
16-
let app: express.Application
17-
let agent: supertest.SuperAgentTest
17+
let s: testutil.HttpServer
1818

1919
before(async () => {
20-
papi = new PluginAPI(logger, path.resolve(__dirname, "test-plugin") + ":meow")
20+
papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`)
2121
await papi.loadPlugins()
2222

23-
app = express.default()
23+
const app = express.default()
2424
papi.mount(app)
25-
2625
app.use("/api/applications", apps.router(papi))
2726

28-
agent = supertest.agent(app)
27+
s = new testutil.HttpServer()
28+
await s.listen(app)
29+
})
30+
31+
after(async () => {
32+
await s.close()
2933
})
3034

3135
it("/api/applications", async () => {
32-
await agent.get("/api/applications").expect(200, [
36+
const resp = await s.fetch("/api/applications")
37+
assert.equal(200, resp.status)
38+
const body = await resp.json()
39+
logger.debug(`${JSON.stringify(body)}`)
40+
assert.deepEqual(body, [
3341
{
3442
name: "Test App",
3543
version: "4.0.0",
@@ -57,6 +65,9 @@ describe("plugin", () => {
5765
const indexHTML = await fsp.readFile(path.join(__dirname, "test-plugin/public/index.html"), {
5866
encoding: "utf8",
5967
})
60-
await agent.get("/test-plugin/test-app").expect(200, indexHTML)
68+
const resp = await s.fetch("/test-plugin/test-app")
69+
assert.equal(200, resp.status)
70+
const body = await resp.text()
71+
assert.equal(body, indexHTML)
6172
})
6273
})

0 commit comments

Comments
 (0)