Skip to content

Commit 8168e16

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 92d0d28 commit 8168e16

File tree

12 files changed

+105
-11
lines changed

12 files changed

+105
-11
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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6+
source ./ci/lib.sh
67

7-
echo "Installing code-server test dependencies..."
8+
pushd test
9+
echo "Installing dependencies for $PWD"
10+
yarn install
11+
popd
812

9-
cd test
13+
pushd test/e2e/extensions/test-extension
14+
echo "Installing dependencies for $PWD"
1015
yarn install
11-
cd ..
16+
popd
1217

13-
cd vendor
14-
echo "Installing vendor dependencies..."
18+
pushd vendor
19+
echo "Installing dependencies for $PWD"
1520

1621
# * We install in 'modules' instead of 'node_modules' because VS Code's extensions
1722
# use a webpack config which cannot differentiate between its own node_modules
@@ -32,6 +37,8 @@ main() {
3237

3338
# Finally, run the vendor `postinstall`
3439
yarn run postinstall
40+
41+
popd
3542
}
3643

3744
main "$@"

ci/dev/test-e2e.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ main() {
66

77
source ./ci/lib.sh
88

9+
pushd test/e2e/extensions/test-extension
10+
echo "Building test extension"
11+
yarn build
12+
popd
13+
914
local dir="$PWD"
1015
if [[ ! ${CODE_SERVER_TEST_ENTRY-} ]]; then
1116
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, test, expect } from "./baseFixture"
2+
3+
describe("Extensions", true, () => {
4+
// This will only work if the test extension is loaded into code-server.
5+
test("should have access to VSCODE_PROXY_URI", async ({ codeServerPage }) => {
6+
const address = await codeServerPage.address()
7+
8+
await codeServerPage.executeCommandViaMenus("code-server: Get proxy URI")
9+
10+
expect(await codeServerPage.page.isVisible(`text=${address}/proxy/{port}`)).toBe(true)
11+
})
12+
})
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==

test/e2e/models/CodeServer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export class CodeServer {
8787
path.join(dir, "config.yaml"),
8888
"--user-data-dir",
8989
dir,
90+
"--extensions-dir",
91+
path.join(__dirname, "../extensions"),
9092
// The last argument is the workspace to open.
9193
dir,
9294
],

test/playwright.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ const config: PlaywrightTestConfig = {
2020
name: "Chromium",
2121
use: { browserName: "chromium" },
2222
},
23-
2423
{
2524
name: "Firefox",
2625
use: { browserName: "firefox" },
2726
},
28-
2927
{
3028
name: "WebKit",
3129
use: { browserName: "webkit" },

0 commit comments

Comments
 (0)