-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from davelopez/fix_clean_workflow
Fix clean workflow
- Loading branch information
Showing
11 changed files
with
371 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.