1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 04:35:25 +00:00

refactor: clean up testing files

This commit is contained in:
Joe Previte 2021-07-12 16:54:19 -07:00
parent a5cf01840a
commit fc16f7e06d
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
5 changed files with 15 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import { JSDOM } from "jsdom" import { JSDOM } from "jsdom"
import { LocationLike } from "../../unit/util.test" import { LocationLike } from "../../util.test"
describe("login", () => { describe("login", () => {
describe("there is an element with id 'base'", () => { describe("there is an element with id 'base'", () => {
@ -36,7 +36,7 @@ describe("login", () => {
document.body.appendChild(mockElement) document.body.appendChild(mockElement)
spy.mockImplementation(() => mockElement) spy.mockImplementation(() => mockElement)
// Load file // Load file
require("../../../src/browser/pages/login") require("../../../../src/browser/pages/login")
const el: HTMLInputElement | null = document.querySelector("input#base") const el: HTMLInputElement | null = document.querySelector("input#base")
expect(el?.value).toBe("/hello-world") expect(el?.value).toBe("/hello-world")
@ -80,7 +80,7 @@ describe("login", () => {
it("should do nothing", () => { it("should do nothing", () => {
spy.mockImplementation(() => null) spy.mockImplementation(() => null)
// Load file // Load file
require("../../../src/browser/pages/login") require("../../../../src/browser/pages/login")
// It's called once by getOptions in the top of the file // It's called once by getOptions in the top of the file
// and then another to get the base element // and then another to get the base element

View File

@ -6,7 +6,7 @@ import {
getNlsConfiguration, getNlsConfiguration,
nlsConfigElementId, nlsConfigElementId,
setBodyBackgroundToThemeBackgroundColor, setBodyBackgroundToThemeBackgroundColor,
} from "../../../src/browser/pages/vscode" } from "../../../../src/browser/pages/vscode"
describe("vscode", () => { describe("vscode", () => {
describe("getNlsConfiguration", () => { describe("getNlsConfiguration", () => {

View File

@ -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 "../util.test"
describe("register", () => { describe("register", () => {
describe("when navigator and serviceWorker are defined", () => { describe("when navigator and serviceWorker are defined", () => {
@ -50,7 +50,7 @@ describe("register", () => {
it("should register a ServiceWorker", () => { it("should register a ServiceWorker", () => {
// Load service worker like you would in the browser // Load service worker like you would in the browser
require("../../src/browser/register") require("../../../src/browser/register")
expect(mockRegisterFn).toHaveBeenCalled() expect(mockRegisterFn).toHaveBeenCalled()
expect(mockRegisterFn).toHaveBeenCalledTimes(1) expect(mockRegisterFn).toHaveBeenCalledTimes(1)
}) })
@ -64,7 +64,7 @@ describe("register", () => {
}) })
// Load service worker like you would in the browser // Load service worker like you would in the browser
require("../../src/browser/register") require("../../../src/browser/register")
expect(mockRegisterFn).toHaveBeenCalled() expect(mockRegisterFn).toHaveBeenCalled()
expect(loggerModule.logger.error).toHaveBeenCalled() expect(loggerModule.logger.error).toHaveBeenCalled()
@ -88,7 +88,7 @@ describe("register", () => {
it("should log an error", () => { it("should log an error", () => {
// Load service worker like you would in the browser // Load service worker like you would in the browser
require("../../src/browser/register") require("../../../src/browser/register")
expect(loggerModule.logger.error).toHaveBeenCalled() expect(loggerModule.logger.error).toHaveBeenCalled()
expect(loggerModule.logger.error).toHaveBeenCalledTimes(1) expect(loggerModule.logger.error).toHaveBeenCalledTimes(1)
expect(loggerModule.logger.error).toHaveBeenCalledWith("[Service Worker] navigator is undefined") expect(loggerModule.logger.error).toHaveBeenCalledWith("[Service Worker] navigator is undefined")

View File

@ -58,7 +58,7 @@ describe("serviceWorker", () => {
}) })
it("should add 3 listeners: install, activate and fetch", () => { it("should add 3 listeners: install, activate and fetch", () => {
require("../../src/browser/serviceWorker.ts") require("../../../src/browser/serviceWorker.ts")
const listenerEventNames = listeners.map((listener) => listener.event) const listenerEventNames = listeners.map((listener) => listener.event)
expect(listeners).toHaveLength(3) expect(listeners).toHaveLength(3)
@ -68,20 +68,20 @@ describe("serviceWorker", () => {
}) })
it("should call the proper callbacks for 'install'", async () => { it("should call the proper callbacks for 'install'", async () => {
require("../../src/browser/serviceWorker.ts") require("../../../src/browser/serviceWorker.ts")
emit("install") emit("install")
expect(spy).toHaveBeenCalledWith("[Service Worker] installed") expect(spy).toHaveBeenCalledWith("[Service Worker] installed")
expect(spy).toHaveBeenCalledTimes(1) expect(spy).toHaveBeenCalledTimes(1)
}) })
it("should do nothing when 'fetch' is called", async () => { it("should do nothing when 'fetch' is called", async () => {
require("../../src/browser/serviceWorker.ts") require("../../../src/browser/serviceWorker.ts")
emit("fetch") emit("fetch")
expect(spy).not.toHaveBeenCalled() expect(spy).not.toHaveBeenCalled()
}) })
it("should call the proper callbacks for 'activate'", async () => { it("should call the proper callbacks for 'activate'", async () => {
require("../../src/browser/serviceWorker.ts") require("../../../src/browser/serviceWorker.ts")
emit("activate") emit("activate")
// Activate serviceWorker // Activate serviceWorker

View File

@ -469,9 +469,7 @@ describe("pathToFsPath", () => {
util util
// @ts-expect-error We need to check other types // @ts-expect-error We need to check other types
.pathToFsPath({}), .pathToFsPath({}),
).toThrow( ).toThrow(`Could not compute fsPath from given uri. Expected path to be of type string, but was of type undefined.`)
`Could not compute fsPath from given uri. Expected path to be of type string, but was of type undefined.`,
)
}) })
it("should not throw an error for a string array", () => { it("should not throw an error for a string array", () => {
// @ts-expect-error We need to check other types // @ts-expect-error We need to check other types