Skip to content

Commit 9aada06

Browse files
authored
Add placeholder e2e test for running Python (#34)
1 parent cc33968 commit 9aada06

File tree

6 files changed

+86
-29
lines changed

6 files changed

+86
-29
lines changed

packages/databricks-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"test:watch": "tsc -p . -w --outDir out",
196196
"test:unit": "node ./out/test/runTest.js",
197197
"test:integ:prepare": "yarn run vscode:package && extest get-vscode --type ${VSCODE_TEST_VERSION:-stable} --storage /tmp/vscode-test-databricks && extest get-chromedriver --storage /tmp/vscode-test-databricks && extest install-vsix -f databricks-0.0.1.vsix --storage /tmp/vscode-test-databricks",
198-
"test:integ:run": "yarn run test:compile && ts-node src/test/e2e/scripts/e2e.ts --storage /tmp/vscode-test-databricks --code_settings src/test/e2e/settings.json out/test/e2e/*.e2e.js",
198+
"test:integ:run": "yarn run test:compile && ts-node src/test/e2e/scripts/e2e.ts --storage /tmp/vscode-test-databricks --code_settings src/test/e2e/settings.json 'out/**/*.e2e.js'",
199199
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:run",
200200
"test": "yarn run test:compile && yarn run compile && yarn run test:lint && yarn run test:unit",
201201
"build": "yarn run vscode:prepublish",

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert = require("node:assert");
22
import path = require("node:path");
33
import * as fs from "fs/promises";
4+
import * as tmp from "tmp-promise";
45
import {
56
VSBrowser,
67
WebDriver,
@@ -11,13 +12,19 @@ import {
1112
ContextMenu,
1213
CustomTreeSection,
1314
} from "vscode-extension-tester";
14-
import {getViewSection, openCommandPrompt, waitForTreeItems} from "./utils";
15+
import {
16+
getViewSection,
17+
openCommandPrompt,
18+
openFolder,
19+
waitForTreeItems,
20+
} from "./utils";
1521

1622
describe("Configure Databricks Extension", function () {
1723
// these will be populated by the before() function
1824
let browser: VSBrowser;
1925
let driver: WebDriver;
2026
let projectDir: string;
27+
let cleanup: () => void;
2128

2229
// this will be populated by the tests
2330
let clusterId: string;
@@ -28,32 +35,19 @@ describe("Configure Databricks Extension", function () {
2835
browser = VSBrowser.instance;
2936
driver = browser.driver;
3037

31-
assert(process.env["PROJECT_DIR"]);
32-
projectDir = process.env["PROJECT_DIR"];
38+
({path: projectDir, cleanup} = await tmp.dir());
39+
await openFolder(browser, projectDir);
40+
});
41+
42+
after(() => {
43+
cleanup();
3344
});
3445

3546
it("should open VSCode", async () => {
3647
const title = await driver.getTitle();
3748
assert(title.indexOf("Get Started") >= 0);
3849
});
3950

40-
it("should open project folder", async () => {
41-
await fs.writeFile(path.join(projectDir, "test.txt"), "test");
42-
(await new ActivityBar().getViewControl("Explorer"))?.openView();
43-
44-
const workbench = new Workbench();
45-
const prompt = await openCommandPrompt(workbench);
46-
await prompt.setText(">File: Open Folder");
47-
await prompt.confirm();
48-
49-
const input = await InputBox.create();
50-
await input.setText(projectDir);
51-
await input.confirm();
52-
53-
// wait for reload to complete
54-
await new Promise((resolve) => setTimeout(resolve, 3000));
55-
});
56-
5751
it("should open databricks panel and login", async () => {
5852
const section = await getViewSection("Configuration");
5953
assert(section);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import assert = require("node:assert");
2+
import path = require("node:path");
3+
import * as fs from "fs/promises";
4+
import * as tmp from "tmp-promise";
5+
import {
6+
VSBrowser,
7+
WebDriver,
8+
ActivityBar,
9+
InputBox,
10+
Workbench,
11+
} from "vscode-extension-tester";
12+
import {openCommandPrompt, openFolder} from "./utils";
13+
14+
describe("Run python on cluster", function () {
15+
// these will be populated by the before() function
16+
let browser: VSBrowser;
17+
let driver: WebDriver;
18+
let projectDir: string;
19+
let cleanup: () => void;
20+
21+
this.timeout(20_000);
22+
23+
before(async () => {
24+
browser = VSBrowser.instance;
25+
driver = browser.driver;
26+
27+
({path: projectDir, cleanup} = await tmp.dir());
28+
29+
await fs.mkdir(path.join(projectDir, ".databricks"));
30+
await fs.writeFile(
31+
path.join(projectDir, ".databricks", "project.json"),
32+
JSON.stringify({
33+
clusterId: process.env["DATABRICKS_CLUSTER_ID"],
34+
profile: "DEFAULT",
35+
})
36+
);
37+
await openFolder(browser, projectDir);
38+
});
39+
40+
after(() => {
41+
cleanup();
42+
});
43+
44+
// TODO
45+
it("should connect to Databricks", async () => {
46+
const title = await driver.getTitle();
47+
assert(title.indexOf("Get Started") >= 0);
48+
});
49+
50+
// TODO
51+
it("should run a python file on a cluster", async () => {});
52+
});

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
import {spawn} from "child_process";
33
import * as assert from "assert";
44
import * as fs from "fs/promises";
5-
import * as path from "path";
65
import * as tmp from "tmp-promise";
76

87
/**
9-
* Create a temporary directory for the test and populate the Databricks config file
10-
* with values taken from environment variables
8+
* Create a temporary Databricks config file with values taken from environment variables
119
*/
1210
async function main(args: string[]) {
1311
assert(
@@ -23,10 +21,10 @@ async function main(args: string[]) {
2321
"Environment variable DATABRICKS_CLUSTER_ID must be set"
2422
);
2523

26-
const {path: projectDir, cleanup} = await tmp.dir();
24+
const {path: configFile, cleanup} = await tmp.file();
2725
try {
2826
await fs.writeFile(
29-
path.join(projectDir, ".databrickscfg"),
27+
configFile,
3028
`[DEFAULT]
3129
host = ${process.env["DATABRICKS_HOST"]}
3230
token = ${process.env["DATABRICKS_TOKEN"]}`
@@ -35,8 +33,7 @@ token = ${process.env["DATABRICKS_TOKEN"]}`
3533
const child = spawn("extest", ["run-tests", ...args], {
3634
env: {
3735
DATABRICKS_CLUSTER_ID: process.env["DATABRICKS_CLUSTER_ID"],
38-
PROJECT_DIR: projectDir,
39-
DATABRICKS_CONFIG_FILE: path.join(projectDir, ".databrickscfg"),
36+
DATABRICKS_CONFIG_FILE: configFile,
4037
PATH: process.env["PATH"],
4138
},
4239
stdio: "inherit",

packages/databricks-vscode/src/test/e2e/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"typescript.updateImportsOnFileMove.enabled": "always",
33
"files.simpleDialog.enable": true,
44
"workbench.editor.enablePreview": true,
5-
"window.newWindowDimensions": "default"
5+
"window.newWindowDimensions": "default",
6+
"window.openFoldersInNewWindow": "off"
67
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Workbench,
66
ActivityBar,
77
ViewSection,
8+
VSBrowser,
89
} from "vscode-extension-tester";
910

1011
// work around for https://github.com/redhat-developer/vscode-extension-tester/issues/470
@@ -37,6 +38,18 @@ export async function openCommandPrompt(
3738
return InputBox.create();
3839
}
3940

41+
export async function openFolder(
42+
browser: VSBrowser,
43+
projectDir: string
44+
): Promise<void> {
45+
try {
46+
await browser.openResources(projectDir);
47+
} catch (e) {}
48+
49+
await browser.driver.sleep(1000);
50+
await browser.waitForWorkbench();
51+
}
52+
4053
export async function getViewSection(
4154
name: string
4255
): Promise<ViewSection | undefined> {

0 commit comments

Comments
 (0)