Skip to content

Commit a7940d3

Browse files
committed
Add test extension
This will let us test extension-related features (like the proxy URI). I removed the environment variables in the script because they override the ones you set yourself. We still set defaults in constants.ts.
1 parent b59b393 commit a7940d3

File tree

12 files changed

+138
-30
lines changed

12 files changed

+138
-30
lines changed

.eslintrc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ rules:
3636
import/order:
3737
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
3838
no-async-promise-executor: off
39-
# This isn't a real module, just types, which apparently doesn't resolve.
40-
import/no-unresolved: [error, { ignore: ["express-serve-static-core"] }]
39+
# These aren't real modules, just types, which apparently don't resolve.
40+
import/no-unresolved: [error, { ignore: ["express-serve-static-core", "vscode"] }]
4141

4242
settings:
4343
# Does not work with CommonJS unfortunately.

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ jobs:
381381
382382
- name: Run end-to-end tests
383383
run: |
384-
./release-packages/code-server*-linux-amd64/bin/code-server --log trace &
384+
./release-packages/code-server*-linux-amd64/bin/code-server --log trace --extensions-dir ./test/e2e/extensions &
385385
yarn test:e2e
386386
387387
- name: Upload test artifacts

ci/dev/postinstall.sh

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ main() {
55
cd "$(dirname "$0")/../.."
66
source ./ci/lib.sh
77

8-
# This installs the dependencies needed for testing
9-
cd test
8+
pushd test
9+
echo "Installing dependencies for $PWD"
1010
yarn
11-
cd ..
11+
popd
1212

13-
cd lib/vscode
14-
yarn ${CI+--frozen-lockfile}
13+
pushd test/e2e/extensions/test-extension
14+
echo "Installing dependencies for $PWD"
15+
yarn
16+
popd
1517

18+
pushd lib/vscode
19+
echo "Installing dependencies for $PWD"
20+
yarn ${CI+--frozen-lockfile}
1621
symlink_asar
22+
popd
1723
}
1824

1925
main "$@"

ci/dev/test-e2e.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
cd test
7-
# We set these environment variables because they're used in the e2e tests
8-
# they don't have to be these values, but these are the defaults
9-
PASSWORD=e45432jklfdsab CODE_SERVER_ADDRESS=http://localhost:8080 yarn playwright test "$@"
6+
source ./ci/lib.sh
7+
8+
pushd test/e2e/extensions/test-extension
9+
echo "Building test extension"
10+
yarn build
11+
popd
12+
13+
pushd test
14+
echo "Running e2e tests"
15+
yarn playwright test "$@"
16+
popd
1017
}
1118

1219
main "$@"

ci/dev/test-unit.sh

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ main() {
55
cd "$(dirname "$0")/../.."
66
cd test/unit/test-plugin
77
make -s out/index.js
8+
89
# We must keep jest in a sub-directory. See ../../test/package.json for more
910
# information. We must also run it from the root otherwise coverage will not
1011
# include our source files.

test/e2e/extensions.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CODE_SERVER_ADDRESS, storageState } from "../utils/constants"
2+
import { test } from "./baseFixture"
3+
4+
test.describe("Extensions", () => {
5+
test.use({
6+
storageState,
7+
})
8+
9+
// This will only work if the test extension is loaded into code-server.
10+
test("should have access to VSCODE_PROXY_URI", async ({ codeServerPage }) => {
11+
await codeServerPage.runCommandFromPalette("code-server: Get proxy URI")
12+
13+
await codeServerPage.page.isVisible(`text=${CODE_SERVER_ADDRESS}/proxy/{port}`)
14+
})
15+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/extension.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from "vscode"
2+
3+
export function activate(context: vscode.ExtensionContext) {
4+
context.subscriptions.push(
5+
vscode.commands.registerCommand("codeServerTest.proxyUri", () => {
6+
if (process.env.VSCODE_PROXY_URI) {
7+
vscode.window.showInformationMessage(process.env.VSCODE_PROXY_URI)
8+
} else {
9+
vscode.window.showErrorMessage("No proxy URI was set")
10+
}
11+
}),
12+
)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "code-server-extension",
3+
"description": "code-server test extension",
4+
"version": "0.0.1",
5+
"publisher": "cdr",
6+
"activationEvents": [
7+
"onCommand:codeServerTest.proxyUri"
8+
],
9+
"engines": {
10+
"vscode": "^1.56.0"
11+
},
12+
"main": "./extension.js",
13+
"contributes": {
14+
"commands": [
15+
{
16+
"command": "codeServerTest.proxyUri",
17+
"title": "Get proxy URI",
18+
"category": "code-server"
19+
}
20+
]
21+
},
22+
"devDependencies": {
23+
"@types/vscode": "^1.56.0",
24+
"typescript": "^4.0.5"
25+
},
26+
"scripts": {
27+
"build": "tsc extension.ts"
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "commonjs",
5+
"outDir": ".",
6+
"strict": true,
7+
"baseUrl": "./"
8+
},
9+
"include": ["./extension.ts"]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/vscode@^1.56.0":
6+
version "1.57.0"
7+
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.57.0.tgz#cc648e0573b92f725cd1baf2621f8da9f8bc689f"
8+
integrity sha512-FeznBFtIDCWRluojTsi9c3LLcCHOXP5etQfBK42+ixo1CoEAchkw39tuui9zomjZuKfUVL33KZUDIwHZ/xvOkQ==
9+
10+
typescript@^4.0.5:
11+
version "4.3.2"
12+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
13+
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==

test/e2e/models/CodeServer.ts

+31-18
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,10 @@ export class CodeServer {
8181
* visible already.
8282
*/
8383
async focusTerminal() {
84-
// Click [aria-label="Application Menu"] div[role="none"]
85-
await this.page.click('[aria-label="Application Menu"] div[role="none"]')
86-
87-
// Click text=View
88-
await this.page.hover("text=View")
89-
await this.page.click("text=View")
90-
91-
// Click text=Command Palette
92-
await this.page.hover("text=Command Palette")
93-
await this.page.click("text=Command Palette")
94-
95-
// Type Terminal: Focus Terminal
96-
await this.page.keyboard.type("Terminal: Focus Terminal")
97-
98-
// Click Terminal: Focus Terminal
99-
await this.page.hover("text=Terminal: Focus Terminal")
100-
await this.page.click("text=Terminal: Focus Terminal")
84+
// Execute the focus terminal command via the command palette.
85+
await this.runCommandFromPalette("Terminal: Focus Terminal")
10186

102-
// Wait for terminal textarea to show up
87+
// Wait for terminal textarea to show up.
10388
await this.page.waitForSelector("textarea.xterm-helper-textarea")
10489
}
10590

@@ -113,4 +98,32 @@ export class CodeServer {
11398
await this.navigate()
11499
await this.reloadUntilEditorIsReady()
115100
}
101+
102+
/**
103+
* Run a command via the command palette.
104+
*/
105+
async runCommandFromPalette(command: string) {
106+
await this.runCommandFromMenu(["View", "Command Palette"])
107+
108+
// Type the command we want.
109+
await this.page.keyboard.type(command)
110+
111+
// Click on the matching command.
112+
await this.page.hover(`text=${command}`)
113+
await this.page.click(`text=${command}`)
114+
}
115+
116+
/**
117+
* Run a command from the application menu.
118+
*/
119+
async runCommandFromMenu(menus: string[]) {
120+
// Open the application menu.
121+
await this.page.click('[aria-label="Application Menu"] div[role="none"]')
122+
123+
// Open each sub-menu in turn.
124+
for (const menu in menus) {
125+
await this.page.hover(`text=${menu}`)
126+
await this.page.click(`text=${menu}`)
127+
}
128+
}
116129
}

0 commit comments

Comments
 (0)