Skip to content

Commit 5177b8d

Browse files
Add integration tests for resource explorer refresh and bundle job resource run (#1108)
## Changes * Add e2e integration test for refreshing a bundle when bundle file changes * Add e2e integration test for running a bundle job resource * Add a common prefix to all resources created by bundle tests to ease cleanup. ## Tests <!-- How is this tested? -->
1 parent f00ebd2 commit 5177b8d

20 files changed

+907
-280
lines changed

.github/workflows/push.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ jobs:
2626
cli_arch: ${{ matrix.arch.cli_arch }}
2727
secrets: inherit
2828

29+
validate-tests:
30+
runs-on: ubuntu-latest
31+
needs: ["run-tests"]
32+
steps:
33+
- run: echo "Tests successfull"
34+
shell: bash
35+
2936
package:
30-
name: Package VSIX
31-
needs: "run-tests"
37+
name: Package Arm64 VSIX
3238
runs-on: "macos-latest"
3339
steps:
3440
- uses: actions/checkout@v3
@@ -53,7 +59,7 @@ jobs:
5359
- run: mkdir -p packages/databricks-vscode/artifacts
5460

5561
- name: Build VSIX
56-
run: yarn package -o artifacts -t darwin-x64
62+
run: yarn package -o artifacts -t darwin-arm64
5763
working-directory: packages/databricks-vscode
5864

5965
- name: Upload artifacts

.github/workflows/tests.yml

Lines changed: 132 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ on:
1717
type: string
1818

1919
jobs:
20-
test-extension:
21-
name: Test VSCode Extension
20+
unit-test-extension:
21+
name: Run unit tests
2222
runs-on: ${{ inputs.os }}
2323
environment:
2424
name: azure-prod-usr
@@ -43,12 +43,6 @@ jobs:
4343
node-version: ${{ inputs.node-version }}
4444
cache: "yarn"
4545

46-
- name: Cache wdio
47-
uses: actions/cache@v3
48-
with:
49-
path: /tmp/wdio-vscode-service
50-
key: ${{ inputs.cli_arch }}-${{ inputs.vscode-version }}-wdio
51-
5246
- name: Cache VSCode unit test runner
5347
uses: actions/cache@v3
5448
with:
@@ -76,18 +70,143 @@ jobs:
7670
run: yarn run test:cov
7771
working-directory: packages/databricks-vscode
7872

79-
- name: Integration Tests
80-
run: yarn run test:integ:prepare && yarn run test:integ:run
73+
list-integration-test-specs:
74+
name: Generate integration test matrix
75+
runs-on: ${{ inputs.os }}
76+
outputs:
77+
specs: ${{ steps.generate-matrix.outputs.specs }}
78+
defaults:
79+
run:
80+
shell: bash
81+
82+
steps:
83+
- uses: actions/checkout@v3
84+
85+
- name: Use Node.js ${{ inputs.node-version }}
86+
uses: actions/setup-node@v3
87+
with:
88+
node-version: ${{ inputs.node-version }}
89+
cache: "yarn"
90+
91+
- run: yarn install --immutable
92+
93+
- name: Generate matrix
94+
id: generate-matrix
95+
run: |
96+
echo "specs=$(yarn ts-node scripts/list_integration_tests.ts)"
97+
echo "specs=$(yarn ts-node scripts/list_integration_tests.ts)" >> $GITHUB_OUTPUT
8198
working-directory: packages/databricks-vscode
8299

83-
- name: Integration Tests SDK wrappers
84-
run: yarn run test:integ:sdk
100+
extension-integration-tests:
101+
name: Run extension e2e integration tests
102+
needs: [list-integration-test-specs]
103+
strategy:
104+
fail-fast: false
105+
matrix:
106+
spec: ${{fromJson(needs.list-integration-test-specs.outputs.specs)}}
107+
108+
runs-on: ${{ inputs.os }}
109+
environment:
110+
name: azure-prod-usr
111+
112+
env:
113+
VSCODE_TEST_VERSION: ${{ inputs.vscode-version }}
114+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
115+
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
116+
TEST_DEFAULT_CLUSTER_ID: ${{ secrets.TEST_VSCODE_CLUSTER_ID }}
117+
CLI_ARCH: ${{ inputs.cli_arch }}
118+
119+
defaults:
120+
run:
121+
shell: bash
122+
123+
steps:
124+
- uses: actions/checkout@v3
125+
126+
- name: Use Node.js ${{ inputs.node-version }}
127+
uses: actions/setup-node@v3
128+
with:
129+
node-version: ${{ inputs.node-version }}
130+
cache: "yarn"
131+
132+
- name: Get vscode engine
133+
id: vscode-engine
134+
run: |
135+
echo "vscode=$(cat package.json | jq .engines.vscode | tr -d '^"')"
136+
echo "vscode=$(cat package.json | jq .engines.vscode | tr -d '^"')" >> $GITHUB_OUTPUT
137+
working-directory: packages/databricks-vscode
138+
139+
- name: Cache wdio
140+
id: wdio-cache
141+
uses: actions/cache@v3
142+
with:
143+
path: packages/databricks-vscode/tmp/wdio-vscode-service
144+
key: ${{ inputs.cli_arch }}-${{ steps.vscode-engine.outputs.vscode }}-wdio
145+
146+
- name: mkdir packages/databricks-vscode/tmp/wdio-vscode-service
147+
run: mkdir -p packages/databricks-vscode/tmp/wdio-vscode-service
148+
if: steps.wdio-cache.outputs.cache-hit != 'true'
149+
150+
- run: yarn install --immutable
151+
152+
- name: Fetching Databricks CLI
153+
run: yarn run package:cli:fetch
154+
working-directory: packages/databricks-vscode
155+
env:
156+
GH_TOKEN: ${{ github.token }}
157+
158+
- name: Building packages
159+
run: yarn run build
160+
161+
- name: Integration Tests
162+
run: yarn run test:integ:extension --spec ${{ matrix.spec.path }}
85163
working-directory: packages/databricks-vscode
86164

87165
- name: Upload test logs
88166
if: always()
89167
continue-on-error: true
90168
uses: actions/upload-artifact@v3
91169
with:
92-
name: test-logs ${{ join(inputs.*, ' - ') }} - ${{ github.event_name }}
170+
name: test-logs ${{ join(inputs.*, ' - ') }} - ${{ matrix.spec.baseName }} - ${{ github.event_name }}
93171
path: packages/databricks-vscode/logs
172+
173+
sdk-wrappers-integration-tests:
174+
name: Run integration tests for SDK wrappers
175+
runs-on: ${{ inputs.os }}
176+
environment:
177+
name: azure-prod-usr
178+
179+
env:
180+
VSCODE_TEST_VERSION: ${{ inputs.vscode-version }}
181+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
182+
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
183+
TEST_DEFAULT_CLUSTER_ID: ${{ secrets.TEST_VSCODE_CLUSTER_ID }}
184+
CLI_ARCH: ${{ inputs.cli_arch }}
185+
186+
defaults:
187+
run:
188+
shell: bash
189+
190+
steps:
191+
- uses: actions/checkout@v3
192+
193+
- name: Use Node.js ${{ inputs.node-version }}
194+
uses: actions/setup-node@v3
195+
with:
196+
node-version: ${{ inputs.node-version }}
197+
cache: "yarn"
198+
199+
- run: yarn install --immutable
200+
201+
- name: Fetching Databricks CLI
202+
run: yarn run package:cli:fetch
203+
working-directory: packages/databricks-vscode
204+
env:
205+
GH_TOKEN: ${{ github.token }}
206+
207+
- name: Building packages
208+
run: yarn run build
209+
210+
- name: Integration Tests SDK wrappers
211+
run: yarn run test:integ:sdk
212+
working-directory: packages/databricks-vscode

packages/databricks-vscode/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ src/test/e2e/workspace/
55
extension/
66
.pytest_cache/
77
.build/
8+
**/tmp/**
89

910
# Telemetry file, automatically generated by packages/databricks-vscode/scripts/generateTelemetry.ts
1011
telemetry.json

packages/databricks-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@
802802
"test:lint": "eslint src --ext ts && prettier . -c",
803803
"test:unit": "yarn run build && node ./out/test/runTest.js",
804804
"test:integ:prepare": "yarn run package",
805-
"test:integ:run": "wdio run src/test/e2e/wdio.conf.ts",
805+
"test:integ:extension": "yarn run test:integ:prepare && wdio run src/test/e2e/wdio.conf.ts",
806806
"test:integ:sdk": "ts-mocha --type-check 'src/sdk-extensions/**/*.integ.ts'",
807-
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:run && yarn run test:integ:sdk",
807+
"test:integ": "yarn run test:integ:extension && yarn run test:integ:sdk",
808808
"test:cov": "nyc yarn run test:unit",
809809
"test": "yarn run test:lint && yarn run test:unit",
810810
"clean": "rm -rf node_modules out .vscode-test",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {glob} from "glob";
2+
import path from "path";
3+
4+
function toUnixPath(path: string) {
5+
if (process.platform === "win32") {
6+
return path.replace(/\\/g, "/");
7+
}
8+
return path;
9+
}
10+
11+
const integrationTests = glob
12+
.globSync(
13+
toUnixPath(
14+
path.join(process.cwd(), "src", "test", "e2e", "**", "*.e2e.ts")
15+
),
16+
{
17+
nocase: process.platform === "win32",
18+
}
19+
)
20+
.map((testPath) => {
21+
return {
22+
path: toUnixPath(path.relative(process.cwd(), testPath)),
23+
baseName: path.basename(testPath, ".e2e.ts"),
24+
};
25+
});
26+
27+
// eslint-disable-next-line no-console
28+
console.log(JSON.stringify(integrationTests));

packages/databricks-vscode/src/bundle/BundleFileSet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export async function getSubProjects(root: Uri) {
3030
.map((rootFile) => {
3131
const dirname = path.dirname(path.normalize(rootFile));
3232
const absolute = Uri.file(dirname);
33-
const relative = Uri.file(
34-
absolute.fsPath.replace(normalizedRoot, "")
35-
);
33+
const relative = path.relative(normalizedRoot, dirname);
3634
return {absolute, relative};
3735
})
3836
.filter(({absolute}) => {

packages/databricks-vscode/src/bundle/BundleInitWizard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import {writeFile, mkdir} from "fs/promises";
2020
import path from "path";
2121

2222
export async function promptToOpenSubProjects(
23-
projects: {absolute: Uri; relative: Uri}[],
23+
projects: {absolute: Uri; relative: string}[],
2424
authProvider?: AuthProvider
2525
) {
2626
type OpenProjectItem = QuickPickItem & {uri?: Uri};
2727
const items: OpenProjectItem[] = projects.map((project) => {
2828
return {
2929
uri: project.absolute,
30-
label: project.relative.fsPath,
30+
label: project.relative,
3131
detail: project.absolute.fsPath,
3232
};
3333
});

packages/databricks-vscode/src/bundle/BundleProjectManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class BundleProjectManager {
3333
private projectServicesReady = false;
3434
private projectServicesMutex = new Mutex();
3535

36-
private subProjects?: {relative: Uri; absolute: Uri}[];
36+
private subProjects?: {relative: string; absolute: Uri}[];
3737
private legacyProjectConfig?: ProjectConfigFile;
3838

3939
constructor(

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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,24 @@
11
import assert from "node:assert";
2-
import * as fs from "fs/promises";
32
import {
43
dismissNotifications,
54
waitForInput,
65
getViewSection,
76
waitForLogin,
8-
clearBundleConfig,
9-
createBasicBundleConfig,
10-
} from "./utils.ts";
7+
} from "./utils/commonUtils.ts";
118
import {CustomTreeSection} from "wdio-vscode-service";
12-
13-
let cfgPath: string;
14-
let cfgContent: Buffer;
9+
import {
10+
getBasicBundleConfig,
11+
writeRootBundleConfig,
12+
} from "./utils/dabsFixtures.ts";
1513

1614
describe("Configure Databricks Extension", async function () {
1715
this.timeout(3 * 60 * 1000);
1816

19-
before(async function () {
20-
assert(process.env.WORKSPACE_PATH, "WORKSPACE_PATH doesn't exist");
17+
it("should open VSCode and dismiss notifications", async function () {
2118
assert(
2219
process.env.DATABRICKS_CONFIG_FILE,
2320
"DATABRICKS_CONFIG_FILE doesn't exist"
2421
);
25-
cfgPath = process.env.DATABRICKS_CONFIG_FILE;
26-
cfgContent = await fs.readFile(cfgPath);
27-
});
28-
29-
after(async function () {
30-
try {
31-
await clearBundleConfig();
32-
if (cfgContent) {
33-
await fs.writeFile(cfgPath, cfgContent);
34-
}
35-
} catch (e) {
36-
console.error(e);
37-
}
38-
});
39-
40-
it("should open VSCode and dismiss notifications", async function () {
4122
const workbench = await browser.getWorkbench();
4223
const title = await workbench.getTitleBar().getTitle();
4324
assert(
@@ -60,7 +41,11 @@ describe("Configure Databricks Extension", async function () {
6041
});
6142

6243
it("should automatically login after detecting bundle configuration", async () => {
63-
await createBasicBundleConfig();
44+
assert(process.env.WORKSPACE_PATH, "WORKSPACE_PATH doesn't exist");
45+
await writeRootBundleConfig(
46+
getBasicBundleConfig(),
47+
process.env.WORKSPACE_PATH
48+
);
6449
await waitForLogin("DEFAULT");
6550
});
6651

0 commit comments

Comments
 (0)