From bc02005dc097a10b5216b616ff0bd7a911240748 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Sat, 17 Sep 2022 10:33:03 -0700 Subject: [PATCH] refactor: move test-plugin to integration suite This seems more appropriate given this tests how a plugin might work within code-server. --- ci/dev/test-integration.sh | 9 ++++++++- ci/dev/test-unit.sh | 7 ------- test/{unit/node => integration}/plugin.test.ts | 10 +++++----- .../node => integration}/test-plugin/.eslintrc.js | 0 .../node => integration}/test-plugin/.gitignore | 0 .../node => integration}/test-plugin/Makefile | 0 .../node => integration}/test-plugin/package.json | 0 .../test-plugin/public/icon.svg | 0 .../test-plugin/public/index.html | 0 .../node => integration}/test-plugin/src/index.ts | 14 +++++++++----- .../node => integration}/test-plugin/tsconfig.json | 0 .../node => integration}/test-plugin/yarn.lock | 0 test/tsconfig.json | 1 - 13 files changed, 22 insertions(+), 19 deletions(-) rename test/{unit/node => integration}/plugin.test.ts (92%) rename test/{unit/node => integration}/test-plugin/.eslintrc.js (100%) rename test/{unit/node => integration}/test-plugin/.gitignore (100%) rename test/{unit/node => integration}/test-plugin/Makefile (100%) rename test/{unit/node => integration}/test-plugin/package.json (100%) rename test/{unit/node => integration}/test-plugin/public/icon.svg (100%) rename test/{unit/node => integration}/test-plugin/public/index.html (100%) rename test/{unit/node => integration}/test-plugin/src/index.ts (72%) rename test/{unit/node => integration}/test-plugin/tsconfig.json (100%) rename test/{unit/node => integration}/test-plugin/yarn.lock (100%) diff --git a/ci/dev/test-integration.sh b/ci/dev/test-integration.sh index 2d46bb895..e9d260883 100755 --- a/ci/dev/test-integration.sh +++ b/ci/dev/test-integration.sh @@ -24,6 +24,13 @@ main() { path="$CODE_SERVER_PATH" fi + # TODO@jsjoeio - skip if already built + # TODO@jsjoeio - move to integration test suite too + echo "Building test plugin" + pushd test/integration/test-plugin + make -s out/index.js + popd + echo "Running tests with code-server binary: '$path'" if [[ ! -f $path ]]; then @@ -33,7 +40,7 @@ main() { exit 1 fi - CODE_SERVER_PATH="$path" CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --coverage=false --testRegex "./test/integration" --testPathIgnorePatterns "./test/integration/fixtures" + CODE_SERVER_PATH="$path" CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --coverage=false --testRegex "./test/integration" --testPathIgnorePatterns "./test/integration/fixtures" --testPathIgnorePatterns "./test/integration/test-plugin" } main "$@" diff --git a/ci/dev/test-unit.sh b/ci/dev/test-unit.sh index 21bce8bdf..e832c1031 100755 --- a/ci/dev/test-unit.sh +++ b/ci/dev/test-unit.sh @@ -6,13 +6,6 @@ main() { source ./ci/lib.sh - # TODO@jsjoeio - skip if already built - # TODO@jsjoeio - move to integration test suite too - echo "Building test plugin" - pushd test/unit/node/test-plugin - make -s out/index.js - popd - # Our code imports from `out` in order to work during development but if you # have only built for production you will have not have this directory. In # that case symlink `out` to a production build directory. diff --git a/test/unit/node/plugin.test.ts b/test/integration/plugin.test.ts similarity index 92% rename from test/unit/node/plugin.test.ts rename to test/integration/plugin.test.ts index 88210fd85..2df91d0c5 100644 --- a/test/unit/node/plugin.test.ts +++ b/test/integration/plugin.test.ts @@ -2,11 +2,11 @@ import { logger } from "@coder/logger" import * as express from "express" import * as fs from "fs" import * as path from "path" -import { HttpCode } from "../../../src/common/http" -import { AuthType } from "../../../src/node/cli" -import { codeServer, PluginAPI } from "../../../src/node/plugin" -import * as apps from "../../../src/node/routes/apps" -import * as httpserver from "../../utils/httpserver" +import { HttpCode } from "../../src/common/http" +import { AuthType } from "../../src/node/cli" +import { codeServer, PluginAPI } from "../../src/node/plugin" +import * as apps from "../../src/node/routes/apps" +import * as httpserver from "../utils/httpserver" const fsp = fs.promises // Jest overrides `require` so our usual override doesn't work. diff --git a/test/unit/node/test-plugin/.eslintrc.js b/test/integration/test-plugin/.eslintrc.js similarity index 100% rename from test/unit/node/test-plugin/.eslintrc.js rename to test/integration/test-plugin/.eslintrc.js diff --git a/test/unit/node/test-plugin/.gitignore b/test/integration/test-plugin/.gitignore similarity index 100% rename from test/unit/node/test-plugin/.gitignore rename to test/integration/test-plugin/.gitignore diff --git a/test/unit/node/test-plugin/Makefile b/test/integration/test-plugin/Makefile similarity index 100% rename from test/unit/node/test-plugin/Makefile rename to test/integration/test-plugin/Makefile diff --git a/test/unit/node/test-plugin/package.json b/test/integration/test-plugin/package.json similarity index 100% rename from test/unit/node/test-plugin/package.json rename to test/integration/test-plugin/package.json diff --git a/test/unit/node/test-plugin/public/icon.svg b/test/integration/test-plugin/public/icon.svg similarity index 100% rename from test/unit/node/test-plugin/public/icon.svg rename to test/integration/test-plugin/public/icon.svg diff --git a/test/unit/node/test-plugin/public/index.html b/test/integration/test-plugin/public/index.html similarity index 100% rename from test/unit/node/test-plugin/public/index.html rename to test/integration/test-plugin/public/index.html diff --git a/test/unit/node/test-plugin/src/index.ts b/test/integration/test-plugin/src/index.ts similarity index 72% rename from test/unit/node/test-plugin/src/index.ts rename to test/integration/test-plugin/src/index.ts index 22ef723ba..2d34ad17a 100644 --- a/test/unit/node/test-plugin/src/index.ts +++ b/test/integration/test-plugin/src/index.ts @@ -1,22 +1,26 @@ +// TODO@jsjoeio - how do I fix this? +// @ts-ignore - we know code-server exists import * as cs from "code-server" import * as fspath from "path" +type FixMeLater = any + export const plugin: cs.Plugin = { displayName: "Test Plugin", routerPath: "/test-plugin", homepageURL: "https://example.com", description: "Plugin used in code-server tests.", - init(config) { + init(config: FixMeLater) { config.logger.debug("test-plugin loaded!") }, router() { const r = cs.express.Router() - r.get("/test-app", (_, res) => { + r.get("/test-app", (_: FixMeLater, res: FixMeLater) => { res.sendFile(fspath.resolve(__dirname, "../public/index.html")) }) - r.get("/goland/icon.svg", (_, res) => { + r.get("/goland/icon.svg", (_: FixMeLater, res: FixMeLater) => { res.sendFile(fspath.resolve(__dirname, "../public/icon.svg")) }) r.get("/error", () => { @@ -27,8 +31,8 @@ export const plugin: cs.Plugin = { wsRouter() { const wr = cs.WsRouter() - wr.ws("/test-app", (req) => { - cs.wss.handleUpgrade(req, req.ws, req.head, (ws) => { + wr.ws("/test-app", (req: FixMeLater) => { + cs.wss.handleUpgrade(req, req.ws, req.head, (ws: FixMeLater) => { req.ws.resume() ws.send("hello") }) diff --git a/test/unit/node/test-plugin/tsconfig.json b/test/integration/test-plugin/tsconfig.json similarity index 100% rename from test/unit/node/test-plugin/tsconfig.json rename to test/integration/test-plugin/tsconfig.json diff --git a/test/unit/node/test-plugin/yarn.lock b/test/integration/test-plugin/yarn.lock similarity index 100% rename from test/unit/node/test-plugin/yarn.lock rename to test/integration/test-plugin/yarn.lock diff --git a/test/tsconfig.json b/test/tsconfig.json index 3e568e887..179ac1d81 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,5 +1,4 @@ { "extends": "../tsconfig.json", "include": ["./**/*.ts"], - "exclude": ["./unit/node/test-plugin"] }