From 866a8a649df9fbfc5d6ef7c5e74cb6f342011b30 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:32:47 +0200 Subject: [PATCH] Refactor e2e tests configuration + strict types in client --- client/package-lock.json | 65 ++++++++++++++++++++++ client/package.json | 3 + client/src/commands/index.ts | 5 ++ client/tests/e2e/runTests.ts | 2 +- client/tests/e2e/suite/extension.ga.e2e.ts | 15 +++-- client/tests/e2e/suite/helpers.ts | 10 ++-- client/tests/e2e/tsconfig.json | 11 ++++ client/tsconfig.json | 5 +- package.json | 2 +- 9 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 client/tests/e2e/tsconfig.json diff --git a/client/package-lock.json b/client/package-lock.json index ac0b888..7489b81 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -12,10 +12,38 @@ "vscode-languageclient": "^8.1.0", "vscode-uri": "^3.0.8" }, + "devDependencies": { + "@types/glob": "^8.1.0" + }, "engines": { "vscode": "^1.63.0" } }, + "node_modules/@types/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", + "dev": true, + "dependencies": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, + "node_modules/@types/minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", + "dev": true + }, + "node_modules/@types/node": { + "version": "20.14.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.2.tgz", + "integrity": "sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -65,6 +93,12 @@ "node": ">=10" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/vscode-jsonrpc": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz", @@ -112,6 +146,31 @@ } }, "dependencies": { + "@types/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", + "dev": true, + "requires": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, + "@types/minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", + "dev": true + }, + "@types/node": { + "version": "20.14.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.2.tgz", + "integrity": "sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -149,6 +208,12 @@ "lru-cache": "^6.0.0" } }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "vscode-jsonrpc": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz", diff --git a/client/package.json b/client/package.json index b8b8e13..9b90320 100644 --- a/client/package.json +++ b/client/package.json @@ -23,5 +23,8 @@ "webpack": "webpack", "watch": "webpack --watch --progress", "test": "jest" + }, + "devDependencies": { + "@types/glob": "^8.1.0" } } diff --git a/client/src/commands/index.ts b/client/src/commands/index.ts index e903df1..3de261b 100644 --- a/client/src/commands/index.ts +++ b/client/src/commands/index.ts @@ -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 diff --git a/client/tests/e2e/runTests.ts b/client/tests/e2e/runTests.ts index c871f34..3d87e91 100644 --- a/client/tests/e2e/runTests.ts +++ b/client/tests/e2e/runTests.ts @@ -6,7 +6,7 @@ async function main(): Promise { 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 diff --git a/client/tests/e2e/suite/extension.ga.e2e.ts b/client/tests/e2e/suite/extension.ga.e2e.ts index 8cab3cd..1f387db 100644 --- a/client/tests/e2e/suite/extension.ga.e2e.ts +++ b/client/tests/e2e/suite/extension.ga.e2e.ts @@ -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"; @@ -22,7 +22,9 @@ 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"); @@ -30,6 +32,7 @@ suite("Native (JSON) Workflows", () => { const actualCleanJson = document.getText(); assert.notEqual(dirtyDoc, actualCleanJson); const expectedCleanDocument = await openDocument(cleanDocUri); + assert.ok(expectedCleanDocument); const expectedCleanJson = expectedCleanDocument.getText(); assert.strictEqual(actualCleanJson, expectedCleanJson); }); diff --git a/client/tests/e2e/suite/helpers.ts b/client/tests/e2e/suite/helpers.ts index 29edd10..939ac28 100644 --- a/client/tests/e2e/suite/helpers.ts +++ b/client/tests/e2e/suite/helpers.ts @@ -12,11 +12,11 @@ export interface DocumentEditor { export async function activate(): Promise { 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 { +export async function openDocumentInEditor(docUri: vscode.Uri): Promise { try { const document = await vscode.workspace.openTextDocument(docUri); const editor = await vscode.window.showTextDocument(document); @@ -29,16 +29,18 @@ export async function openDocumentInEditor(docUri: vscode.Uri): Promise { +export async function openDocument(docUri: vscode.Uri): Promise { 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 { +export async function activateAndOpenInEditor(docUri: vscode.Uri): Promise { await activate(); const documentEditor = await openDocumentInEditor(docUri); return documentEditor; diff --git a/client/tests/e2e/tsconfig.json b/client/tests/e2e/tsconfig.json new file mode 100644 index 0000000..e5954c9 --- /dev/null +++ b/client/tests/e2e/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es2019", + "lib": ["ES2019", "WebWorker"], + "module": "commonjs", + "sourceMap": true, + "strict": true, + "baseUrl": ".", + "skipLibCheck": true + } +} diff --git a/client/tsconfig.json b/client/tsconfig.json index c7417ce..4c4d44d 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -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"], diff --git a/package.json b/package.json index 17b3e5e..b76536f 100644 --- a/package.json +++ b/package.json @@ -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"