Skip to content

Commit 2690e22

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 15b39e6 commit 2690e22

File tree

11 files changed

+107
-9
lines changed

11 files changed

+107
-9
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 2 deletions
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.

ci/dev/postinstall.sh

Lines changed: 11 additions & 5 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ main() {
55
cd "$(dirname "$0")/../.."
66
source ./ci/lib.sh
77

8+
pushd test/e2e/extensions/test-extension
9+
echo "Building test extension"
10+
yarn build
11+
popd
12+
813
local dir="$PWD"
914
if [[ ! ${CODE_SERVER_TEST_ENTRY-} ]]; then
1015
echo "Set CODE_SERVER_TEST_ENTRY to test another build of code-server"

ci/dev/test-unit.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
cd test/unit/node/test-plugin
6+
source ./ci/lib.sh
7+
8+
echo "Building test plugin"
9+
pushd test/unit/node/test-plugin
710
make -s out/index.js
11+
popd
12+
813
# We must keep jest in a sub-directory. See ../../test/package.json for more
914
# information. We must also run it from the root otherwise coverage will not
1015
# include our source files.
11-
cd "$OLDPWD"
1216
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@"
1317
}
1418

test/e2e/extensions.test.ts

Lines changed: 15 additions & 0 deletions
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+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/extension.js
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 29 additions & 0 deletions
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+
}
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 13 additions & 0 deletions
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==

0 commit comments

Comments
 (0)