From bbbaa477e8761c1809a97d111222168d6a36fa0b Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 17 Jun 2022 19:40:19 +0200 Subject: [PATCH] Move unit tests to related project --- package.json | 10 +++- server/gx-workflow-ls-format2/package.json | 6 ++- .../jest.config.js | 0 server/gx-workflow-ls-native/package.json | 8 ++- .../tests}/testHelpers.ts | 4 +- .../tests/testWorkflowProvider.ts | 4 +- .../tests/unit}/customValidationRules.test.ts | 12 ++--- .../tests/unit}/jsonUtils.test.ts | 2 +- .../unit}/nativeWorkflowDocument.test.ts | 8 +-- server/gx-workflow-ls-native/tsconfig.json | 5 +- server/package-lock.json | 50 ++++++++++++------- server/package.json | 12 ++--- 12 files changed, 72 insertions(+), 49 deletions(-) rename server/{ => gx-workflow-ls-native}/jest.config.js (100%) rename server/{tests/unit => gx-workflow-ls-native/tests}/testHelpers.ts (84%) rename server/{ => gx-workflow-ls-native}/tests/testWorkflowProvider.ts (92%) rename server/{tests/unit/nativeServer => gx-workflow-ls-native/tests/unit}/customValidationRules.test.ts (77%) rename server/{tests/unit/nativeServer => gx-workflow-ls-native/tests/unit}/jsonUtils.test.ts (98%) rename server/{tests/unit/nativeServer => gx-workflow-ls-native/tests/unit}/nativeWorkflowDocument.test.ts (63%) diff --git a/package.json b/package.json index 962c8b8..5f4f2c5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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 } } diff --git a/server/gx-workflow-ls-format2/package.json b/server/gx-workflow-ls-format2/package.json index 382db99..9db4126 100644 --- a/server/gx-workflow-ls-format2/package.json +++ b/server/gx-workflow-ls-format2/package.json @@ -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": {} diff --git a/server/jest.config.js b/server/gx-workflow-ls-native/jest.config.js similarity index 100% rename from server/jest.config.js rename to server/gx-workflow-ls-native/jest.config.js diff --git a/server/gx-workflow-ls-native/package.json b/server/gx-workflow-ls-native/package.json index 9be72da..a2c1db9 100644 --- a/server/gx-workflow-ls-native/package.json +++ b/server/gx-workflow-ls-native/package.json @@ -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", diff --git a/server/tests/unit/testHelpers.ts b/server/gx-workflow-ls-native/tests/testHelpers.ts similarity index 84% rename from server/tests/unit/testHelpers.ts rename to server/gx-workflow-ls-native/tests/testHelpers.ts index c059299..92cf987 100644 --- a/server/tests/unit/testHelpers.ts +++ b/server/gx-workflow-ls-native/tests/testHelpers.ts @@ -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); diff --git a/server/tests/testWorkflowProvider.ts b/server/gx-workflow-ls-native/tests/testWorkflowProvider.ts similarity index 92% rename from server/tests/testWorkflowProvider.ts rename to server/gx-workflow-ls-native/tests/testWorkflowProvider.ts index 7b94c6f..8486b42 100644 --- a/server/tests/testWorkflowProvider.ts +++ b/server/gx-workflow-ls-native/tests/testWorkflowProvider.ts @@ -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. */ @@ -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; } } diff --git a/server/tests/unit/nativeServer/customValidationRules.test.ts b/server/gx-workflow-ls-native/tests/unit/customValidationRules.test.ts similarity index 77% rename from server/tests/unit/nativeServer/customValidationRules.test.ts rename to server/gx-workflow-ls-native/tests/unit/customValidationRules.test.ts index 295aeaf..95d53ef 100644 --- a/server/tests/unit/nativeServer/customValidationRules.test.ts +++ b/server/gx-workflow-ls-native/tests/unit/customValidationRules.test.ts @@ -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", () => { @@ -11,20 +11,20 @@ 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); @@ -32,7 +32,7 @@ describe("Custom Validation Rules", () => { 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); diff --git a/server/tests/unit/nativeServer/jsonUtils.test.ts b/server/gx-workflow-ls-native/tests/unit/jsonUtils.test.ts similarity index 98% rename from server/tests/unit/nativeServer/jsonUtils.test.ts rename to server/gx-workflow-ls-native/tests/unit/jsonUtils.test.ts index a6aab02..f9790ea 100644 --- a/server/tests/unit/nativeServer/jsonUtils.test.ts +++ b/server/gx-workflow-ls-native/tests/unit/jsonUtils.test.ts @@ -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", () => { diff --git a/server/tests/unit/nativeServer/nativeWorkflowDocument.test.ts b/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts similarity index 63% rename from server/tests/unit/nativeServer/nativeWorkflowDocument.test.ts rename to server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts index 0d0e550..feca4ee 100644 --- a/server/tests/unit/nativeServer/nativeWorkflowDocument.test.ts +++ b/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts @@ -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(); diff --git a/server/gx-workflow-ls-native/tsconfig.json b/server/gx-workflow-ls-native/tsconfig.json index a359936..a2c3b2d 100644 --- a/server/gx-workflow-ls-native/tsconfig.json +++ b/server/gx-workflow-ls-native/tsconfig.json @@ -8,6 +8,7 @@ "esModuleInterop": true, "sourceMap": true, "strict": true, - "rootDirs": ["src"] - } + "rootDirs": ["src", "tests"] + }, + "include": ["src/**/*.ts", "tests/**/*.ts"] } diff --git a/server/package-lock.json b/server/package-lock.json index 9be0a20..36cc5ff 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -12,22 +12,18 @@ "gx-workflow-ls-format2", "gx-workflow-ls-native", "packages/*" - ], - "dependencies": { - "jsonc-parser": "^3.0.0", - "vscode-json-languageservice": "^4.2.1", - "vscode-languageserver": "^7.0.0", - "vscode-languageserver-textdocument": "^1.0.4", - "vscode-languageserver-types": "^3.16.0", - "vscode-uri": "^3.0.3" - } + ] }, "gx-workflow-ls-format2": { "version": "0.1.0", "license": "MIT", "dependencies": { "@gxwf/server-common": "*", - "@gxwf/yaml-language-service": "*" + "@gxwf/yaml-language-service": "*", + "vscode-languageserver": "^7.0.0", + "vscode-languageserver-textdocument": "^1.0.4", + "vscode-languageserver-types": "^3.16.0", + "vscode-uri": "^3.0.3" }, "devDependencies": {} }, @@ -35,7 +31,13 @@ "version": "0.1.0", "license": "MIT", "dependencies": { - "@gxwf/server-common": "*" + "@gxwf/server-common": "*", + "jsonc-parser": "^3.0.0", + "vscode-json-languageservice": "^4.2.1", + "vscode-languageserver": "^7.0.0", + "vscode-languageserver-textdocument": "^1.0.4", + "vscode-languageserver-types": "^3.16.0", + "vscode-uri": "^3.0.3" } }, "node_modules/@gxwf/server-common": { @@ -115,9 +117,9 @@ "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" }, "node_modules/vscode-nls": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.0.tgz", - "integrity": "sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.1.tgz", + "integrity": "sha512-hHQV6iig+M21lTdItKPkJAaWrxALQb/nqpVffakO4knJOh3DrU2SXOMzUzNgo1eADPzu3qSsJY1weCzvR52q9A==" }, "node_modules/vscode-uri": { "version": "3.0.3", @@ -182,13 +184,23 @@ "version": "file:gx-workflow-ls-format2", "requires": { "@gxwf/server-common": "*", - "@gxwf/yaml-language-service": "*" + "@gxwf/yaml-language-service": "*", + "vscode-languageserver": "^7.0.0", + "vscode-languageserver-textdocument": "^1.0.4", + "vscode-languageserver-types": "^3.16.0", + "vscode-uri": "^3.0.3" } }, "gx-workflow-ls-native": { "version": "file:gx-workflow-ls-native", "requires": { - "@gxwf/server-common": "*" + "@gxwf/server-common": "*", + "jsonc-parser": "^3.0.0", + "vscode-json-languageservice": "^4.2.1", + "vscode-languageserver": "^7.0.0", + "vscode-languageserver-textdocument": "^1.0.4", + "vscode-languageserver-types": "^3.16.0", + "vscode-uri": "^3.0.3" } }, "jsonc-parser": { @@ -241,9 +253,9 @@ "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" }, "vscode-nls": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.0.tgz", - "integrity": "sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.1.tgz", + "integrity": "sha512-hHQV6iig+M21lTdItKPkJAaWrxALQb/nqpVffakO4knJOh3DrU2SXOMzUzNgo1eADPzu3qSsJY1weCzvR52q9A==" }, "vscode-uri": { "version": "3.0.3", diff --git a/server/package.json b/server/package.json index b17db8e..47ed7d1 100644 --- a/server/package.json +++ b/server/package.json @@ -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",