Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8acb2ae

Browse files
committed
plugin.test.ts: Switch to testutil.HttpServer
1 parent ea1949e commit 8acb2ae

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

‎test/plugin.test.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
import { logger } from "@coder/logger"
2+
import * as assert from "assert"
23
import * as express from "express"
34
import * as fs from "fs"
45
import { describe } from "mocha"
56
import * as path from "path"
6-
import * as supertest from "supertest"
77
import { PluginAPI } from "../src/node/plugin"
88
import * as apps from "../src/node/routes/apps"
9+
import * as testutil from "./testutil"
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+
constapp = 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)

AltStyle によって変換されたページ (->オリジナル) /