Skip to content

Commit 4ae510c

Browse files
authored
Manually download VSCode (#156)
Workaround for redhat-developer/vscode-extension-tester#524 fixes `throw new Error('The `onCancel` handler was attached after the promise settled.');`, which sporadically failed CI tests.
1 parent 3a77caa commit 4ae510c

File tree

7 files changed

+170
-23
lines changed

7 files changed

+170
-23
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ jobs:
5151
run: yarn test:cov
5252

5353
- name: Integration Tests
54-
uses: nick-fields/retry@v2
55-
with:
56-
max_attempts: 3
57-
retry_wait_seconds: 2
58-
timeout_minutes: 10
59-
retry_on: any
60-
command: yarn run test:integ:cov
54+
run: yarn run test:integ:cov
6155

6256
- run: |
6357
cd coverage
@@ -122,18 +116,12 @@ jobs:
122116
working-directory: packages/databricks-vscode
123117

124118
- name: Integration Tests
125-
uses: nick-fields/retry@v2
126-
with:
127-
max_attempts: 3
128-
retry_wait_seconds: 2
129-
timeout_minutes: 10
130-
retry_on: any
131-
command: |
132-
yarn workspace databricks-vscode run test:integ:clean
133-
yarn install --immutable
134-
yarn build
135-
cd packages/databricks-vscode
136-
yarn run test:integ
119+
run: |
120+
yarn workspace databricks-vscode run test:integ:clean
121+
yarn install --immutable
122+
yarn build
123+
cd packages/databricks-vscode
124+
yarn run test:integ
137125
138126
- name: Upload test logs
139127
if: always()

packages/databricks-vscode/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@
503503
"test:lint": "eslint src --ext ts && prettier . -c",
504504
"test:unit": "yarn run build && node ./out/test/runTest.js",
505505
"test:integ:clean": "yarn run clean && rm -rf /tmp/vscode-test-databricks /tmp/databricks-vscode-test-extensions",
506-
"test:integ:prepare": "CODE_VERSION=1.69.1 && yarn run package && extest get-vscode --code_version $CODE_VERSION --storage /tmp/vscode-test-databricks && extest get-chromedriver --code_version 1.69.1 --storage /tmp/vscode-test-databricks",
507-
"test:integ:install-vsix": "extest install-vsix --storage /tmp/vscode-test-databricks -f databricks-vscode*.vsix -e /tmp/databricks-vscode-test-extensions",
506+
"test:integ:prepare": "CODE_VERSION=1.69.1 && yarn run package && ts-node src/test/vscode-extension-tester-patch/cli.ts get-vscode --code_version $CODE_VERSION --storage /tmp/vscode-test-databricks && ts-node src/test/vscode-extension-tester-patch/cli.ts get-chromedriver --code_version $CODE_VERSION --storage /tmp/vscode-test-databricks",
507+
"test:integ:install-vsix": "ts-node src/test/vscode-extension-tester-patch/cli.ts install-vsix --storage /tmp/vscode-test-databricks -f databricks-vscode*.vsix -e /tmp/databricks-vscode-test-extensions",
508508
"test:integ:run": "yarn run build && node out/test/e2e/scripts/e2e.js -e /tmp/databricks-vscode-test-extensions --storage /tmp/vscode-test-databricks --code_settings src/test/e2e/settings.json 'out/**/*.e2e.js'",
509509
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:install-vsix && yarn run test:integ:run",
510510
"test:cov": "nyc yarn run test:unit",
@@ -519,6 +519,7 @@
519519
},
520520
"devDependencies": {
521521
"@istanbuljs/nyc-config-typescript": "^1.0.2",
522+
"@types/fs-extra": "^9.0.13",
522523
"@types/glob": "^8.0.0",
523524
"@types/mocha": "^9.1.1",
524525
"@types/node": "^18.7.17",
@@ -529,12 +530,15 @@
529530
"@vscode/test-electron": "^2.1.5",
530531
"esbuild": "^0.15.7",
531532
"eslint": "^8.23.1",
533+
"fs-extra": "^10.1.0",
532534
"glob": "^8.0.3",
533535
"mocha": "^10.0.0",
536+
"mock-require": "^3.0.3",
534537
"nyc": "^15.1.0",
535538
"prettier": "^2.7.1",
536539
"tmp-promise": "^3.0.3",
537540
"ts-mockito": "^2.6.1",
541+
"ts-node": "^10.9.1",
538542
"typescript": "^4.8.3",
539543
"vsce": "^2.11.0",
540544
"vscode-extension-tester": "^4.4.1",
@@ -558,4 +562,4 @@
558562
],
559563
"report-dir": "coverage"
560564
}
561-
}
565+
}

packages/databricks-vscode/src/test/e2e/configure.e2e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ describe("Configure Databricks Extension", async function () {
169169
}
170170

171171
await input.setText(clusterId);
172+
await driver.sleep(200);
172173
await input.confirm();
173174

174175
// wait for tree to update
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# UGLY HACK
2+
3+
Please remove this folder once https://github.com/redhat-developer/vscode-extension-tester/issues/524 is fixed.
4+
5+
This version contains a fix for https://github.com/redhat-developer/vscode-extension-tester/issues/524 to make CI more reliable.
6+
7+
The patch in this repo is the same as this commit https://github.com/garden-io/garden/commit/eb00c57c1f84dda83c442da10362ddcfca594c37 for a different project.
8+
9+
The code in this folder is based on https://github.com/redhat-developer/vscode-extension-tester/tree/0aced778186c1a749cc4ea2e893fc12836c846e9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
3+
require("mock-require")(
4+
"vscode-extension-tester/out/util/download",
5+
"./download"
6+
);
7+
8+
import {program} from "commander";
9+
10+
require("vscode-extension-tester/out/cli");
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import * as fs from "fs-extra";
2+
import got, {OptionsOfTextResponseBody, Response} from "got";
3+
import {promisify} from "util";
4+
import stream = require("stream");
5+
import {HttpProxyAgent, HttpsProxyAgent} from "hpagent";
6+
7+
const httpProxyAgent = !process.env.HTTP_PROXY
8+
? undefined
9+
: new HttpProxyAgent({
10+
proxy: process.env.HTTP_PROXY,
11+
});
12+
13+
const httpsProxyAgent = !process.env.HTTPS_PROXY
14+
? undefined
15+
: new HttpsProxyAgent({
16+
proxy: process.env.HTTPS_PROXY,
17+
});
18+
19+
// This is to prevent Unhandled Promise Rejections in got
20+
// See: https://github.com/sindresorhus/got/issues/1489#issuecomment-805485731
21+
function isGotResponseOk(response: Response) {
22+
const {statusCode} = response;
23+
const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
24+
25+
return (
26+
(statusCode >= 200 && statusCode <= limitStatusCode) ||
27+
statusCode === 304
28+
);
29+
}
30+
31+
const options: OptionsOfTextResponseBody & {isStream?: undefined} = {
32+
headers: {
33+
"user-agent": "nodejs",
34+
},
35+
agent: {
36+
http: httpProxyAgent,
37+
https: httpsProxyAgent,
38+
},
39+
hooks: {
40+
afterResponse: [
41+
(response) => {
42+
if (isGotResponseOk(response)) {
43+
response.request.destroy();
44+
}
45+
46+
return response;
47+
},
48+
],
49+
},
50+
};
51+
52+
export class Download {
53+
static async getText(uri: string): Promise<string> {
54+
const body = await got(uri, options).text();
55+
return JSON.parse(body as string);
56+
}
57+
58+
static getFile(
59+
uri: string,
60+
destination: string,
61+
progress = false
62+
): Promise<void> {
63+
console.log("PATCHED DOWNLOAD");
64+
65+
let lastTick = 0;
66+
const dlStream = got.stream(uri, options);
67+
if (progress) {
68+
dlStream.on("downloadProgress", ({transferred, total, percent}) => {
69+
const currentTime = Date.now();
70+
if (
71+
total > 0 &&
72+
(lastTick === 0 ||
73+
transferred === total ||
74+
currentTime - lastTick >= 2000)
75+
) {
76+
console.log(
77+
`progress: ${transferred}/${total} (${Math.floor(
78+
100 * percent
79+
)}%)`
80+
);
81+
lastTick = currentTime;
82+
}
83+
});
84+
}
85+
const writeStream = fs.createWriteStream(destination);
86+
87+
return promisify(stream.pipeline)(dlStream, writeStream);
88+
}
89+
}

yarn.lock

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,15 @@ __metadata:
662662
languageName: node
663663
linkType: hard
664664

665+
"@types/fs-extra@npm:^9.0.13":
666+
version: 9.0.13
667+
resolution: "@types/fs-extra@npm:9.0.13"
668+
dependencies:
669+
"@types/node": "*"
670+
checksum: add79e212acd5ac76b97b9045834e03a7996aef60a814185e0459088fd290519a3c1620865d588fa36c4498bf614210d2a703af5cf80aa1dbc125db78f6edac3
671+
languageName: node
672+
linkType: hard
673+
665674
"@types/glob@npm:^8.0.0":
666675
version: 8.0.0
667676
resolution: "@types/glob@npm:8.0.0"
@@ -1838,6 +1847,7 @@ __metadata:
18381847
"@databricks/databricks-sdk": "*"
18391848
"@databricks/databricks-vscode-types": "workspace:^"
18401849
"@istanbuljs/nyc-config-typescript": ^1.0.2
1850+
"@types/fs-extra": ^9.0.13
18411851
"@types/glob": ^8.0.0
18421852
"@types/mocha": ^9.1.1
18431853
"@types/node": ^18.7.17
@@ -1850,12 +1860,15 @@ __metadata:
18501860
"@vscode/webview-ui-toolkit": ^1.0.1
18511861
esbuild: ^0.15.7
18521862
eslint: ^8.23.1
1863+
fs-extra: ^10.1.0
18531864
glob: ^8.0.3
18541865
mocha: ^10.0.0
1866+
mock-require: ^3.0.3
18551867
nyc: ^15.1.0
18561868
prettier: ^2.7.1
18571869
tmp-promise: ^3.0.3
18581870
ts-mockito: ^2.6.1
1871+
ts-node: ^10.9.1
18591872
typescript: ^4.8.3
18601873
vsce: ^2.11.0
18611874
vscode-extension-tester: ^4.4.1
@@ -2741,7 +2754,7 @@ __metadata:
27412754
languageName: node
27422755
linkType: hard
27432756

2744-
"fs-extra@npm:^10.0.0":
2757+
"fs-extra@npm:^10.0.0, fs-extra@npm:^10.1.0":
27452758
version: 10.1.0
27462759
resolution: "fs-extra@npm:10.1.0"
27472760
dependencies:
@@ -2836,6 +2849,13 @@ __metadata:
28362849
languageName: node
28372850
linkType: hard
28382851

2852+
"get-caller-file@npm:^1.0.2":
2853+
version: 1.0.3
2854+
resolution: "get-caller-file@npm:1.0.3"
2855+
checksum: 2b90a7f848896abcebcdc0acc627a435bcf05b9cd280599bc980ebfcdc222416c3df12c24c4845f69adc4346728e8966f70b758f9369f3534182791dfbc25c05
2856+
languageName: node
2857+
linkType: hard
2858+
28392859
"get-caller-file@npm:^2.0.1, get-caller-file@npm:^2.0.5":
28402860
version: 2.0.5
28412861
resolution: "get-caller-file@npm:2.0.5"
@@ -4035,6 +4055,16 @@ __metadata:
40354055
languageName: node
40364056
linkType: hard
40374057

4058+
"mock-require@npm:^3.0.3":
4059+
version: 3.0.3
4060+
resolution: "mock-require@npm:3.0.3"
4061+
dependencies:
4062+
get-caller-file: ^1.0.2
4063+
normalize-path: ^2.1.1
4064+
checksum: 6355c0bd9d7acb5247155142928b0154ace2913264b42d9a611a85d469ed11048f405efe432ffc627a57efb87ec359589a7419bf680b4fd248612311deb031bd
4065+
languageName: node
4066+
linkType: hard
4067+
40384068
"monaco-page-objects@npm:^2.0.1":
40394069
version: 2.0.1
40404070
resolution: "monaco-page-objects@npm:2.0.1"
@@ -4191,6 +4221,15 @@ __metadata:
41914221
languageName: node
41924222
linkType: hard
41934223

4224+
"normalize-path@npm:^2.1.1":
4225+
version: 2.1.1
4226+
resolution: "normalize-path@npm:2.1.1"
4227+
dependencies:
4228+
remove-trailing-separator: ^1.0.1
4229+
checksum: 7e9cbdcf7f5b8da7aa191fbfe33daf290cdcd8c038f422faf1b8a83c972bf7a6d94c5be34c4326cb00fb63bc0fd97d9fbcfaf2e5d6142332c2cd36d2e1b86cea
4230+
languageName: node
4231+
linkType: hard
4232+
41944233
"normalize-path@npm:^3.0.0, normalize-path@npm:~3.0.0":
41954234
version: 3.0.0
41964235
resolution: "normalize-path@npm:3.0.0"
@@ -4725,6 +4764,13 @@ __metadata:
47254764
languageName: node
47264765
linkType: hard
47274766

4767+
"remove-trailing-separator@npm:^1.0.1":
4768+
version: 1.1.0
4769+
resolution: "remove-trailing-separator@npm:1.1.0"
4770+
checksum: d3c20b5a2d987db13e1cca9385d56ecfa1641bae143b620835ac02a6b70ab88f68f117a0021838db826c57b31373d609d52e4f31aca75fc490c862732d595419
4771+
languageName: node
4772+
linkType: hard
4773+
47284774
"require-directory@npm:^2.1.1":
47294775
version: 2.1.1
47304776
resolution: "require-directory@npm:2.1.1"

0 commit comments

Comments
 (0)