Skip to content

Commit

Permalink
Move unit tests to related project
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 18, 2022
1 parent 6522261 commit bbbaa47
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 49 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
},
"scripts": {
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
"lint": "eslint ./client/src ./server/src --ext .ts,.tsx",
"lint": "eslint ./client/src ./server --ext .ts,.tsx",
"format": "prettier --write .",
"clean": "rimraf client/dist && rimraf server/dist",
"compile-servers": "cd server && npm run compile",
Expand All @@ -213,7 +213,7 @@
"watch": "concurrently --kill-others \"npm run watch-server\" \"npm run watch-client\"",
"watch-server": "cd server && npm run watch",
"watch-client": "cd client && npm run watch",
"test": "jest",
"test": "npm run test-unit-client && npm run test-unit-server",
"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",
Expand Down Expand Up @@ -245,5 +245,11 @@
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
"__metadata": {
"id": "2306ad21-fa2c-46f9-bba8-a22e32c7cb9a",
"publisherDisplayName": "davelopez",
"publisherId": "b10132ef-3f96-4db4-acb0-d6a0ca1848c7",
"isPreReleaseVersion": false
}
}
6 changes: 5 additions & 1 deletion server/gx-workflow-ls-format2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"license": "MIT",
"dependencies": {
"@gxwf/server-common": "*",
"@gxwf/yaml-language-service": "*"
"@gxwf/yaml-language-service": "*",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-languageserver-types": "^3.16.0",
"vscode-languageserver": "^7.0.0",
"vscode-uri": "^3.0.3"
},
"devDependencies": {},
"scripts": {}
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion server/gx-workflow-ls-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
"author": "davelopez",
"license": "MIT",
"dependencies": {
"@gxwf/server-common": "*"
"@gxwf/server-common": "*",
"jsonc-parser": "^3.0.0",
"vscode-json-languageservice": "^4.2.1",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-languageserver-types": "^3.16.0",
"vscode-languageserver": "^7.0.0",
"vscode-uri": "^3.0.3"
},
"scripts": {
"webpack": "webpack",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ASTNode, getLanguageService, JSONDocument } from "vscode-json-languageservice";
import { TextDocument } from "../../src/common/languageTypes";
import { NativeWorkflowDocument } from "../../src/nativeServer/nativeWorkflowDocument";
import { TextDocument } from "@gxwf/server-common/src/languageTypes";
import { NativeWorkflowDocument } from "../src/nativeWorkflowDocument";

export function toJsonDocument(contents: string): { textDoc: TextDocument; jsonDoc: JSONDocument } {
const textDoc = TextDocument.create("foo://bar/file.json", "json", 0, contents);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import * as path from "path";

const TEST_DATA_PATH = path.join(__dirname, "..", "..", "test-data");
const TEST_DATA_PATH = path.join(__dirname, "..", "..", "..", "test-data");

interface TestJsonWorkflows {
/** Workflows for testing validation issues. */
Expand Down Expand Up @@ -37,7 +37,7 @@ export class TestWorkflowProvider {
};

/** Workflows in native JSON format. */
public static get nativeJson(): TestJsonWorkflows {
public static get workflows(): TestJsonWorkflows {
return this._jsonWorkflows;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createNativeWorkflowDocument } from "../testHelpers";
import { WorkflowOutputLabelValidation } from "../../../src/common/providers/validation/WorkflowOutputLabelValidation";
import { TestWorkflowProvider } from "../../testWorkflowProvider";
import { WorkflowOutputLabelValidation } from "@gxwf/server-common/src/providers/validation/WorkflowOutputLabelValidation";
import { TestWorkflowProvider } from "../testWorkflowProvider";

describe("Custom Validation Rules", () => {
describe("WorkflowOutputLabelValidation Rule", () => {
Expand All @@ -11,28 +11,28 @@ describe("Custom Validation Rules", () => {
});

it("should not provide diagnostics when there are no steps", async () => {
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.nativeJson.validation.withoutSteps);
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.workflows.validation.withoutSteps);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});

it("should not provide diagnostics when there are no workflow_outputs in the steps", async () => {
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.nativeJson.validation.withThreeSteps);
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.workflows.validation.withThreeSteps);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});

it("should not provide diagnostics when the steps contains workflow_outputs with label", async () => {
const wfDocument = createNativeWorkflowDocument(
TestWorkflowProvider.nativeJson.validation.withWorkflowOutputLabels
TestWorkflowProvider.workflows.validation.withWorkflowOutputLabels
);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});

it("should provide diagnostics when the steps contains workflow_outputs without label", async () => {
const wfDocument = createNativeWorkflowDocument(
TestWorkflowProvider.nativeJson.validation.withoutWorkflowOutputLabels
TestWorkflowProvider.workflows.validation.withoutWorkflowOutputLabels
);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTNode, PropertyASTNode } from "vscode-json-languageservice";
import { getPathSegments, getPropertyNodeFromPath } from "../../../src/nativeServer/jsonUtils";
import { getPathSegments, getPropertyNodeFromPath } from "../../src/jsonUtils";
import { getJsonDocumentRoot } from "../testHelpers";

describe("JSON Utility Functions", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createNativeWorkflowDocument } from "../testHelpers";
import { TestWorkflowProvider } from "../../testWorkflowProvider";
import { TestWorkflowProvider } from "../testWorkflowProvider";

describe("NativeWorkflowDocument", () => {
describe("getStepNodes", () => {
it.each([
["", 0],
[TestWorkflowProvider.nativeJson.validation.withoutSteps, 0],
[TestWorkflowProvider.nativeJson.validation.withOneStep, 1],
[TestWorkflowProvider.nativeJson.validation.withThreeSteps, 3],
[TestWorkflowProvider.workflows.validation.withoutSteps, 0],
[TestWorkflowProvider.workflows.validation.withOneStep, 1],
[TestWorkflowProvider.workflows.validation.withThreeSteps, 3],
])("returns the expected number of steps", (wf_content: string, expectedNumSteps: number) => {
const wfDocument = createNativeWorkflowDocument(wf_content);
const stepNodes = wfDocument.getStepNodes();
Expand Down
5 changes: 3 additions & 2 deletions server/gx-workflow-ls-native/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"esModuleInterop": true,
"sourceMap": true,
"strict": true,
"rootDirs": ["src"]
}
"rootDirs": ["src", "tests"]
},
"include": ["src/**/*.ts", "tests/**/*.ts"]
}
50 changes: 31 additions & 19 deletions server/package-lock.json

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

12 changes: 3 additions & 9 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
"version": "0.1.0",
"author": "davelopez",
"license": "MIT",
"dependencies": {
"jsonc-parser": "^3.0.0",
"vscode-languageserver": "^7.0.0",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-languageserver-types": "^3.16.0",
"vscode-json-languageservice": "^4.2.1",
"vscode-uri": "^3.0.3"
},
"scripts": {
"compile-native-server": "webpack --config ./gx-workflow-ls-native/webpack.config.js",
"compile-format2-server": "webpack --config ./gx-workflow-ls-format2/webpack.config.js",
"compile": "npm run compile-native-server && npm run compile-format2-server",
"watch-native-server": "webpack --watch --progress --config ./gx-workflow-ls-native/webpack.config.js",
"watch-format2-server": "webpack --watch --progress --config ./gx-workflow-ls-format2/webpack.config.js",
"watch": "concurrently --kill-others \"npm run watch-format2-server\" \"npm run watch-native-server\""
"watch": "concurrently --kill-others \"npm run watch-format2-server\" \"npm run watch-native-server\"",
"test-unit-native": "cd gx-workflow-ls-native && npm run test-unit && cd ..",
"test-unit": "npm run test-unit-native"
},
"workspaces": [
"gx-workflow-ls-format2",
Expand Down

0 comments on commit bbbaa47

Please sign in to comment.