Skip to content

Commit 3f7104b

Browse files
committed
refactor: move unit tests to test/unit
1 parent ed839c9 commit 3f7104b

22 files changed

+269
-72
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as fs from "fs-extra"
33
import * as net from "net"
44
import * as os from "os"
55
import * as path from "path"
6-
import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../src/node/cli"
7-
import { paths, tmpdir } from "../src/node/util"
6+
import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../../src/node/cli"
7+
import { paths, tmpdir } from "../../src/node/util"
88

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { commit, getPackageJson, version } from "../src/node/constants"
2-
import { loggerModule } from "./helpers"
1+
import { commit, getPackageJson, version } from "../../src/node/constants"
2+
import { loggerModule } from "../utils/helpers"
33

44
// jest.mock is hoisted above the imports so we must use `require` here.
5-
jest.mock("@coder/logger", () => require("./helpers").loggerModule)
5+
jest.mock("@coder/logger", () => require("../utils/helpers").loggerModule)
66

77
describe("constants", () => {
88
describe("getPackageJson", () => {

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

Lines changed: 2 additions & 2 deletions
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 "../../node_modules/@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/health.test.ts renamed to test/unit/health.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as httpserver from "./httpserver"
2-
import * as integration from "./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/http.test.ts renamed to test/unit/http.test.ts

Lines changed: 1 addition & 1 deletion
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/plugin.test.ts renamed to test/unit/plugin.test.ts

Lines changed: 5 additions & 5 deletions
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 "./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/proxy.test.ts renamed to test/unit/proxy.test.ts

Lines changed: 2 additions & 2 deletions
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 "./httpserver"
4-
import * as integration from "./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/register.test.ts renamed to test/unit/register.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSDOM } from "jsdom"
2-
import { loggerModule } from "./helpers"
2+
import { loggerModule } from "../utils/helpers"
33

44
describe("register", () => {
55
describe("when navigator and serviceWorker are defined", () => {
@@ -40,7 +40,7 @@ describe("register", () => {
4040

4141
it("should register a ServiceWorker", () => {
4242
// Load service worker like you would in the browser
43-
require("../src/browser/register")
43+
require("../../src/browser/register")
4444
expect(mockRegisterFn).toHaveBeenCalled()
4545
expect(mockRegisterFn).toHaveBeenCalledTimes(1)
4646
})
@@ -54,7 +54,7 @@ describe("register", () => {
5454
})
5555

5656
// Load service worker like you would in the browser
57-
require("../src/browser/register")
57+
require("../../src/browser/register")
5858

5959
expect(mockRegisterFn).toHaveBeenCalled()
6060
expect(loggerModule.logger.error).toHaveBeenCalled()
@@ -78,7 +78,7 @@ describe("register", () => {
7878

7979
it("should log an error to the console", () => {
8080
// Load service worker like you would in the browser
81-
require("../src/browser/register")
81+
require("../../src/browser/register")
8282
expect(spy).toHaveBeenCalled()
8383
expect(spy).toHaveBeenCalledTimes(1)
8484
expect(spy).toHaveBeenCalledWith("[Service Worker] navigator is undefined")

test/serviceWorker.test.ts renamed to test/unit/serviceWorker.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("serviceWorker", () => {
5858
})
5959

6060
it("should add 3 listeners: install, activate and fetch", () => {
61-
require("../src/browser/serviceWorker.ts")
61+
require("../../src/browser/serviceWorker.ts")
6262
const listenerEventNames = listeners.map((listener) => listener.event)
6363

6464
expect(listeners).toHaveLength(3)
@@ -68,20 +68,20 @@ describe("serviceWorker", () => {
6868
})
6969

7070
it("should call the proper callbacks for 'install'", async () => {
71-
require("../src/browser/serviceWorker.ts")
71+
require("../../src/browser/serviceWorker.ts")
7272
emit("install")
7373
expect(spy).toHaveBeenCalledWith("[Service Worker] installed")
7474
expect(spy).toHaveBeenCalledTimes(1)
7575
})
7676

7777
it("should do nothing when 'fetch' is called", async () => {
78-
require("../src/browser/serviceWorker.ts")
78+
require("../../src/browser/serviceWorker.ts")
7979
emit("fetch")
8080
expect(spy).not.toHaveBeenCalled()
8181
})
8282

8383
it("should call the proper callbacks for 'activate'", async () => {
84-
require("../src/browser/serviceWorker.ts")
84+
require("../../src/browser/serviceWorker.ts")
8585
emit("activate")
8686

8787
// Activate serviceWorker

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as fs from "fs-extra"
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 { SocketProxyProvider } from "../src/node/socket"
8-
import { generateCertificate, tmpdir } from "../src/node/util"
6+
import { Emitter } from "../../src/common/emitter"
7+
import { SocketProxyProvider } from "../../src/node/socket"
8+
import { generateCertificate, tmpdir } from "../../src/node/util"
99

1010
describe("SocketProxyProvider", () => {
1111
const provider = new SocketProxyProvider()

0 commit comments

Comments
 (0)