|
1 | 1 | import { logger } from "@coder/logger"
|
2 | 2 | import * as express from "express"
|
3 |
| -import * as fs from "fs" |
4 | 3 | import { describe } from "mocha"
|
5 |
| -import * as path from "path" |
6 |
| -import * as supertest from "supertest" |
7 | 4 | import { PluginAPI } from "../src/node/plugin"
|
| 5 | +import * as testutil from "./testutil" |
| 6 | +import * as path from "path" |
| 7 | +import * as assert from "assert" |
8 | 8 | import * as apps from "../src/node/routes/apps"
|
| 9 | +import * as fs from "fs" |
9 | 10 | const fsp = fs.promises
|
10 | 11 |
|
11 | 12 | /**
|
12 | 13 | * Use $LOG_LEVEL=debug to see debug logs.
|
13 | 14 | */
|
14 | 15 | describe("plugin", () => {
|
15 | 16 | let papi: PluginAPI
|
16 |
| - let app: express.Application |
17 |
| - let agent: supertest.SuperAgentTest |
| 17 | + let s: testutil.HttpServer |
18 | 18 |
|
19 | 19 | before(async () => {
|
20 |
| - papi = new PluginAPI(logger, path.resolve(__dirname, "test-plugin") + ":meow") |
| 20 | + papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`) |
21 | 21 | await papi.loadPlugins()
|
22 | 22 |
|
23 |
| - app = express.default() |
| 23 | + const app = express.default() |
24 | 24 | papi.mount(app)
|
25 |
| - |
26 | 25 | app.use("/api/applications", apps.router(papi))
|
27 | 26 |
|
28 |
| - agent = supertest.agent(app) |
| 27 | + s = new testutil.HttpServer() |
| 28 | + await s.listen(app) |
| 29 | + }) |
| 30 | + |
| 31 | + after(async () => { |
| 32 | + await s.close() |
29 | 33 | })
|
30 | 34 |
|
31 | 35 | 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, [ |
33 | 41 | {
|
34 | 42 | name: "Test App",
|
35 | 43 | version: "4.0.0",
|
@@ -57,6 +65,9 @@ describe("plugin", () => {
|
57 | 65 | const indexHTML = await fsp.readFile(path.join(__dirname, "test-plugin/public/index.html"), {
|
58 | 66 | encoding: "utf8",
|
59 | 67 | })
|
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) |
61 | 72 | })
|
62 | 73 | })
|
0 commit comments