Merge pull request #3866 from cdr/jsjoeio-reorg-test-files
refactor: clean up test file structure
This commit is contained in:
commit
7e43f7d6b0
@ -3,7 +3,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$(dirname "$0")/../.."
|
cd "$(dirname "$0")/../.."
|
||||||
cd test/unit/test-plugin
|
cd test/unit/node/test-plugin
|
||||||
make -s out/index.js
|
make -s out/index.js
|
||||||
# We must keep jest in a sub-directory. See ../../test/package.json for more
|
# 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
|
# information. We must also run it from the root otherwise coverage will not
|
||||||
|
@ -143,7 +143,7 @@ Our unit tests are written in TypeScript and run using
|
|||||||
|
|
||||||
These live under [test/unit](../test/unit).
|
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
|
### Integration tests
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { JSDOM } from "jsdom"
|
import { JSDOM } from "jsdom"
|
||||||
import { LocationLike } from "../../util.test"
|
import { LocationLike } from "../../common/util.test"
|
||||||
|
|
||||||
describe("login", () => {
|
describe("login", () => {
|
||||||
describe("there is an element with id 'base'", () => {
|
describe("there is an element with id 'base'", () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { JSDOM } from "jsdom"
|
import { JSDOM } from "jsdom"
|
||||||
import { registerServiceWorker } from "../../../src/browser/register"
|
import { registerServiceWorker } from "../../../src/browser/register"
|
||||||
import { createLoggerMock } from "../../utils/helpers"
|
import { createLoggerMock } from "../../utils/helpers"
|
||||||
import { LocationLike } from "../util.test"
|
import { LocationLike } from "../common/util.test"
|
||||||
|
|
||||||
describe("register", () => {
|
describe("register", () => {
|
||||||
describe("when navigator and serviceWorker are defined", () => {
|
describe("when navigator and serviceWorker are defined", () => {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// Note: we need to import logger from the root
|
// Note: we need to import logger from the root
|
||||||
// because this is the logger used in logError in ../src/common/util
|
// 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", () => {
|
describe("emitter", () => {
|
||||||
let spy: jest.SpyInstance
|
let spy: jest.SpyInstance
|
@ -1,4 +1,4 @@
|
|||||||
import { HttpCode, HttpError } from "../../src/common/http"
|
import { HttpCode, HttpError } from "../../../src/common/http"
|
||||||
|
|
||||||
describe("http", () => {
|
describe("http", () => {
|
||||||
describe("HttpCode", () => {
|
describe("HttpCode", () => {
|
@ -1,6 +1,6 @@
|
|||||||
import { JSDOM } from "jsdom"
|
import { JSDOM } from "jsdom"
|
||||||
import * as util from "../../src/common/util"
|
import * as util from "../../../src/common/util"
|
||||||
import { createLoggerMock } from "../utils/helpers"
|
import { createLoggerMock } from "../../utils/helpers"
|
||||||
|
|
||||||
const dom = new JSDOM()
|
const dom = new JSDOM()
|
||||||
global.document = dom.window.document
|
global.document = dom.window.document
|
@ -3,9 +3,9 @@ import { promises as fs } from "fs"
|
|||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import * as os from "os"
|
import * as os from "os"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../src/node/cli"
|
import { Args, parse, setDefaults, shouldOpenInExistingInstance, splitOnFirstEquals } from "../../../src/node/cli"
|
||||||
import { tmpdir } from "../../src/node/constants"
|
import { tmpdir } from "../../../src/node/constants"
|
||||||
import { paths } from "../../src/node/util"
|
import { paths } from "../../../src/node/util"
|
||||||
|
|
||||||
type Mutable<T> = {
|
type Mutable<T> = {
|
||||||
-readonly [P in keyof T]: T[P]
|
-readonly [P in keyof T]: T[P]
|
@ -1,7 +1,7 @@
|
|||||||
import { createLoggerMock } from "../utils/helpers"
|
import { createLoggerMock } from "../../utils/helpers"
|
||||||
|
|
||||||
describe("constants", () => {
|
describe("constants", () => {
|
||||||
let constants: typeof import("../../src/node/constants")
|
let constants: typeof import("../../../src/node/constants")
|
||||||
|
|
||||||
describe("with package.json defined", () => {
|
describe("with package.json defined", () => {
|
||||||
const loggerModule = createLoggerMock()
|
const loggerModule = createLoggerMock()
|
||||||
@ -15,8 +15,8 @@ describe("constants", () => {
|
|||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.mock("@coder/logger", () => loggerModule)
|
jest.mock("@coder/logger", () => loggerModule)
|
||||||
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
|
jest.mock("../../../package.json", () => mockPackageJson, { virtual: true })
|
||||||
constants = require("../../src/node/constants")
|
constants = require("../../../src/node/constants")
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
@ -57,8 +57,8 @@ describe("constants", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.mock("../../package.json", () => mockPackageJson, { virtual: true })
|
jest.mock("../../../package.json", () => mockPackageJson, { virtual: true })
|
||||||
constants = require("../../src/node/constants")
|
constants = require("../../../src/node/constants")
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
@ -2,11 +2,11 @@ import { logger } from "@coder/logger"
|
|||||||
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"
|
||||||
import { HttpCode } from "../../src/common/http"
|
import { HttpCode } from "../../../src/common/http"
|
||||||
import { AuthType } from "../../src/node/cli"
|
import { AuthType } from "../../../src/node/cli"
|
||||||
import { codeServer, PluginAPI } from "../../src/node/plugin"
|
import { codeServer, PluginAPI } from "../../../src/node/plugin"
|
||||||
import * as apps from "../../src/node/routes/apps"
|
import * as apps from "../../../src/node/routes/apps"
|
||||||
import * as httpserver from "../utils/httpserver"
|
import * as httpserver from "../../utils/httpserver"
|
||||||
const fsp = fs.promises
|
const fsp = fs.promises
|
||||||
|
|
||||||
// Jest overrides `require` so our usual override doesn't work.
|
// Jest overrides `require` so our usual override doesn't work.
|
@ -1,7 +1,7 @@
|
|||||||
import bodyParser from "body-parser"
|
import bodyParser from "body-parser"
|
||||||
import * as express from "express"
|
import * as express from "express"
|
||||||
import * as httpserver from "../utils/httpserver"
|
import * as httpserver from "../../utils/httpserver"
|
||||||
import * as integration from "../utils/integration"
|
import * as integration from "../../utils/integration"
|
||||||
|
|
||||||
describe("proxy", () => {
|
describe("proxy", () => {
|
||||||
const nhooyrDevServer = new httpserver.HttpServer()
|
const nhooyrDevServer = new httpserver.HttpServer()
|
@ -1,5 +1,5 @@
|
|||||||
import * as httpserver from "../../utils/httpserver"
|
import * as httpserver from "../../../utils/httpserver"
|
||||||
import * as integration from "../../utils/integration"
|
import * as integration from "../../../utils/integration"
|
||||||
|
|
||||||
describe("health", () => {
|
describe("health", () => {
|
||||||
let codeServer: httpserver.HttpServer | undefined
|
let codeServer: httpserver.HttpServer | undefined
|
@ -1,6 +1,6 @@
|
|||||||
import { RateLimiter } from "../../../src/node/routes/login"
|
import { RateLimiter } from "../../../../src/node/routes/login"
|
||||||
import * as httpserver from "../../utils/httpserver"
|
import * as httpserver from "../../../utils/httpserver"
|
||||||
import * as integration from "../../utils/integration"
|
import * as integration from "../../../utils/integration"
|
||||||
|
|
||||||
describe("login", () => {
|
describe("login", () => {
|
||||||
describe("RateLimiter", () => {
|
describe("RateLimiter", () => {
|
@ -1,8 +1,8 @@
|
|||||||
import { promises as fs } from "fs"
|
import { promises as fs } from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { tmpdir } from "../../utils/helpers"
|
import { tmpdir } from "../../../utils/helpers"
|
||||||
import * as httpserver from "../../utils/httpserver"
|
import * as httpserver from "../../../utils/httpserver"
|
||||||
import * as integration from "../../utils/integration"
|
import * as integration from "../../../utils/integration"
|
||||||
|
|
||||||
describe("/static", () => {
|
describe("/static", () => {
|
||||||
let _codeServer: httpserver.HttpServer | undefined
|
let _codeServer: httpserver.HttpServer | undefined
|
@ -3,10 +3,10 @@ import { promises as fs } from "fs"
|
|||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import * as tls from "tls"
|
import * as tls from "tls"
|
||||||
import { Emitter } from "../../src/common/emitter"
|
import { Emitter } from "../../../src/common/emitter"
|
||||||
import { tmpdir } from "../../src/node/constants"
|
import { tmpdir } from "../../../src/node/constants"
|
||||||
import { SocketProxyProvider } from "../../src/node/socket"
|
import { SocketProxyProvider } from "../../../src/node/socket"
|
||||||
import { generateCertificate } from "../../src/node/util"
|
import { generateCertificate } from "../../../src/node/util"
|
||||||
|
|
||||||
describe("SocketProxyProvider", () => {
|
describe("SocketProxyProvider", () => {
|
||||||
const provider = new SocketProxyProvider()
|
const provider = new SocketProxyProvider()
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
@ -44,7 +44,7 @@
|
|||||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
|
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
|
||||||
"paths": {
|
"paths": {
|
||||||
"code-server": ["../../../typings/pluginapi"]
|
"code-server": ["../../../../typings/pluginapi"]
|
||||||
} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
|
} /* 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. */
|
// "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. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
@ -1,9 +1,9 @@
|
|||||||
import { promises as fs } from "fs"
|
import { promises as fs } from "fs"
|
||||||
import * as http from "http"
|
import * as http from "http"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { tmpdir } from "../../src/node/constants"
|
import { tmpdir } from "../../../src/node/constants"
|
||||||
import { SettingsProvider, UpdateSettings } from "../../src/node/settings"
|
import { SettingsProvider, UpdateSettings } from "../../../src/node/settings"
|
||||||
import { LatestResponse, UpdateProvider } from "../../src/node/update"
|
import { LatestResponse, UpdateProvider } from "../../../src/node/update"
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
let version = "1.0.0"
|
let version = "1.0.0"
|
@ -1,9 +1,9 @@
|
|||||||
import * as cp from "child_process"
|
import * as cp from "child_process"
|
||||||
import * as path from "path"
|
|
||||||
import { promises as fs } from "fs"
|
import { promises as fs } from "fs"
|
||||||
|
import * as path from "path"
|
||||||
import { generateUuid } from "../../../src/common/util"
|
import { generateUuid } from "../../../src/common/util"
|
||||||
import * as util from "../../../src/node/util"
|
|
||||||
import { tmpdir } from "../../../src/node/constants"
|
import { tmpdir } from "../../../src/node/constants"
|
||||||
|
import * as util from "../../../src/node/util"
|
||||||
|
|
||||||
describe("getEnvPaths", () => {
|
describe("getEnvPaths", () => {
|
||||||
describe("on darwin", () => {
|
describe("on darwin", () => {
|
||||||
|
Reference in New Issue
Block a user