diff --git a/ci/dev/test-unit.sh b/ci/dev/test-unit.sh index f2e76ee5..65fa9400 100755 --- a/ci/dev/test-unit.sh +++ b/ci/dev/test-unit.sh @@ -3,7 +3,7 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." - cd test/unit/test-plugin + cd test/unit/node/test-plugin make -s out/index.js # We must keep jest in a sub-directory. See ../../test/package.json for more # information. We must also run it from the root otherwise coverage will not diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 1863dcb2..32c9e777 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -143,7 +143,7 @@ Our unit tests are written in TypeScript and run using These live under [test/unit](../test/unit). -We use unit tests for functions and things that can be tested in isolation. +We use unit tests for functions and things that can be tested in isolation. The file structure is modeled closely after `/src` so it's easy for people to know where test files should live. ### Integration tests diff --git a/test/unit/browser/pages/login.test.ts b/test/unit/browser/pages/login.test.ts index d8efea06..92d4d117 100644 --- a/test/unit/browser/pages/login.test.ts +++ b/test/unit/browser/pages/login.test.ts @@ -1,5 +1,5 @@ import { JSDOM } from "jsdom" -import { LocationLike } from "../../util.test" +import { LocationLike } from "../../common/util.test" describe("login", () => { describe("there is an element with id 'base'", () => { diff --git a/test/unit/browser/register.test.ts b/test/unit/browser/register.test.ts index f2302cb8..1c213196 100644 --- a/test/unit/browser/register.test.ts +++ b/test/unit/browser/register.test.ts @@ -1,7 +1,7 @@ import { JSDOM } from "jsdom" import { registerServiceWorker } from "../../../src/browser/register" import { createLoggerMock } from "../../utils/helpers" -import { LocationLike } from "../util.test" +import { LocationLike } from "../common/util.test" describe("register", () => { describe("when navigator and serviceWorker are defined", () => { diff --git a/test/unit/emitter.test.ts b/test/unit/common/emitter.test.ts similarity index 95% rename from test/unit/emitter.test.ts rename to test/unit/common/emitter.test.ts index c9d24d57..46a5dddd 100644 --- a/test/unit/emitter.test.ts +++ b/test/unit/common/emitter.test.ts @@ -1,8 +1,8 @@ // Note: we need to import logger from the root // because this is the logger used in logError in ../src/common/util -import { logger } from "../../node_modules/@coder/logger" +import { logger } from "@coder/logger" -import { Emitter } from "../../src/common/emitter" +import { Emitter } from "../../../src/common/emitter" describe("emitter", () => { let spy: jest.SpyInstance diff --git a/test/unit/http.test.ts b/test/unit/common/http.test.ts similarity index 94% rename from test/unit/http.test.ts rename to test/unit/common/http.test.ts index 5275adc8..fd49ae18 100644 --- a/test/unit/http.test.ts +++ b/test/unit/common/http.test.ts @@ -1,4 +1,4 @@ -import { HttpCode, HttpError } from "../../src/common/http" +import { HttpCode, HttpError } from "../../../src/common/http" describe("http", () => { describe("HttpCode", () => { diff --git a/test/unit/util.test.ts b/test/unit/common/util.test.ts similarity index 98% rename from test/unit/util.test.ts rename to test/unit/common/util.test.ts index daf0d876..85422aa8 100644 --- a/test/unit/util.test.ts +++ b/test/unit/common/util.test.ts @@ -1,6 +1,6 @@ import { JSDOM } from "jsdom" -import * as util from "../../src/common/util" -import { createLoggerMock } from "../utils/helpers" +import * as util from "../../../src/common/util" +import { createLoggerMock } from "../../utils/helpers" const dom = new JSDOM() global.document = dom.window.document diff --git a/test/unit/cli.test.ts b/test/unit/node/cli.test.ts similarity index 98% rename from test/unit/cli.test.ts rename to test/unit/node/cli.test.ts index 2d6e252a..93a86776 100644 --- a/test/unit/cli.test.ts +++ b/test/unit/node/cli.test.ts @@ -3,9 +3,9 @@ import { promises as fs } from "fs" import * as net from "net" import * as os from "os" import * as path from "path" -import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../src/node/cli" -import { tmpdir } from "../../src/node/constants" -import { paths } from "../../src/node/util" +import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../../src/node/cli" +import { tmpdir } from "../../../src/node/constants" +import { paths } from "../../../src/node/util" type Mutable = { -readonly [P in keyof T]: T[P] diff --git a/test/unit/constants.test.ts b/test/unit/node/constants.test.ts similarity index 83% rename from test/unit/constants.test.ts rename to test/unit/node/constants.test.ts index fe9c26d2..5b9a8d87 100644 --- a/test/unit/constants.test.ts +++ b/test/unit/node/constants.test.ts @@ -1,7 +1,7 @@ -import { createLoggerMock } from "../utils/helpers" +import { createLoggerMock } from "../../utils/helpers" describe("constants", () => { - let constants: typeof import("../../src/node/constants") + let constants: typeof import("../../../src/node/constants") describe("with package.json defined", () => { const loggerModule = createLoggerMock() @@ -15,8 +15,8 @@ describe("constants", () => { beforeAll(() => { jest.mock("@coder/logger", () => loggerModule) - jest.mock("../../package.json", () => mockPackageJson, { virtual: true }) - constants = require("../../src/node/constants") + jest.mock("../../../package.json", () => mockPackageJson, { virtual: true }) + constants = require("../../../src/node/constants") }) afterAll(() => { @@ -57,8 +57,8 @@ describe("constants", () => { } beforeAll(() => { - jest.mock("../../package.json", () => mockPackageJson, { virtual: true }) - constants = require("../../src/node/constants") + jest.mock("../../../package.json", () => mockPackageJson, { virtual: true }) + constants = require("../../../src/node/constants") }) afterAll(() => { diff --git a/test/unit/plugin.test.ts b/test/unit/node/plugin.test.ts similarity index 91% rename from test/unit/plugin.test.ts rename to test/unit/node/plugin.test.ts index 7df360df..5459db2c 100644 --- a/test/unit/plugin.test.ts +++ b/test/unit/node/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/proxy.test.ts b/test/unit/node/proxy.test.ts similarity index 96% rename from test/unit/proxy.test.ts rename to test/unit/node/proxy.test.ts index a9c1554e..febc8a6d 100644 --- a/test/unit/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -1,7 +1,7 @@ import bodyParser from "body-parser" import * as express from "express" -import * as httpserver from "../utils/httpserver" -import * as integration from "../utils/integration" +import * as httpserver from "../../utils/httpserver" +import * as integration from "../../utils/integration" describe("proxy", () => { const nhooyrDevServer = new httpserver.HttpServer() diff --git a/test/unit/routes/health.test.ts b/test/unit/node/routes/health.test.ts similarity index 90% rename from test/unit/routes/health.test.ts rename to test/unit/node/routes/health.test.ts index 81472ced..4b950b40 100644 --- a/test/unit/routes/health.test.ts +++ b/test/unit/node/routes/health.test.ts @@ -1,5 +1,5 @@ -import * as httpserver from "../../utils/httpserver" -import * as integration from "../../utils/integration" +import * as httpserver from "../../../utils/httpserver" +import * as integration from "../../../utils/integration" describe("health", () => { let codeServer: httpserver.HttpServer | undefined diff --git a/test/unit/routes/login.test.ts b/test/unit/node/routes/login.test.ts similarity index 92% rename from test/unit/routes/login.test.ts rename to test/unit/node/routes/login.test.ts index ba4fcac8..038461b4 100644 --- a/test/unit/routes/login.test.ts +++ b/test/unit/node/routes/login.test.ts @@ -1,6 +1,6 @@ -import { RateLimiter } from "../../../src/node/routes/login" -import * as httpserver from "../../utils/httpserver" -import * as integration from "../../utils/integration" +import { RateLimiter } from "../../../../src/node/routes/login" +import * as httpserver from "../../../utils/httpserver" +import * as integration from "../../../utils/integration" describe("login", () => { describe("RateLimiter", () => { diff --git a/test/unit/routes/static.test.ts b/test/unit/node/routes/static.test.ts similarity index 96% rename from test/unit/routes/static.test.ts rename to test/unit/node/routes/static.test.ts index 13897626..cca66ffc 100644 --- a/test/unit/routes/static.test.ts +++ b/test/unit/node/routes/static.test.ts @@ -1,8 +1,8 @@ import { promises as fs } from "fs" import * as path from "path" -import { tmpdir } from "../../utils/helpers" -import * as httpserver from "../../utils/httpserver" -import * as integration from "../../utils/integration" +import { tmpdir } from "../../../utils/helpers" +import * as httpserver from "../../../utils/httpserver" +import * as integration from "../../../utils/integration" describe("/static", () => { let _codeServer: httpserver.HttpServer | undefined diff --git a/test/unit/socket.test.ts b/test/unit/node/socket.test.ts similarity index 95% rename from test/unit/socket.test.ts rename to test/unit/node/socket.test.ts index 9b8749f5..b7969657 100644 --- a/test/unit/socket.test.ts +++ b/test/unit/node/socket.test.ts @@ -3,10 +3,10 @@ import { promises as fs } from "fs" import * as net from "net" import * as path from "path" import * as tls from "tls" -import { Emitter } from "../../src/common/emitter" -import { tmpdir } from "../../src/node/constants" -import { SocketProxyProvider } from "../../src/node/socket" -import { generateCertificate } from "../../src/node/util" +import { Emitter } from "../../../src/common/emitter" +import { tmpdir } from "../../../src/node/constants" +import { SocketProxyProvider } from "../../../src/node/socket" +import { generateCertificate } from "../../../src/node/util" describe("SocketProxyProvider", () => { const provider = new SocketProxyProvider() diff --git a/test/unit/test-plugin/.eslintrc.yaml b/test/unit/node/test-plugin/.eslintrc.yaml similarity index 100% rename from test/unit/test-plugin/.eslintrc.yaml rename to test/unit/node/test-plugin/.eslintrc.yaml diff --git a/test/unit/test-plugin/.gitignore b/test/unit/node/test-plugin/.gitignore similarity index 100% rename from test/unit/test-plugin/.gitignore rename to test/unit/node/test-plugin/.gitignore diff --git a/test/unit/test-plugin/Makefile b/test/unit/node/test-plugin/Makefile similarity index 100% rename from test/unit/test-plugin/Makefile rename to test/unit/node/test-plugin/Makefile diff --git a/test/unit/test-plugin/package.json b/test/unit/node/test-plugin/package.json similarity index 100% rename from test/unit/test-plugin/package.json rename to test/unit/node/test-plugin/package.json diff --git a/test/unit/test-plugin/public/icon.svg b/test/unit/node/test-plugin/public/icon.svg similarity index 100% rename from test/unit/test-plugin/public/icon.svg rename to test/unit/node/test-plugin/public/icon.svg diff --git a/test/unit/test-plugin/public/index.html b/test/unit/node/test-plugin/public/index.html similarity index 100% rename from test/unit/test-plugin/public/index.html rename to test/unit/node/test-plugin/public/index.html diff --git a/test/unit/test-plugin/src/index.ts b/test/unit/node/test-plugin/src/index.ts similarity index 100% rename from test/unit/test-plugin/src/index.ts rename to test/unit/node/test-plugin/src/index.ts diff --git a/test/unit/test-plugin/tsconfig.json b/test/unit/node/test-plugin/tsconfig.json similarity index 99% rename from test/unit/test-plugin/tsconfig.json rename to test/unit/node/test-plugin/tsconfig.json index bb30a1ad..194af141 100644 --- a/test/unit/test-plugin/tsconfig.json +++ b/test/unit/node/test-plugin/tsconfig.json @@ -44,7 +44,7 @@ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ "baseUrl": "./" /* Base directory to resolve non-absolute module names. */, "paths": { - "code-server": ["../../../typings/pluginapi"] + "code-server": ["../../../../typings/pluginapi"] } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */, // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ diff --git a/test/unit/test-plugin/yarn.lock b/test/unit/node/test-plugin/yarn.lock similarity index 100% rename from test/unit/test-plugin/yarn.lock rename to test/unit/node/test-plugin/yarn.lock diff --git a/test/unit/update.test.ts b/test/unit/node/update.test.ts similarity index 95% rename from test/unit/update.test.ts rename to test/unit/node/update.test.ts index e76c87d3..c76c9c7b 100644 --- a/test/unit/update.test.ts +++ b/test/unit/node/update.test.ts @@ -1,9 +1,9 @@ import { promises as fs } from "fs" import * as http from "http" import * as path from "path" -import { tmpdir } from "../../src/node/constants" -import { SettingsProvider, UpdateSettings } from "../../src/node/settings" -import { LatestResponse, UpdateProvider } from "../../src/node/update" +import { tmpdir } from "../../../src/node/constants" +import { SettingsProvider, UpdateSettings } from "../../../src/node/settings" +import { LatestResponse, UpdateProvider } from "../../../src/node/update" describe("update", () => { let version = "1.0.0" diff --git a/test/unit/node/util.test.ts b/test/unit/node/util.test.ts index 7945b696..d7e6cf87 100644 --- a/test/unit/node/util.test.ts +++ b/test/unit/node/util.test.ts @@ -1,9 +1,9 @@ import * as cp from "child_process" -import * as path from "path" import { promises as fs } from "fs" +import * as path from "path" import { generateUuid } from "../../../src/common/util" -import * as util from "../../../src/node/util" import { tmpdir } from "../../../src/node/constants" +import * as util from "../../../src/node/util" describe("getEnvPaths", () => { describe("on darwin", () => {