Skip to content

Commit

Permalink
Add basic gxformat2 schema support
Browse files Browse the repository at this point in the history
Explore gxformat2 schema support
  • Loading branch information
davelopez authored Oct 8, 2022
2 parents 2a2a9ca + 4829c80 commit b3978df
Show file tree
Hide file tree
Showing 46 changed files with 6,037 additions and 2,093 deletions.
7 changes: 5 additions & 2 deletions client/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

/* eslint-disable @typescript-eslint/no-var-requires */
const { compilerOptions } = require("./tsconfig.json");

module.exports = {
preset: "ts-jest",
globals: {
"ts-jest": {
tsconfig: "../tsconfig.json",
tsconfig: compilerOptions,
},
},
// The glob patterns Jest uses to detect test files
testMatch: ["**/__tests__/*.+(ts|tsx|js)", "**/unit/*.test.ts"],
testMatch: ["**/__tests__/*.+(ts|tsx|js)", "**/*.test.ts"],

// An array of file extensions your modules use
moduleFileExtensions: ["ts", "tsx", "js"],
Expand Down
74 changes: 0 additions & 74 deletions client/tests/e2e/suite/extension.e2e.ts

This file was deleted.

73 changes: 73 additions & 0 deletions client/tests/e2e/suite/extension.ga.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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 {
activateAndOpenInEditor,
getDocUri,
closeAllEditors,
openDocument,
sleep,
assertDiagnostics,
updateSettings,
resetSettings,
waitForDiagnostics,
} from "./helpers";

suite("Native (JSON) Workflows", () => {
teardown(closeAllEditors);
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);
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);
const expectedCleanJson = expectedCleanDocument.getText();
assert.strictEqual(actualCleanJson, expectedCleanJson);
});
});

suite("Validation Tests", () => {
beforeEach(async () => {
await resetSettings();
});
test("Changing validation profile shows custom diagnostics", async () => {
const docUri = getDocUri(path.join("json", "validation", "test_wf_03.ga"));
await activateAndOpenInEditor(docUri);
await assertDiagnostics(docUri, []); // Expect no issues

// Change to stricter validation profile
await updateSettings("validation.profile", "iwc");
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, [
{
message: 'Missing property "release".',
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 1)),
severity: vscode.DiagnosticSeverity.Error,
},
{
message: "Missing label in workflow output.",
range: new vscode.Range(new vscode.Position(16, 16), new vscode.Position(19, 17)),
severity: vscode.DiagnosticSeverity.Error,
},
{
message: "Missing label in workflow output.",
range: new vscode.Range(new vscode.Position(20, 16), new vscode.Position(23, 17)),
severity: vscode.DiagnosticSeverity.Error,
},
]);

await resetSettings();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, []); // Expect no issues
});
});
});
45 changes: 45 additions & 0 deletions client/tests/e2e/suite/extension.gxformat2.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 {
activateAndOpenInEditor,
getDocUri,
closeAllEditors,
assertDiagnostics,
resetSettings,
waitForDiagnostics,
} from "./helpers";

suite("Format2 (YAML) Workflows", () => {
teardown(closeAllEditors);
suite("Validation Tests", () => {
beforeEach(async () => {
await resetSettings();
});
test("Missing required fields return diagnostics", async () => {
const docUri = getDocUri(path.join("yaml", "validation", "test_wf_00.gxwf.yml"));
await activateAndOpenInEditor(docUri);
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, [
{
message: "The 'steps' field is required.",
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 21)),
severity: vscode.DiagnosticSeverity.Error,
},
{
message: "The 'inputs' field is required.",
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 21)),
severity: vscode.DiagnosticSeverity.Error,
},
{
message: "The 'outputs' field is required.",
range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 21)),
severity: vscode.DiagnosticSeverity.Error,
},
]);
});
});
});
15 changes: 13 additions & 2 deletions client/tests/e2e/suite/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ export async function openDocument(docUri: vscode.Uri): Promise<vscode.TextDocum
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 async function waitForDiagnostics(docUri: vscode.Uri, timeoutInMilliseconds = 2000): Promise<void> {
const waitMilliseconds = 100;
let waitTimeout = timeoutInMilliseconds;
let diagnostics = vscode.languages.getDiagnostics(docUri);
while (waitTimeout > 0 && !diagnostics.length) {
await sleep(waitMilliseconds);
waitTimeout -= waitMilliseconds;
diagnostics = vscode.languages.getDiagnostics(docUri);
}
}

export const getDocPath = (filePath: string): string => {
return path.resolve(__dirname, path.join("..", "..", "..", "..", "test-data", filePath));
};
Expand Down Expand Up @@ -92,5 +102,6 @@ export async function updateSettings(setting: string, value: unknown): Promise<v
export async function resetSettings(): Promise<void> {
const configuration = vscode.workspace.getConfiguration("galaxyWorkflows");
await configuration.update("cleaning.cleanableProperties", undefined, true);
return configuration.update("validation.profile", undefined, true);
await configuration.update("validation.profile", undefined, true);
return sleep(500); // Wait for settings to be applied
}
15 changes: 12 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

/* eslint-disable @typescript-eslint/no-var-requires */
const { pathsToModuleNameMapper } = require("ts-jest");
const { compilerOptions } = require("./tsconfig.json");

module.exports = {
preset: "ts-jest",
globals: {
"ts-jest": {
tsconfig: "tsconfig.json",
tsconfig: compilerOptions,
},
},
// The glob patterns Jest uses to detect test files
testMatch: ["**/__tests__/*.+(ts|tsx|js)", "**/unit/*.test.ts"],
testMatch: ["**/__tests__/*.+(ts|tsx|js)", "**/*.test.ts"],

// An array of file extensions your modules use
moduleFileExtensions: ["ts", "tsx", "js"],
moduleFileExtensions: ["ts", "tsx", "js", "yaml"],
transform: {
// ... other transforms ...
"\\.yaml$": "jest-transform-yaml",
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/" }),
};
Loading

0 comments on commit b3978df

Please sign in to comment.