Skip to content

Commit 7e43f7d

Browse files
authored
Merge pull request #3866 from cdr/jsjoeio-reorg-test-files
refactor: clean up test file structure
2 parents 93c89ba + 7a6ec20 commit 7e43f7d

26 files changed

+43
-43
lines changed

ci/dev/test-unit.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
cd test/unit/test-plugin
6+
cd test/unit/node/test-plugin
77
make -s out/index.js
88
# We must keep jest in a sub-directory. See ../../test/package.json for more
99
# information. We must also run it from the root otherwise coverage will not

docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Our unit tests are written in TypeScript and run using
143143

144144
These live under [test/unit](../test/unit).
145145

146-
We use unit tests for functions and things that can be tested in isolation.
146+
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.
147147

148148
### Integration tests
149149

test/unit/browser/pages/login.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSDOM } from "jsdom"
2-
import { LocationLike } from "../../util.test"
2+
import { LocationLike } from "../../common/util.test"
33

44
describe("login", () => {
55
describe("there is an element with id 'base'", () => {

test/unit/browser/register.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JSDOM } from "jsdom"
22
import { registerServiceWorker } from "../../../src/browser/register"
33
import { createLoggerMock } from "../../utils/helpers"
4-
import { LocationLike } from "../util.test"
4+
import { LocationLike } from "../common/util.test"
55

66
describe("register", () => {
77
describe("when navigator and serviceWorker are defined", () => {

test/unit/emitter.test.ts renamed to test/unit/common/emitter.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Note: we need to import logger from the root
22
// because this is the logger used in logError in ../src/common/util
3-
import { logger } from "../../node_modules/@coder/logger"
3+
import { logger } from "@coder/logger"
44

5-
import { Emitter } from "../../src/common/emitter"
5+
import { Emitter } from "../../../src/common/emitter"
66

77
describe("emitter", () => {
88
let spy: jest.SpyInstance

test/unit/http.test.ts renamed to test/unit/common/http.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpCode, HttpError } from "../../src/common/http"
1+
import { HttpCode, HttpError } from "../../../src/common/http"
22

33
describe("http", () => {
44
describe("HttpCode", () => {

test/unit/util.test.ts renamed to test/unit/common/util.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from "jsdom"
2-
import * as util from "../../src/common/util"
3-
import { createLoggerMock } from "../utils/helpers"
2+
import * as util from "../../../src/common/util"
3+
import { createLoggerMock } from "../../utils/helpers"
44

55
const dom = new JSDOM()
66
global.document = dom.window.document

test/unit/cli.test.ts renamed to test/unit/node/cli.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { promises as fs } from "fs"
33
import * as net from "net"
44
import * as os from "os"
55
import * as path from "path"
6-
import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../src/node/cli"
7-
import { tmpdir } from "../../src/node/constants"
8-
import { paths } from "../../src/node/util"
6+
import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../../src/node/cli"
7+
import { tmpdir } from "../../../src/node/constants"
8+
import { paths } from "../../../src/node/util"
99

1010
type Mutable<T> = {
1111
-readonly [P in keyof T]: T[P]

test/unit/constants.test.ts renamed to test/unit/node/constants.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createLoggerMock } from "../utils/helpers"
1+
import { createLoggerMock } from "../../utils/helpers"
22

33
describe("constants", () => {
4-
let constants: typeof import("../../src/node/constants")
4+
let constants: typeof import("../../../src/node/constants")
55

66
describe("with package.json defined", () => {
77
const loggerModule = createLoggerMock()
@@ -15,8 +15,8 @@ describe("constants", () => {
1515

1616
beforeAll(() => {
1717
jest.mock("@coder/logger", () => loggerModule)
18-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
19-
constants = require("../../src/node/constants")
18+
jest.mock("../../../package.json", () => mockPackageJson, { virtual: true })
19+
constants = require("../../../src/node/constants")
2020
})
2121

2222
afterAll(() => {
@@ -57,8 +57,8 @@ describe("constants", () => {
5757
}
5858

5959
beforeAll(() => {
60-
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
61-
constants = require("../../src/node/constants")
60+
jest.mock("../../../package.json", () => mockPackageJson, { virtual: true })
61+
constants = require("../../../src/node/constants")
6262
})
6363

6464
afterAll(() => {

test/unit/plugin.test.ts renamed to test/unit/node/plugin.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { logger } from "@coder/logger"
22
import * as express from "express"
33
import * as fs from "fs"
44
import * as path from "path"
5-
import { HttpCode } from "../../src/common/http"
6-
import { AuthType } from "../../src/node/cli"
7-
import { codeServer, PluginAPI } from "../../src/node/plugin"
8-
import * as apps from "../../src/node/routes/apps"
9-
import * as httpserver from "../utils/httpserver"
5+
import { HttpCode } from "../../../src/common/http"
6+
import { AuthType } from "../../../src/node/cli"
7+
import { codeServer, PluginAPI } from "../../../src/node/plugin"
8+
import * as apps from "../../../src/node/routes/apps"
9+
import * as httpserver from "../../utils/httpserver"
1010
const fsp = fs.promises
1111

1212
// Jest overrides `require` so our usual override doesn't work.

test/unit/proxy.test.ts renamed to test/unit/node/proxy.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bodyParser from "body-parser"
22
import * as express from "express"
3-
import * as httpserver from "../utils/httpserver"
4-
import * as integration from "../utils/integration"
3+
import * as httpserver from "../../utils/httpserver"
4+
import * as integration from "../../utils/integration"
55

66
describe("proxy", () => {
77
const nhooyrDevServer = new httpserver.HttpServer()

test/unit/routes/health.test.ts renamed to test/unit/node/routes/health.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as httpserver from "../../utils/httpserver"
2-
import * as integration from "../../utils/integration"
1+
import * as httpserver from "../../../utils/httpserver"
2+
import * as integration from "../../../utils/integration"
33

44
describe("health", () => {
55
let codeServer: httpserver.HttpServer | undefined

test/unit/routes/login.test.ts renamed to test/unit/node/routes/login.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { RateLimiter } from "../../../src/node/routes/login"
2-
import * as httpserver from "../../utils/httpserver"
3-
import * as integration from "../../utils/integration"
1+
import { RateLimiter } from "../../../../src/node/routes/login"
2+
import * as httpserver from "../../../utils/httpserver"
3+
import * as integration from "../../../utils/integration"
44

55
describe("login", () => {
66
describe("RateLimiter", () => {

test/unit/routes/static.test.ts renamed to test/unit/node/routes/static.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { promises as fs } from "fs"
22
import * as path from "path"
3-
import { tmpdir } from "../../utils/helpers"
4-
import * as httpserver from "../../utils/httpserver"
5-
import * as integration from "../../utils/integration"
3+
import { tmpdir } from "../../../utils/helpers"
4+
import * as httpserver from "../../../utils/httpserver"
5+
import * as integration from "../../../utils/integration"
66

77
describe("/static", () => {
88
let _codeServer: httpserver.HttpServer | undefined

test/unit/socket.test.ts renamed to test/unit/node/socket.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { promises as fs } from "fs"
33
import * as net from "net"
44
import * as path from "path"
55
import * as tls from "tls"
6-
import { Emitter } from "../../src/common/emitter"
7-
import { tmpdir } from "../../src/node/constants"
8-
import { SocketProxyProvider } from "../../src/node/socket"
9-
import { generateCertificate } from "../../src/node/util"
6+
import { Emitter } from "../../../src/common/emitter"
7+
import { tmpdir } from "../../../src/node/constants"
8+
import { SocketProxyProvider } from "../../../src/node/socket"
9+
import { generateCertificate } from "../../../src/node/util"
1010

1111
describe("SocketProxyProvider", () => {
1212
const provider = new SocketProxyProvider()
File renamed without changes.

test/unit/test-plugin/tsconfig.json renamed to test/unit/node/test-plugin/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
4545
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
4646
"paths": {
47-
"code-server": ["../../../typings/pluginapi"]
47+
"code-server": ["../../../../typings/pluginapi"]
4848
} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
4949
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
5050
// "typeRoots": [], /* List of folders to include type definitions from. */

test/unit/update.test.ts renamed to test/unit/node/update.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { promises as fs } from "fs"
22
import * as http from "http"
33
import * as path from "path"
4-
import { tmpdir } from "../../src/node/constants"
5-
import { SettingsProvider, UpdateSettings } from "../../src/node/settings"
6-
import { LatestResponse, UpdateProvider } from "../../src/node/update"
4+
import { tmpdir } from "../../../src/node/constants"
5+
import { SettingsProvider, UpdateSettings } from "../../../src/node/settings"
6+
import { LatestResponse, UpdateProvider } from "../../../src/node/update"
77

88
describe("update", () => {
99
let version = "1.0.0"

test/unit/node/util.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as cp from "child_process"
2-
import * as path from "path"
32
import { promises as fs } from "fs"
3+
import * as path from "path"
44
import { generateUuid } from "../../../src/common/util"
5-
import * as util from "../../../src/node/util"
65
import { tmpdir } from "../../../src/node/constants"
6+
import * as util from "../../../src/node/util"
77

88
describe("getEnvPaths", () => {
99
describe("on darwin", () => {

0 commit comments

Comments
 (0)