未验证 提交 883dd138 编写于 作者: J Joe Previte

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

上级 646ee3ad
......@@ -6,8 +6,9 @@ main() {
cd test/test-plugin
make -s out/index.js
cd "$OLDPWD"
yarn jest "$@"
cd "$OLDPWD/test"
yarn
yarn test "$@"
}
main "$@"
......@@ -15,8 +15,7 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"newLine": "lf",
"skipLibCheck": true
"newLine": "lf"
},
"include": [
"**/*.ts"
......
......@@ -6,6 +6,6 @@
import * as vscode from 'vscode';
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;
}
{
"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"
}
}
import { logger } from "@coder/logger"
import * as assert from "assert"
import * as express from "express"
import * as fs from "fs"
import * as path from "path"
......@@ -15,7 +14,7 @@ describe("plugin", () => {
let papi: PluginAPI
let s: httpserver.HttpServer
before(async () => {
beforeAll(async () => {
papi = new PluginAPI(logger, `${path.resolve(__dirname, "test-plugin")}:meow`)
await papi.loadPlugins()
......@@ -27,16 +26,16 @@ describe("plugin", () => {
await s.listen(app)
})
after(async () => {
afterAll(async () => {
await s.close()
})
it("/api/applications", async () => {
const resp = await s.fetch("/api/applications")
assert.equal(200, resp.status)
expect(resp.status).toBe(200)
const body = await resp.json()
logger.debug(`${JSON.stringify(body)}`)
assert.deepEqual(body, [
expect(body).toStrictEqual([
{
name: "Test App",
version: "4.0.0",
......@@ -65,8 +64,8 @@ describe("plugin", () => {
encoding: "utf8",
})
const resp = await s.fetch("/test-plugin/test-app")
assert.equal(200, resp.status)
expect(resp.status).toBe(200)
const body = await resp.text()
assert.equal(body, indexHTML)
expect(body).toBe(indexHTML)
})
})
import * as assert from "assert"
import * as express from "express"
import * as httpserver from "./httpserver"
import * as integration from "./integration"
......@@ -8,7 +7,7 @@ describe("proxy", () => {
const nhooyrDevServer = new httpserver.HttpServer()
let proxyPath: string
before(async () => {
beforeAll(async () => {
const e = express.default()
await nhooyrDevServer.listen(e)
e.get("/wsup", (req, res) => {
......@@ -20,7 +19,7 @@ describe("proxy", () => {
})
})
after(async () => {
afterAll(async () => {
await nhooyrDevServer.close()
})
......@@ -34,14 +33,16 @@ describe("proxy", () => {
it("should rewrite the base path", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath)
assert.equal(resp.status, 200)
assert.equal(await resp.json(), "asher is the best")
expect(resp.status).toBe(200)
const json = await resp.json()
expect(json).toBe("asher is the best")
})
it("should not rewrite the base path", async () => {
;[, , codeServer] = await integration.setup(["--auth=none", "--proxy-path-passthrough=true"], "")
const resp = await codeServer.fetch(proxyPath)
assert.equal(resp.status, 200)
assert.equal(await resp.json(), "joe is the best")
expect(resp.status).toBe(200)
const json = await resp.json()
expect(json).toBe("joe is the best")
})
})
{
"extends": "../tsconfig.json",
"include": ["./**/*.ts"]
"compilerOptions": {
"typeRoots": ["node_modules/@types", "../typings"],
"composite": true
},
"include": ["./**/*.ts"],
"exclude": ["node_modules/**"],
"types": ["jest"]
}
此差异已折叠。
......@@ -15,9 +15,9 @@
"sourceMap": true,
"tsBuildInfoFile": "./.cache/tsbuildinfo",
"incremental": true,
"rootDir": "./src",
"typeRoots": ["./node_modules/@types", "./typings"],
"downlevelIteration": true
},
"include": ["./src/**/*.ts"]
"include": ["./src/**/*.ts"],
"exclude": ["test", "lib", "ci", "doc"]
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册