Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clean workflow #39

Merged
merged 7 commits into from
May 16, 2022
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
4 changes: 2 additions & 2 deletions client/tests/e2e/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as path from "path";

import { runTests } from "@vscode/test-electron";

async function main() {
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
27 changes: 20 additions & 7 deletions client/tests/e2e/suite/extension.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import * as assert from "assert";

// 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 myExtension from '../../extension';
import * as path from "path";
import * as assert from "assert";
import { activateAndOpenInEditor, getDocUri, closeAllEditors, openDocument, sleep } from "./helpers";

suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test("Sample test", () => {
assert.strictEqual([1, 2, 3].indexOf(5), -1);
teardown(closeAllEditors);
suite("Native (JSON) Workflows", () => {
suite("Commands Tests", () => {
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 dirtyDoc = document.getText();
await vscode.commands.executeCommand("galaxy-workflows.cleanWorkflow");
await sleep(1000); // Wait for command to apply changes
const actualCleanJson = document.getText();
assert.notEqual(dirtyDoc, actualCleanJson);
const expectedCleanDocument = await openDocument(cleanDocUri);
const expectedCleanJson = expectedCleanDocument.getText();
assert.strictEqual(actualCleanJson, expectedCleanJson);
});
});
});
});
84 changes: 84 additions & 0 deletions client/tests/e2e/suite/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as vscode from "vscode";
import * as path from "path";
import * as assert from "assert";

/**
* Contains the document and its corresponding editor
*/
export interface DocumentEditor {
editor: vscode.TextEditor;
document: vscode.TextDocument;
}

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

export async function openDocumentInEditor(docUri: vscode.Uri): Promise<DocumentEditor> {
try {
const document = await vscode.workspace.openTextDocument(docUri);
const editor = await vscode.window.showTextDocument(document);
return {
editor,
document,
};
} catch (e) {
console.error(e);
}
}

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

export async function activateAndOpenInEditor(docUri: vscode.Uri): Promise<DocumentEditor> {
await activate();
const documentEditor = await openDocumentInEditor(docUri);
await sleep(2000); // Wait for server activation
return documentEditor;
}

export async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export const getDocPath = (filePath: string): string => {
return path.resolve(__dirname, path.join("..", "..", "..", "..", "test-data", filePath));
};

export const getDocUri = (filePath: string): vscode.Uri => {
return vscode.Uri.file(getDocPath(filePath));
};

export async function assertDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]): Promise<void> {
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);

assert.equal(actualDiagnostics.length, expectedDiagnostics.length);

expectedDiagnostics.forEach((expectedDiagnostic, i) => {
const actualDiagnostic = actualDiagnostics[i];
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
});
}

/**
* Asserts that the given workflow document has no diagnostics i.e. is valid.
* @param docUri Workflow document URI
*/
export async function assertValid(docUri: vscode.Uri): Promise<void> {
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
assert.equal(actualDiagnostics.length, 0);
}

export function closeAllEditors(): Thenable<unknown> {
return vscode.commands.executeCommand("workbench.action.closeAllEditors");
}
2 changes: 2 additions & 0 deletions client/tests/e2e/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export function run(): Promise<void> {
const mocha = new Mocha({
ui: "tdd",
color: true,
timeout: 60000,
inlineDiffs: true,
});

const testsRoot = path.resolve(__dirname, "..");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"test-unit-client": "cd client && npm run test-unit && cd ..",
"test-unit-server": "cd server && npm run test-unit && cd ..",
"test-compile": "tsc --project ./client --outDir client/out",
"pretest:e2e": "npm run test-compile",
"pretest:e2e": "npm run compile && npm run test-compile",
"test:e2e": "node ./client/out/e2e/runTests.js"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions server/src/commands/cleanWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export class CleanWorkflowCommand extends CustomCommand {
// Remove trailing comma in previous property node
const isLastNode = workflowDocument.isLastNodeInParent(node);
if (isLastNode) {
const previousNode = workflowDocument.getPreviousSiblingNode(node);
let previousNode = workflowDocument.getPreviousSiblingNode(node);
while (previousNode && nodesToRemove.includes(previousNode)) {
previousNode = workflowDocument.getPreviousSiblingNode(previousNode);
}
if (previousNode) {
const range = this.getFullNodeRange(workflowDocument.textDocument, previousNode);
const nodeText = workflowDocument.textDocument.getText(range);
Expand All @@ -132,10 +135,7 @@ export class CleanWorkflowCommand extends CustomCommand {
return result;
}

private getNonEssentialNodes(
workflowDocument: WorkflowDocument,
cleanablePropertyNames: Set<string>
): PropertyASTNode[] {
private getNonEssentialNodes(workflowDocument: WorkflowDocument, cleanablePropertyNames: Set<string>): ASTNode[] {
const root = workflowDocument.rootNode;
if (!root) {
return [];
Expand Down
71 changes: 71 additions & 0 deletions test-data/json/clean/wf_01_clean.ga
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"a_galaxy_workflow": "true",
"annotation": "This is a cool workflow",
"format-version": "0.1",
"license": "MIT",
"name": "Cool workflow",
"steps": {
"0": {
"annotation": "Some text",
"content_id": null,
"id": 0,
"input_connections": {},
"inputs": [
{
"description": "Some text",
"name": "The cool input"
}
],
"label": "The cool input",
"name": "Input dataset",
"outputs": [],
"tool_id": null,
"tool_state": "{\"optional\": false, \"tag\": \"\"}",
"tool_version": null,
"type": "data_input",
"workflow_outputs": [
{
"label": null,
"output_name": "output"
}
]
},
"1": {
"annotation": "",
"content_id": "wc_gnu",
"id": 1,
"input_connections": {
"input1": {
"id": 0,
"output_name": "output"
}
},
"inputs": [
{
"description": "runtime parameter for tool Line/Word/Character count",
"name": "input1"
}
],
"label": null,
"name": "Line/Word/Character count",
"outputs": [
{
"name": "out_file1",
"type": "tabular"
}
],
"post_job_actions": {},
"tool_id": "wc_gnu",
"tool_state": "{\"include_header\": \"true\", \"input1\": {\"__class__\": \"RuntimeValue\"}, \"options\": [\"lines\", \"words\", \"characters\"], \"__page__\": null, \"__rerun_remap_job_id__\": null}",
"tool_version": "1.0.0",
"type": "tool",
"workflow_outputs": [
{
"label": "Text Count Result",
"output_name": "out_file1"
}
]
}
},
"tags": []
}
99 changes: 99 additions & 0 deletions test-data/json/clean/wf_01_dirty.ga
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"a_galaxy_workflow": "true",
"annotation": "This is a cool workflow",
"format-version": "0.1",
"license": "MIT",
"name": "Cool workflow",
"steps": {
"0": {
"annotation": "Some text",
"content_id": null,
"errors": null,
"id": 0,
"input_connections": {},
"inputs": [
{
"description": "Some text",
"name": "The cool input"
}
],
"label": "The cool input",
"name": "Input dataset",
"outputs": [],
"position": {
"bottom": 610.28125,
"height": 61.78125,
"left": 824,
"right": 1024,
"top": 548.5,
"width": 200,
"x": 824,
"y": 548.5
},
"tool_id": null,
"tool_state": "{\"optional\": false, \"tag\": \"\"}",
"tool_version": null,
"type": "data_input",
"uuid": "f0019f6a-b5ee-476e-8e5f-11cd3bcfaccf",
"workflow_outputs": [
{
"label": null,
"output_name": "output",
"uuid": "2216c468-98e3-42f9-9174-1e4b65f07e8e"
}
]
},
"1": {
"annotation": "",
"content_id": "wc_gnu",
"errors": null,
"id": 1,
"input_connections": {
"input1": {
"id": 0,
"output_name": "output"
}
},
"inputs": [
{
"description": "runtime parameter for tool Line/Word/Character count",
"name": "input1"
}
],
"label": null,
"name": "Line/Word/Character count",
"outputs": [
{
"name": "out_file1",
"type": "tabular"
}
],
"position": {
"bottom": 781.453125,
"height": 133.953125,
"left": 1146,
"right": 1346,
"top": 647.5,
"width": 200,
"x": 1146,
"y": 647.5
},
"post_job_actions": {},
"tool_id": "wc_gnu",
"tool_state": "{\"include_header\": \"true\", \"input1\": {\"__class__\": \"RuntimeValue\"}, \"options\": [\"lines\", \"words\", \"characters\"], \"__page__\": null, \"__rerun_remap_job_id__\": null}",
"tool_version": "1.0.0",
"type": "tool",
"uuid": "1ca6f40f-7b65-46ae-a366-9592279a07cc",
"workflow_outputs": [
{
"label": "Text Count Result",
"output_name": "out_file1",
"uuid": "d9a1c36f-bb05-4dc8-b6d8-10b94ddffb77"
}
]
}
},
"tags": [],
"uuid": "1bcc69fb-e8ec-49db-bd60-c7ac7fa87838",
"version": 2
}
Loading