Skip to content

Commit

Permalink
Merge pull request #3769 from cdr/jsjoeio-chore-cleanup
Browse files Browse the repository at this point in the history
refactor: clean up testing files
  • Loading branch information
jsjoeio committed Jul 13, 2021
2 parents a5cf018 + fc16f7e commit 723a274
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSDOM } from "jsdom"
import { LocationLike } from "../../unit/util.test"
import { LocationLike } from "../../util.test"

describe("login", () => {
describe("there is an element with id 'base'", () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("login", () => {
document.body.appendChild(mockElement)
spy.mockImplementation(() => mockElement)
// Load file
require("../../../src/browser/pages/login")
require("../../../../src/browser/pages/login")

const el: HTMLInputElement | null = document.querySelector("input#base")
expect(el?.value).toBe("/hello-world")
Expand Down Expand Up @@ -80,7 +80,7 @@ describe("login", () => {
it("should do nothing", () => {
spy.mockImplementation(() => null)
// Load file
require("../../../src/browser/pages/login")
require("../../../../src/browser/pages/login")

// It's called once by getOptions in the top of the file
// and then another to get the base element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getNlsConfiguration,
nlsConfigElementId,
setBodyBackgroundToThemeBackgroundColor,
} from "../../../src/browser/pages/vscode"
} from "../../../../src/browser/pages/vscode"

describe("vscode", () => {
describe("getNlsConfiguration", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { registerServiceWorker } from "../../../src/browser/register"
import { createLoggerMock } from "../../utils/helpers"
import { LocationLike } from "../util.test"

describe("register", () => {
describe("when navigator and serviceWorker are defined", () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("register", () => {

it("should register a ServiceWorker", () => {
// Load service worker like you would in the browser
require("../../src/browser/register")
require("../../../src/browser/register")
expect(mockRegisterFn).toHaveBeenCalled()
expect(mockRegisterFn).toHaveBeenCalledTimes(1)
})
Expand All @@ -64,7 +64,7 @@ describe("register", () => {
})

// Load service worker like you would in the browser
require("../../src/browser/register")
require("../../../src/browser/register")

expect(mockRegisterFn).toHaveBeenCalled()
expect(loggerModule.logger.error).toHaveBeenCalled()
Expand All @@ -88,7 +88,7 @@ describe("register", () => {

it("should log an error", () => {
// 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).toHaveBeenCalledTimes(1)
expect(loggerModule.logger.error).toHaveBeenCalledWith("[Service Worker] navigator is undefined")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("serviceWorker", () => {
})

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)

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

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

it("should do nothing when 'fetch' is called", async () => {
require("../../src/browser/serviceWorker.ts")
require("../../../src/browser/serviceWorker.ts")
emit("fetch")
expect(spy).not.toHaveBeenCalled()
})

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

// Activate serviceWorker
Expand Down
4 changes: 1 addition & 3 deletions test/unit/node/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,7 @@ describe("pathToFsPath", () => {
util
// @ts-expect-error We need to check other types
.pathToFsPath({}),
).toThrow(
`Could not compute fsPath from given uri. Expected path to be of type string, but was of type undefined.`,
)
).toThrow(`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", () => {
// @ts-expect-error We need to check other types
Expand Down

0 comments on commit 723a274

Please sign in to comment.