Skip to content

Commit

Permalink
Refactor e2e tests configuration + strict types in client
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 10, 2024
1 parent 52f3f80 commit 866a8a6
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 14 deletions.
65 changes: 65 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"webpack": "webpack",
"watch": "webpack --watch --progress",
"test": "jest"
},
"devDependencies": {
"@types/glob": "^8.1.0"
}
}
5 changes: 5 additions & 0 deletions client/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class ComparableWorkflow {
uri: Uri;
ref?: string;

constructor(uri: Uri, ref?: string) {
this.uri = uri;
this.ref = ref;
}

// TODO: This is no longer working until a new API is available
// ref: https://github.com/microsoft/vscode/issues/177319
// ref: https://github.com/microsoft/vscode/issues/84297
Expand Down
2 changes: 1 addition & 1 deletion client/tests/e2e/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function main(): Promise<void> {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../../");
const extensionDevelopmentPath = path.resolve(__dirname, "../../../../");

// The path to test runner
// Passed to --extensionTestsPath
Expand Down
15 changes: 9 additions & 6 deletions client/tests/e2e/suite/extension.ga.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import * as path from "path";
import * as assert from "assert";
import { beforeEach } from "mocha";
import * as path from "path";
import * as vscode from "vscode";
import {
activateAndOpenInEditor,
getDocUri,
assertDiagnostics,
closeAllEditors,
getDocUri,
openDocument,
resetSettings,
sleep,
assertDiagnostics,
updateSettings,
resetSettings,
waitForDiagnostics,
} from "./helpers";

Expand All @@ -22,14 +22,17 @@ suite("Native (JSON) Workflows", () => {
test("Clean workflow command removes non-essential properties", async () => {
const dirtyDocUri = getDocUri(path.join("json", "clean", "wf_01_dirty.ga"));
const cleanDocUri = getDocUri(path.join("json", "clean", "wf_01_clean.ga"));
const { document } = await activateAndOpenInEditor(dirtyDocUri);
const editor = await activateAndOpenInEditor(dirtyDocUri);
const document = editor?.document;
assert.ok(document);
await sleep(500); // Wait for extension to fully activate... yes Windows CI I'm looking at you...
const dirtyDoc = document.getText();
await vscode.commands.executeCommand("galaxy-workflows.cleanWorkflow");
await sleep(500); // Wait for command to apply changes
const actualCleanJson = document.getText();
assert.notEqual(dirtyDoc, actualCleanJson);
const expectedCleanDocument = await openDocument(cleanDocUri);
assert.ok(expectedCleanDocument);
const expectedCleanJson = expectedCleanDocument.getText();
assert.strictEqual(actualCleanJson, expectedCleanJson);
});
Expand Down
10 changes: 6 additions & 4 deletions client/tests/e2e/suite/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export interface DocumentEditor {

export async function activate(): Promise<unknown> {
const ext = vscode.extensions.getExtension("davelopez.galaxy-workflows");
const api = ext.isActive ? ext.exports : await ext.activate();
const api = ext?.isActive ? ext.exports : await ext?.activate();
return api;
}

export async function openDocumentInEditor(docUri: vscode.Uri): Promise<DocumentEditor> {
export async function openDocumentInEditor(docUri: vscode.Uri): Promise<DocumentEditor | undefined> {
try {
const document = await vscode.workspace.openTextDocument(docUri);
const editor = await vscode.window.showTextDocument(document);
Expand All @@ -29,16 +29,18 @@ export async function openDocumentInEditor(docUri: vscode.Uri): Promise<Document
}
}

export async function openDocument(docUri: vscode.Uri): Promise<vscode.TextDocument> {
export async function openDocument(docUri: vscode.Uri): Promise<vscode.TextDocument | undefined> {
try {
const document = await vscode.workspace.openTextDocument(docUri);
return document;
} catch (e) {
console.error(e);
}

return undefined;
}

export async function activateAndOpenInEditor(docUri: vscode.Uri): Promise<DocumentEditor> {
export async function activateAndOpenInEditor(docUri: vscode.Uri): Promise<DocumentEditor | undefined> {
await activate();
const documentEditor = await openDocumentInEditor(docUri);
return documentEditor;
Expand Down
11 changes: 11 additions & 0 deletions client/tests/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2019",
"lib": ["ES2019", "WebWorker"],
"module": "commonjs",
"sourceMap": true,
"strict": true,
"baseUrl": ".",
"skipLibCheck": true
}
}
5 changes: 3 additions & 2 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2019",
"lib": ["ES2019", "WebWorker"],
"rootDirs": ["src", "tests"],
"module": "commonjs",
"sourceMap": true,
"strict": true,
"baseUrl": ".",
"skipLibCheck": true
},
"include": ["tests"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"test": "npm run test-client && npm run test-server",
"test-client": "cd client && npm test",
"test-server": "cd server && npm test",
"test-compile": "tsc --project ./client --outDir client/out",
"test-compile": "tsc --project ./client/tests/e2e --outDir client/out/tests/e2e",
"pretest:e2e": "npm run clean && npm run compile && npm run test-compile",
"test:e2e": "node ./client/out/tests/e2e/runTests.js",
"test-browser": "vscode-test-web --extensionDevelopmentPath=. ./test-data"
Expand Down

0 comments on commit 866a8a6

Please sign in to comment.