2020-10-30 15:18:59 +08:00
|
|
|
import { logger } from "@coder/logger"
|
2020-11-07 03:46:49 +08:00
|
|
|
import * as express from "express"
|
|
|
|
import * as fs from "fs"
|
2020-10-30 15:26:30 +08:00
|
|
|
import { describe } from "mocha"
|
|
|
|
import * as path from "path"
|
2020-11-06 22:51:46 +08:00
|
|
|
import * as supertest from "supertest"
|
2020-11-07 03:46:49 +08:00
|
|
|
import { PluginAPI } from "../src/node/plugin"
|
2020-11-06 22:51:46 +08:00
|
|
|
import * as apps from "../src/node/routes/apps"
|
2020-11-06 23:09:35 +08:00
|
|
|
const fsp = fs.promises
|
2020-10-30 15:18:59 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use $LOG_LEVEL=debug to see debug logs.
|
|
|
|
*/
|
|
|
|
describe("plugin", () => {
|
2020-11-06 22:51:46 +08:00
|
|
|
let papi: PluginAPI
|
|
|
|
let app: express.Application
|
|
|
|
let agent: supertest.SuperAgentTest
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
papi = new PluginAPI(logger, path.resolve(__dirname, "test-plugin") + ":meow")
|
2020-10-30 15:18:59 +08:00
|
|
|
await papi.loadPlugins()
|
|
|
|
|
2020-11-06 22:51:46 +08:00
|
|
|
app = express.default()
|
|
|
|
papi.mount(app)
|
|
|
|
|
|
|
|
app.use("/api/applications", apps.router(papi))
|
|
|
|
|
|
|
|
agent = supertest.agent(app)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("/api/applications", async () => {
|
|
|
|
await agent.get("/api/applications").expect(200, [
|
|
|
|
{
|
|
|
|
name: "Test App",
|
|
|
|
version: "4.0.0",
|
|
|
|
|
|
|
|
description: "This app does XYZ.",
|
|
|
|
iconPath: "/test-plugin/test-app/icon.svg",
|
|
|
|
homepageURL: "https://example.com",
|
|
|
|
path: "/test-plugin/test-app",
|
2020-10-30 15:18:59 +08:00
|
|
|
|
2020-11-06 22:51:46 +08:00
|
|
|
plugin: {
|
|
|
|
name: "test-plugin",
|
|
|
|
version: "1.0.0",
|
|
|
|
modulePath: path.join(__dirname, "test-plugin"),
|
2020-11-04 10:11:14 +08:00
|
|
|
|
2020-11-06 22:51:46 +08:00
|
|
|
displayName: "Test Plugin",
|
|
|
|
description: "Plugin used in code-server tests.",
|
|
|
|
routerPath: "/test-plugin",
|
2020-11-04 10:45:25 +08:00
|
|
|
homepageURL: "https://example.com",
|
2020-10-30 15:18:59 +08:00
|
|
|
},
|
2020-11-06 22:51:46 +08:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("/test-plugin/test-app", async () => {
|
2020-11-06 23:09:35 +08:00
|
|
|
const indexHTML = await fsp.readFile(path.join(__dirname, "test-plugin/public/index.html"), {
|
|
|
|
encoding: "utf8",
|
|
|
|
})
|
|
|
|
await agent.get("/test-plugin/test-app").expect(200, indexHTML)
|
2020-10-30 15:18:59 +08:00
|
|
|
})
|
|
|
|
})
|