refactor: move jest and add package.json to /test

This commit is contained in:
Joe Previte 2021-01-20 16:37:49 -07:00
parent 646ee3ad7f
commit 883dd13850
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
12 changed files with 3859 additions and 1824 deletions

View File

@ -6,8 +6,9 @@ main() {
cd test/test-plugin cd test/test-plugin
make -s out/index.js make -s out/index.js
cd "$OLDPWD" cd "$OLDPWD/test"
yarn jest "$@" yarn
yarn test "$@"
} }
main "$@" main "$@"

View File

@ -15,8 +15,7 @@
"strict": true, "strict": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"newLine": "lf", "newLine": "lf"
"skipLibCheck": true
}, },
"include": [ "include": [
"**/*.ts" "**/*.ts"

View File

@ -6,6 +6,6 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
export function isWeb(): boolean { export function isWeb(): boolean {
// NOTE@coder: Remove unused ts-expect-error directive which causes tsc to error. // @ts-expect-error
return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web; return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web;
} }

View File

@ -35,7 +35,6 @@
"@types/express": "^4.17.8", "@types/express": "^4.17.8",
"@types/fs-extra": "^8.0.1", "@types/fs-extra": "^8.0.1",
"@types/http-proxy": "^1.17.4", "@types/http-proxy": "^1.17.4",
"@types/jest": "^26.0.20",
"@types/js-yaml": "^3.12.3", "@types/js-yaml": "^3.12.3",
"@types/node": "^12.12.7", "@types/node": "^12.12.7",
"@types/node-fetch": "^2.5.7", "@types/node-fetch": "^2.5.7",
@ -55,7 +54,6 @@
"eslint-config-prettier": "^6.0.0", "eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2", "eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0", "eslint-plugin-prettier": "^3.1.0",
"jest": "^26.6.3",
"leaked-handles": "^5.2.0", "leaked-handles": "^5.2.0",
"parcel-bundler": "^1.12.4", "parcel-bundler": "^1.12.4",
"prettier": "^2.0.5", "prettier": "^2.0.5",

22
test/package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/node-fetch": "^2.5.8",
"@types/supertest": "^2.0.10",
"jest": "^26.6.3",
"node-fetch": "^2.6.1",
"supertest": "^6.1.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
}
}

View File

@ -1,5 +1,4 @@
import { logger } from "@coder/logger" import { logger } from "@coder/logger"
import * as assert from "assert"
import * as express from "express" import * as express from "express"
import * as fs from "fs" import * as fs from "fs"
import * as path from "path" import * as path from "path"
@ -15,7 +14,7 @@ describe("plugin", () => {
let papi: PluginAPI let papi: PluginAPI
let s: httpserver.HttpServer let s: httpserver.HttpServer
before(async () => { beforeAll(async () => {
papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`) papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`)
await papi.loadPlugins() await papi.loadPlugins()
@ -27,16 +26,16 @@ describe("plugin", () => {
await s.listen(app) await s.listen(app)
}) })
after(async () => { afterAll(async () => {
await s.close() await s.close()
}) })
it("/api/applications", async () => { it("/api/applications", async () => {
const resp = await s.fetch("/api/applications") const resp = await s.fetch("/api/applications")
assert.equal(200, resp.status) expect(resp.status).toBe(200)
const body = await resp.json() const body = await resp.json()
logger.debug(`${JSON.stringify(body)}`) logger.debug(`${JSON.stringify(body)}`)
assert.deepEqual(body, [ expect(body).toStrictEqual([
{ {
name: "Test App", name: "Test App",
version: "4.0.0", version: "4.0.0",
@ -65,8 +64,8 @@ describe("plugin", () => {
encoding: "utf8", encoding: "utf8",
}) })
const resp = await s.fetch("/test-plugin/test-app") const resp = await s.fetch("/test-plugin/test-app")
assert.equal(200, resp.status) expect(resp.status).toBe(200)
const body = await resp.text() const body = await resp.text()
assert.equal(body, indexHTML) expect(body).toBe(indexHTML)
}) })
}) })

View File

@ -1,4 +1,3 @@
import * as assert from "assert"
import * as express from "express" import * as express from "express"
import * as httpserver from "./httpserver" import * as httpserver from "./httpserver"
import * as integration from "./integration" import * as integration from "./integration"
@ -8,7 +7,7 @@ describe("proxy", () => {
const nhooyrDevServer = new httpserver.HttpServer() const nhooyrDevServer = new httpserver.HttpServer()
let proxyPath: string let proxyPath: string
before(async () => { beforeAll(async () => {
const e = express.default() const e = express.default()
await nhooyrDevServer.listen(e) await nhooyrDevServer.listen(e)
e.get("/wsup", (req, res) => { e.get("/wsup", (req, res) => {
@ -20,7 +19,7 @@ describe("proxy", () => {
}) })
}) })
after(async () => { afterAll(async () => {
await nhooyrDevServer.close() await nhooyrDevServer.close()
}) })
@ -34,14 +33,16 @@ describe("proxy", () => {
it("should rewrite the base path", async () => { it("should rewrite the base path", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "") ;[, , codeServer] = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath) const resp = await codeServer.fetch(proxyPath)
assert.equal(resp.status, 200) expect(resp.status).toBe(200)
assert.equal(await resp.json(), "asher is the best") const json = await resp.json()
expect(json).toBe("asher is the best")
}) })
it("should not rewrite the base path", async () => { it("should not rewrite the base path", async () => {
;[, , codeServer] = await integration.setup(["--auth=none", "--proxy-path-passthrough=true"], "") ;[, , codeServer] = await integration.setup(["--auth=none", "--proxy-path-passthrough=true"], "")
const resp = await codeServer.fetch(proxyPath) const resp = await codeServer.fetch(proxyPath)
assert.equal(resp.status, 200) expect(resp.status).toBe(200)
assert.equal(await resp.json(), "joe is the best") const json = await resp.json()
expect(json).toBe("joe is the best")
}) })
}) })

View File

@ -1,4 +1,10 @@
{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"include": ["./**/*.ts"] "compilerOptions": {
"typeRoots": ["node_modules/@types", "../typings"],
"composite": true
},
"include": ["./**/*.ts"],
"exclude": ["node_modules/**"],
"types": ["jest"]
} }

3760
test/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,9 @@
"sourceMap": true, "sourceMap": true,
"tsBuildInfoFile": "./.cache/tsbuildinfo", "tsBuildInfoFile": "./.cache/tsbuildinfo",
"incremental": true, "incremental": true,
"rootDir": "./src",
"typeRoots": ["./node_modules/@types", "./typings"], "typeRoots": ["./node_modules/@types", "./typings"],
"downlevelIteration": true "downlevelIteration": true
}, },
"include": ["./src/**/*.ts"] "include": ["./src/**/*.ts"],
"exclude": ["test", "lib", "ci", "doc"]
} }

1849
yarn.lock

File diff suppressed because it is too large Load Diff