2020-10-30 08:18:59 +01:00
|
|
|
import { logger } from "@coder/logger"
|
2021-01-14 15:37:41 +01:00
|
|
|
import * as assert from "assert"
|
2020-11-06 20:46:49 +01:00
|
|
|
import * as express from "express"
|
|
|
|
import * as fs from "fs"
|
2020-10-30 08:26:30 +01:00
|
|
|
import * as path from "path"
|
2020-11-06 20:46:49 +01:00
|
|
|
import { PluginAPI } from "../src/node/plugin"
|
2020-11-06 15:51:46 +01:00
|
|
|
import * as apps from "../src/node/routes/apps"
|
2021-01-14 15:53:34 +01:00
|
|
|
import * as httpserver from "./httpserver"
|
2020-11-06 16:09:35 +01:00
|
|
|
const fsp = fs.promises
|
2020-10-30 08:18:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use $LOG_LEVEL=debug to see debug logs.
|
|
|
|
*/
|
|
|
|
describe("plugin", () => {
|
2020-11-06 15:51:46 +01:00
|
|
|
let papi: PluginAPI
|
2021-01-14 15:53:34 +01:00
|
|
|
let s: httpserver.HttpServer
|
2020-11-06 15:51:46 +01:00
|
|
|
|
|
|
|
before(async () => {
|
2021-01-14 15:37:41 +01:00
|
|
|
papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`)
|
2020-10-30 08:18:59 +01:00
|
|
|
await papi.loadPlugins()
|
|
|
|
|
2021-01-14 15:37:41 +01:00
|
|
|
const app = express.default()
|
2020-11-06 15:51:46 +01:00
|
|
|
papi.mount(app)
|
|
|
|
app.use("/api/applications", apps.router(papi))
|
|
|
|
|
2021-01-14 15:53:34 +01:00
|
|
|
s = new httpserver.HttpServer()
|
2021-01-14 15:37:41 +01:00
|
|
|
await s.listen(app)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await s.close()
|
2020-11-06 15:51:46 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it("/api/applications", async () => {
|
2021-01-14 15:37:41 +01:00
|
|
|
const resp = await s.fetch("/api/applications")
|
|
|
|
assert.equal(200, resp.status)
|
|
|
|
const body = await resp.json()
|
|
|
|
logger.debug(`${JSON.stringify(body)}`)
|
|
|
|
assert.deepEqual(body, [
|
2020-11-06 15:51:46 +01:00
|
|
|
{
|
|
|
|
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 08:18:59 +01:00
|
|
|
|
2020-11-06 15:51:46 +01:00
|
|
|
plugin: {
|
|
|
|
name: "test-plugin",
|
|
|
|
version: "1.0.0",
|
|
|
|
modulePath: path.join(__dirname, "test-plugin"),
|
2020-11-04 03:11:14 +01:00
|
|
|
|
2020-11-06 15:51:46 +01:00
|
|
|
displayName: "Test Plugin",
|
|
|
|
description: "Plugin used in code-server tests.",
|
|
|
|
routerPath: "/test-plugin",
|
2020-11-04 03:45:25 +01:00
|
|
|
homepageURL: "https://example.com",
|
2020-10-30 08:18:59 +01:00
|
|
|
},
|
2020-11-06 15:51:46 +01:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("/test-plugin/test-app", async () => {
|
2020-11-06 16:09:35 +01:00
|
|
|
const indexHTML = await fsp.readFile(path.join(__dirname, "test-plugin/public/index.html"), {
|
|
|
|
encoding: "utf8",
|
|
|
|
})
|
2021-01-14 15:37:41 +01:00
|
|
|
const resp = await s.fetch("/test-plugin/test-app")
|
|
|
|
assert.equal(200, resp.status)
|
|
|
|
const body = await resp.text()
|
|
|
|
assert.equal(body, indexHTML)
|
2020-10-30 08:18:59 +01:00
|
|
|
})
|
|
|
|
})
|