Skip to content

Commit 3d99998

Browse files
authored
feat: proxy URI environment variable (#4681)
* 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. * Add changelog entry for VSCODE_PROXY_URI * Add terminal test for VSCODE_PROXY_URI * Update VS Code This adds the VSCODE_PROXY_URI environment variable.
1 parent f04fcf2 commit 3d99998

15 files changed

+114
-19
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ implementation (#4414).
4040
- The last opened folder/workspace is no longer stored separately in the
4141
settings file (we rely on the already-existing query object instead).
4242

43+
### Added
44+
45+
- `VSCODE_PROXY_URI` env var for use in the terminal and extensions.
46+
4347
### Deprecated
4448

4549
- `--link` is now deprecated (#4562).

ci/dev/postinstall.sh

+17-5
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ 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

913
local args=(install)
1014
if [[ ${CI-} ]]; then
1115
args+=(--frozen-lockfile)
1216
fi
1317

14-
cd test
18+
pushd test
19+
echo "Installing dependencies for $PWD"
1520
yarn "${args[@]}"
16-
cd ..
21+
popd
1722

18-
cd vendor
19-
echo "Installing vendor dependencies..."
23+
pushd test/e2e/extensions/test-extension
24+
echo "Installing dependencies for $PWD"
25+
yarn "${args[@]}"
26+
popd
27+
28+
pushd vendor
29+
echo "Installing dependencies for $PWD"
2030

2131
# We install in 'modules' instead of 'node_modules' because VS Code's
2232
# extensions use a webpack config which cannot differentiate between its own
@@ -33,6 +43,8 @@ main() {
3343

3444
# Finally, run the vendor `postinstall`
3545
yarn run postinstall
46+
47+
popd
3648
}
3749

3850
main "$@"

ci/dev/test-e2e.sh

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ main() {
1313

1414
source ./ci/lib.sh
1515

16+
pushd test/e2e/extensions/test-extension
17+
echo "Building test extension"
18+
yarn build
19+
popd
20+
1621
local dir="$PWD"
1722
if [[ ! ${CODE_SERVER_TEST_ENTRY-} ]]; then
1823
echo "Set CODE_SERVER_TEST_ENTRY to test another build of code-server"

ci/dev/test-unit.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ main() {
66

77
source ./ci/lib.sh
88

9+
echo "Building test plugin"
910
pushd test/unit/node/test-plugin
1011
make -s out/index.js
1112
popd

test/e2e/extensions.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, test } 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+
await codeServerPage.page.waitForSelector(`text=${address}/proxy/{{port}}`)
11+
})
12+
})
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

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class CodeServer {
8888
path.join(dir, "config.yaml"),
8989
"--user-data-dir",
9090
dir,
91+
"--extensions-dir",
92+
path.join(__dirname, "../extensions"),
9193
// The last argument is the workspace to open.
9294
dir,
9395
],

test/e2e/terminal.test.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ import { clean, tmpdir } from "../utils/helpers"
55
import { describe, expect, test } from "./baseFixture"
66

77
describe("Integrated Terminal", true, () => {
8-
// Create a new context with the saved storage state
9-
// so we don't have to logged in
10-
const testFileName = "pipe"
11-
const testString = "new string test from e2e test"
12-
138
const testName = "integrated-terminal"
149
test.beforeAll(async () => {
1510
await clean(testName)
1611
})
1712

18-
test("should echo a string to a file", async ({ codeServerPage }) => {
13+
test("should have access to VSCODE_PROXY_URI", async ({ codeServerPage }) => {
1914
const tmpFolderPath = await tmpdir(testName)
20-
const tmpFile = path.join(tmpFolderPath, testFileName)
15+
const tmpFile = path.join(tmpFolderPath, "pipe")
2116

2217
const command = `mkfifo '${tmpFile}' && cat '${tmpFile}'`
2318
const exec = util.promisify(cp.exec)
@@ -27,12 +22,12 @@ describe("Integrated Terminal", true, () => {
2722
await codeServerPage.focusTerminal()
2823

2924
await codeServerPage.page.waitForLoadState("load")
30-
await codeServerPage.page.keyboard.type(`echo ${testString} > ${tmpFile}`)
25+
await codeServerPage.page.keyboard.type(`printenv VSCODE_PROXY_URI > ${tmpFile}`)
3126
await codeServerPage.page.keyboard.press("Enter")
3227
// It may take a second to process
3328
await codeServerPage.page.waitForTimeout(1000)
3429

3530
const { stdout } = await output
36-
expect(stdout).toMatch(testString)
31+
expect(stdout).toMatch(await codeServerPage.address())
3732
})
3833
})

test/playwright.config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ const config: PlaywrightTestConfig = {
2525
name: "Chromium",
2626
use: { browserName: "chromium" },
2727
},
28-
2928
{
3029
name: "Firefox",
3130
use: { browserName: "firefox" },
3231
},
33-
3432
{
3533
name: "WebKit",
3634
use: { browserName: "webkit" },

vendor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"postinstall": "./postinstall.sh"
88
},
99
"devDependencies": {
10-
"code-oss-dev": "cdr/vscode#69a6ce45fc5b883aa8a950e10b79fd083eb0a7d7"
10+
"code-oss-dev": "cdr/vscode#d4c3c65d5e17a240a95e735a349e311aaf721b60"
1111
}
1212
}

vendor/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ clone-response@^1.0.2:
274274
dependencies:
275275
mimic-response "^1.0.0"
276276

277-
code-oss-dev@cdr/vscode#69a6ce45fc5b883aa8a950e10b79fd083eb0a7d7:
277+
code-oss-dev@cdr/vscode#d4c3c65d5e17a240a95e735a349e311aaf721b60:
278278
version "1.63.0"
279-
resolved "https://codeload.github.com/cdr/vscode/tar.gz/69a6ce45fc5b883aa8a950e10b79fd083eb0a7d7"
279+
resolved "https://codeload.github.com/cdr/vscode/tar.gz/d4c3c65d5e17a240a95e735a349e311aaf721b60"
280280
dependencies:
281281
"@microsoft/applicationinsights-web" "^2.6.4"
282282
"@parcel/watcher" "2.0.3"

0 commit comments

Comments
 (0)