Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"test:watch": "tsc -p . -w --outDir out",
"test:unit": "node ./out/test/runTest.js",
"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",
"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",
"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'",
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:run",
"test": "yarn run test:compile && yarn run compile && yarn run test:lint && yarn run test:unit",
"build": "yarn run vscode:prepublish",
Expand Down
34 changes: 14 additions & 20 deletions packages/databricks-vscode/src/test/e2e/configure.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert = require("node:assert");
import path = require("node:path");
import * as fs from "fs/promises";
import * as tmp from "tmp-promise";
import {
VSBrowser,
WebDriver,
Expand All @@ -11,13 +12,19 @@ import {
ContextMenu,
CustomTreeSection,
} from "vscode-extension-tester";
import {getViewSection, openCommandPrompt, waitForTreeItems} from "./utils";
import {
getViewSection,
openCommandPrompt,
openFolder,
waitForTreeItems,
} from "./utils";

describe("Configure Databricks Extension", function () {
// these will be populated by the before() function
let browser: VSBrowser;
let driver: WebDriver;
let projectDir: string;
let cleanup: () => void;

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

assert(process.env["PROJECT_DIR"]);
projectDir = process.env["PROJECT_DIR"];
({path: projectDir, cleanup} = await tmp.dir());
await openFolder(browser, projectDir);
});

after(() => {
cleanup();
});

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

it("should open project folder", async () => {
await fs.writeFile(path.join(projectDir, "test.txt"), "test");
(await new ActivityBar().getViewControl("Explorer"))?.openView();

const workbench = new Workbench();
const prompt = await openCommandPrompt(workbench);
await prompt.setText(">File: Open Folder");
await prompt.confirm();

const input = await InputBox.create();
await input.setText(projectDir);
await input.confirm();

// wait for reload to complete
await new Promise((resolve) => setTimeout(resolve, 3000));
});

it("should open databricks panel and login", async () => {
const section = await getViewSection("Configuration");
assert(section);
Expand Down
52 changes: 52 additions & 0 deletions packages/databricks-vscode/src/test/e2e/run_on_cluster.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import assert = require("node:assert");
import path = require("node:path");
import * as fs from "fs/promises";
import * as tmp from "tmp-promise";
import {
VSBrowser,
WebDriver,
ActivityBar,
InputBox,
Workbench,
} from "vscode-extension-tester";
import {openCommandPrompt, openFolder} from "./utils";

describe("Run python on cluster", function () {
// these will be populated by the before() function
let browser: VSBrowser;
let driver: WebDriver;
let projectDir: string;
let cleanup: () => void;

this.timeout(20_000);

before(async () => {
browser = VSBrowser.instance;
driver = browser.driver;

({path: projectDir, cleanup} = await tmp.dir());

await fs.mkdir(path.join(projectDir, ".databricks"));
await fs.writeFile(
path.join(projectDir, ".databricks", "project.json"),
JSON.stringify({
clusterId: process.env["DATABRICKS_CLUSTER_ID"],
profile: "DEFAULT",
})
);
await openFolder(browser, projectDir);
});

after(() => {
cleanup();
});

// TODO
it("should connect to Databricks", async () => {
const title = await driver.getTitle();
assert(title.indexOf("Get Started") >= 0);
});

// TODO
it("should run a python file on a cluster", async () => {});
});
11 changes: 4 additions & 7 deletions packages/databricks-vscode/src/test/e2e/scripts/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import {spawn} from "child_process";
import * as assert from "assert";
import * as fs from "fs/promises";
import * as path from "path";
import * as tmp from "tmp-promise";

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

const {path: projectDir, cleanup} = await tmp.dir();
const {path: configFile, cleanup} = await tmp.file();
try {
await fs.writeFile(
path.join(projectDir, ".databrickscfg"),
configFile,
`[DEFAULT]
host = ${process.env["DATABRICKS_HOST"]}
token = ${process.env["DATABRICKS_TOKEN"]}`
Expand All @@ -35,8 +33,7 @@ token = ${process.env["DATABRICKS_TOKEN"]}`
const child = spawn("extest", ["run-tests", ...args], {
env: {
DATABRICKS_CLUSTER_ID: process.env["DATABRICKS_CLUSTER_ID"],
PROJECT_DIR: projectDir,
DATABRICKS_CONFIG_FILE: path.join(projectDir, ".databrickscfg"),
DATABRICKS_CONFIG_FILE: configFile,
PATH: process.env["PATH"],
},
stdio: "inherit",
Expand Down
3 changes: 2 additions & 1 deletion packages/databricks-vscode/src/test/e2e/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"typescript.updateImportsOnFileMove.enabled": "always",
"files.simpleDialog.enable": true,
"workbench.editor.enablePreview": true,
"window.newWindowDimensions": "default"
"window.newWindowDimensions": "default",
"window.openFoldersInNewWindow": "off"
}
13 changes: 13 additions & 0 deletions packages/databricks-vscode/src/test/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Workbench,
ActivityBar,
ViewSection,
VSBrowser,
} from "vscode-extension-tester";

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

export async function openFolder(
browser: VSBrowser,
projectDir: string
): Promise<void> {
try {
await browser.openResources(projectDir);
} catch (e) {}

await browser.driver.sleep(1000);
await browser.waitForWorkbench();
}

export async function getViewSection(
name: string
): Promise<ViewSection | undefined> {
Expand Down