Skip to content

Commit 353c2a1

Browse files
committed
Update tests to reflect new upstream behavior.
1 parent b4bda04 commit 353c2a1

File tree

8 files changed

+36
-124
lines changed

8 files changed

+36
-124
lines changed

src/common/http.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,3 @@ export class HttpError extends Error {
1818
this.name = this.constructor.name
1919
}
2020
}
21-
22-
/**
23-
* Base options included on every page.
24-
*/
25-
export interface ClientConfiguration {
26-
codeServerVersion: string
27-
base: string
28-
csStaticBase: string
29-
}

src/common/util.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ClientConfiguration } from "./http"
2-
31
/**
42
* Split a string up to the delimiter. If the delimiter doesn't exist the first
53
* item will have all the text and the second item will be an empty string.
@@ -52,35 +50,6 @@ export const resolveBase = (base?: string): string => {
5250
return normalize(url.pathname)
5351
}
5452

55-
/**
56-
* Get client-side configuration embedded in the HTML or query params.
57-
*/
58-
export const getClientConfiguration = <T extends ClientConfiguration>(): T => {
59-
let config: T
60-
try {
61-
config = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!)
62-
} catch (error) {
63-
config = {} as T
64-
}
65-
66-
// You can also pass options in stringified form to the options query
67-
// variable. Options provided here will override the ones in the options
68-
// element.
69-
const params = new URLSearchParams(location.search)
70-
const queryOpts = params.get("options")
71-
if (queryOpts) {
72-
config = {
73-
...config,
74-
...JSON.parse(queryOpts),
75-
}
76-
}
77-
78-
config.base = resolveBase(config.base)
79-
config.csStaticBase = resolveBase(config.csStaticBase)
80-
81-
return config
82-
}
83-
8453
/**
8554
* Wrap the value in an array if it's not already an array. If the value is
8655
* undefined return an empty array.

src/node/cli.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class OptionalString extends Optional<string> {}
3232
export interface Args
3333
extends Pick<
3434
CodeServerLib.NativeParsedArgs,
35+
| "_"
3536
| "user-data-dir"
3637
| "enable-proposed-api"
3738
| "extensions-dir"
@@ -42,7 +43,12 @@ export interface Args
4243
| "locale"
4344
| "log"
4445
| "verbose"
45-
| "_"
46+
| "install-source"
47+
| "list-extensions"
48+
| "install-extension"
49+
| "uninstall-extension"
50+
| "locate-extension"
51+
// | "telemetry"
4652
> {
4753
config?: string
4854
auth?: AuthType
@@ -64,10 +70,7 @@ export interface Args
6470
socket?: string
6571
version?: boolean
6672
force?: boolean
67-
"list-extensions"?: boolean
68-
"install-extension"?: string[]
6973
"show-versions"?: boolean
70-
"uninstall-extension"?: string[]
7174
"proxy-domain"?: string[]
7275
"reuse-window"?: boolean
7376
"new-window"?: boolean
@@ -177,6 +180,8 @@ const options: Options<Required<Args>> = {
177180
"extra-builtin-extensions-dir": { type: "string[]", path: true },
178181
"list-extensions": { type: "boolean", description: "List installed VS Code extensions." },
179182
force: { type: "boolean", description: "Avoid prompts when installing VS Code extensions." },
183+
"install-source": { type: "string" },
184+
"locate-extension": { type: "string[]" },
180185
"install-extension": {
181186
type: "string[]",
182187
description:

src/node/http.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ import * as express from "express"
33
import * as expressCore from "express-serve-static-core"
44
import path from "path"
55
import qs from "qs"
6-
import { ClientConfiguration, HttpCode, HttpError } from "../common/http"
6+
import { HttpCode, HttpError } from "../common/http"
77
import { normalize } from "../common/util"
88
import { AuthType, DefaultedArgs } from "./cli"
99
import { version as codeServerVersion } from "./constants"
1010
import { Heart } from "./heart"
1111
import { getPasswordMethod, IsCookieValidArgs, isCookieValid, sanitizeString, escapeHtml, escapeJSON } from "./util"
1212

13+
/**
14+
* Base options included on every page.
15+
*/
16+
export interface ClientConfiguration {
17+
codeServerVersion: string
18+
base: string
19+
csStaticBase: string
20+
}
21+
1322
declare global {
1423
// eslint-disable-next-line @typescript-eslint/no-namespace
1524
namespace Express {

src/node/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import { startLink } from "./link"
1010
import { register } from "./routes"
1111
import { humanPath, isFile, loadAMDModule, open } from "./util"
1212

13-
export const shouldSpawnCliProcess = async (args: DefaultedArgs): Promise<boolean> => {
14-
const shouldSpawn = await loadAMDModule<(argv: DefaultedArgs) => boolean>("vs/code/node/cli", "shouldSpawnCliProcess")
13+
export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs): Promise<boolean> => {
14+
const shouldSpawn = await loadAMDModule<(argv: CodeServerLib.NativeParsedArgs) => boolean>(
15+
"vs/code/node/cli",
16+
"shouldSpawnCliProcess",
17+
)
1518

1619
return shouldSpawn(args)
1720
}

test/unit/common/util.test.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -110,71 +110,6 @@ describe("util", () => {
110110
})
111111
})
112112

113-
describe("getOptions", () => {
114-
beforeEach(() => {
115-
const location: LocationLike = {
116-
pathname: "/healthz",
117-
origin: "http://localhost:8080",
118-
// search: "?environmentId=600e0187-0909d8a00cb0a394720d4dce",
119-
}
120-
121-
// Because resolveBase is not a pure function
122-
// and relies on the global location to be set
123-
// we set it before all the tests
124-
// and tell TS that our location should be looked at
125-
// as Location (even though it's missing some properties)
126-
global.location = location as Location
127-
})
128-
129-
afterEach(() => {
130-
jest.restoreAllMocks()
131-
})
132-
133-
it("should return options with base and cssStaticBase even if it doesn't exist", () => {
134-
expect(util.getClientConfiguration()).toStrictEqual({
135-
base: "",
136-
csStaticBase: "",
137-
})
138-
})
139-
140-
it("should return options when they do exist", () => {
141-
// Mock getElementById
142-
const spy = jest.spyOn(document, "getElementById")
143-
// Create a fake element and set the attribute
144-
const mockElement = document.createElement("div")
145-
mockElement.setAttribute(
146-
"data-settings",
147-
'{"base":".","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableUpdateCheck":false}',
148-
)
149-
// Return mockElement from the spy
150-
// this way, when we call "getElementById"
151-
// it returns the element
152-
spy.mockImplementation(() => mockElement)
153-
154-
expect(util.getClientConfiguration()).toStrictEqual({
155-
base: "",
156-
csStaticBase: "/static/development/Users/jp/Dev/code-server",
157-
disableUpdateCheck: false,
158-
logLevel: 2,
159-
})
160-
})
161-
162-
it("should include queryOpts", () => {
163-
// Trying to understand how the implementation works
164-
// 1. It grabs the search params from location.search (i.e. ?)
165-
// 2. it then grabs the "options" param if it exists
166-
// 3. then it creates a new options object
167-
// spreads the original options
168-
// then parses the queryOpts
169-
location.search = '?options={"logLevel":2}'
170-
expect(util.getClientConfiguration()).toStrictEqual({
171-
base: "",
172-
csStaticBase: "",
173-
logLevel: 2,
174-
})
175-
})
176-
})
177-
178113
describe("arrayify", () => {
179114
it("should return value it's already an array", () => {
180115
expect(util.arrayify(["hello", "world"])).toStrictEqual(["hello", "world"])

test/unit/node/cli.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import {
1010
parse,
1111
setDefaults,
1212
shouldOpenInExistingInstance,
13-
shouldRunVsCodeCli,
1413
splitOnFirstEquals,
1514
} from "../../../src/node/cli"
1615
import { tmpdir } from "../../../src/node/constants"
16+
import { shouldSpawnCliProcess } from "../../../src/node/main"
1717
import { generatePassword, paths } from "../../../src/node/util"
1818
import { useEnv } from "../../utils/helpers"
1919

@@ -486,45 +486,45 @@ describe("splitOnFirstEquals", () => {
486486
})
487487
})
488488

489-
describe("shouldRunVsCodeCli", () => {
490-
it("should return false if no 'extension' related args passed in", () => {
489+
describe("shouldSpawnCliProcess", () => {
490+
it("should return false if no 'extension' related args passed in", async () => {
491491
const args = {
492492
_: [],
493493
}
494-
const actual = shouldRunVsCodeCli(args)
494+
const actual = await shouldSpawnCliProcess(args)
495495
const expected = false
496496

497497
expect(actual).toBe(expected)
498498
})
499499

500-
it("should return true if 'list-extensions' passed in", () => {
500+
it("should return true if 'list-extensions' passed in", async () => {
501501
const args = {
502502
_: [],
503503
["list-extensions"]: true,
504504
}
505-
const actual = shouldRunVsCodeCli(args)
505+
const actual = await shouldSpawnCliProcess(args)
506506
const expected = true
507507

508508
expect(actual).toBe(expected)
509509
})
510510

511-
it("should return true if 'install-extension' passed in", () => {
511+
it("should return true if 'install-extension' passed in", async () => {
512512
const args = {
513513
_: [],
514514
["install-extension"]: ["hello.world"],
515515
}
516-
const actual = shouldRunVsCodeCli(args)
516+
const actual = await shouldSpawnCliProcess(args)
517517
const expected = true
518518

519519
expect(actual).toBe(expected)
520520
})
521521

522-
it("should return true if 'uninstall-extension' passed in", () => {
522+
it("should return true if 'uninstall-extension' passed in", async () => {
523523
const args = {
524524
_: [],
525525
["uninstall-extension"]: ["hello.world"],
526526
}
527-
const actual = shouldRunVsCodeCli(args)
527+
const actual = await shouldSpawnCliProcess(args)
528528
const expected = true
529529

530530
expect(actual).toBe(expected)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as integration from "../../../utils/integration"
77

88
const NOT_FOUND = {
99
code: 404,
10-
message: "Not Found",
10+
message: /not found/i,
1111
}
1212

1313
describe("/_static", () => {
@@ -44,7 +44,7 @@ describe("/_static", () => {
4444
expect(resp.status).toBe(NOT_FOUND.code)
4545

4646
const content = await resp.json()
47-
expect(content.error).toContain(NOT_FOUND.message)
47+
expect(content.error).toMatch(NOT_FOUND.message)
4848
})
4949
}
5050

0 commit comments

Comments
 (0)