From 829eabc2d6cfd980b19f8c246d20b5f86d33fd4f Mon Sep 17 00:00:00 2001 From: Michael Daines Date: Thu, 7 Sep 2023 13:48:22 -0400 Subject: [PATCH] Split type check tests into separate files --- packages/viz/test/types/graph-objects.ts | 106 ++++++++++++++ packages/viz/test/types/index.ts | 171 ---------------------- packages/viz/test/types/package.json | 2 +- packages/viz/test/types/render-options.ts | 47 ++++++ packages/viz/test/types/render-result.ts | 45 ++++++ packages/viz/test/types/top-level.ts | 23 +++ packages/viz/test/types/viz.ts | 35 +++++ 7 files changed, 257 insertions(+), 172 deletions(-) create mode 100644 packages/viz/test/types/graph-objects.ts delete mode 100644 packages/viz/test/types/index.ts create mode 100644 packages/viz/test/types/render-options.ts create mode 100644 packages/viz/test/types/render-result.ts create mode 100644 packages/viz/test/types/top-level.ts create mode 100644 packages/viz/test/types/viz.ts diff --git a/packages/viz/test/types/graph-objects.ts b/packages/viz/test/types/graph-objects.ts new file mode 100644 index 00000000..4311215f --- /dev/null +++ b/packages/viz/test/types/graph-objects.ts @@ -0,0 +1,106 @@ +import { instance } from "@viz-js/viz"; + +instance().then(viz => { + viz.render({}); + + viz.render({ + edges: [ + { tail: "a", head: "b" } + ] + }); + + viz.render({ + directed: false, + strict: false, + name: "G", + graphAttributes: { + label: "Test" + }, + edgeAttributes: { + color: "green" + }, + nodeAttributes: { + shape: "circle" + }, + nodes: [ + { name: "a", attributes: { label: "A" } } + ], + edges: [ + { tail: "a", head: "b", attributes: { label: "test" } } + ], + subgraphs: [ + { + name: "cluster1", + graphAttributes: { + color: "green" + }, + edgeAttributes: { + color: "blue" + }, + nodeAttributes: { + color: "red" + }, + subgraphs: [ + { + nodes: [ + { name: "b" } + ] + } + ] + } + ] + }); + + viz.render({ + graphAttributes: { + width: 2, + abc: true, + label: { html: "test" } + }, + nodes: [ + { + name: "a", + attributes: { + width: 2, + abc: true, + label: { html: "test" } + } + } + ] + }); + + viz.render({ + graphAttributes: { + // @ts-expect-error + blah: null + } + }); + + viz.render({ + graphAttributes: { + // @ts-expect-error + label: { stuff: "abc" } + } + }); + + viz.render({ + subgraphs: [ + { + // @ts-expect-error + directed: false + } + ] + }); + + viz.render({ + subgraphs: [ + { + // @ts-expect-error + strict: true + } + ] + }); + + // @ts-expect-error + viz.render({ a: "b" }); +}); diff --git a/packages/viz/test/types/index.ts b/packages/viz/test/types/index.ts deleted file mode 100644 index 267c1cc5..00000000 --- a/packages/viz/test/types/index.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { instance, graphvizVersion, formats, engines, type RenderOptions, type RenderResult, type RenderError } from "@viz-js/viz"; - -// @ts-expect-error -import { Viz } from "@viz-js/viz"; - -// @ts-expect-error -import { type Viz } from "@viz-js/viz"; - -// @ts-expect-error -import { type SuccessResult } from "@viz-js/viz"; - -// @ts-expect-error -import { type FailureResult } from "@viz-js/viz"; - -let version: string = graphvizVersion; - -let supportedEngines: Array = engines; - -let supportedFormats: Array = formats; - -instance().then(viz => { - let options: RenderOptions = {}; - - options.format = "dot"; - options.engine = "dot"; - options.yInvert = true; - options.graphAttributes = { rankdir: "LR" }; - options.nodeAttributes = { width: 2 }; - options.edgeAttributes = { color: "green" }; - - // @ts-expect-error - options.format = false; - - // @ts-expect-error - options.engine = 123; - - // @ts-expect-error - options.yInvert = 1; - - // @ts-expect-error - options.whatever = 123; - - let result: RenderResult; - - result = viz.render("digraph { a -> b }"); - - result = viz.render("digraph { a -> b }", { format: "svg" }); - - result = viz.render("digraph { a -> b }", { format: "svg", engine: "dot", yInvert: false }); - - result = viz.render("digraph { a -> b }", { nodeAttributes: { shape: "circle" } }); - - result = viz.render({}); - - result = viz.render({ - edges: [ - { tail: "a", head: "b" } - ] - }); - result = viz.render({ - directed: false, - strict: false, - name: "G", - nodeAttributes: { - shape: "circle" - }, - graphAttributes: { - label: "Test" - }, - nodes: [ - { name: "a", attributes: { label: "A" } } - ], - edges: [ - { tail: "a", head: "b" } - ], - subgraphs: [ - { - name: "cluster1", - edgeAttributes: { - color: "blue" - }, - graphAttributes: { - color: "green" - }, - subgraphs: [ - { - nodes: [ - { name: "b" } - ] - } - ] - } - ] - }); - - result = viz.render({ - graphAttributes: { - width: 2, - abc: true, - label: { html: "test" } - }, - nodes: [ - { - name: "a", - attributes: { - width: 2, - abc: true, - label: { html: "test" } - } - } - ] - }); - - result = viz.render({ - graphAttributes: { - // @ts-expect-error - blah: null, - // @ts-expect-error - label: { stuff: "abc" } - } - }); - - // @ts-expect-error - result = viz.render({ a: "b" }); - - switch (result.status) { - case "success": - { - let output: string = result.output; - break; - } - - case "failure": - { - // @ts-expect-error - let output: string = result.output; - break; - } - - // @ts-expect-error - case "invalid": - break; - } - - let errorMessages: Array = result.errors.filter(error => error.level == "error").map(error => error.message); - - // @ts-expect-error - let invalidLevelMessages: Array = result.errors.filter(error => error.level == "invalid").map(error => error.message); - - // @ts-expect-error - result = viz.render("digraph { a -> b }", { format: false }); - - // @ts-expect-error - result = viz.render("digraph { a -> b }", { engine: 123 }); - - // @ts-expect-error - result = viz.render("digraph { a -> b }", { yInvert: 1 }); - - // @ts-expect-error - result = viz.render("digraph { a -> b }", { whatever: 123 }); - - let stringResult: string = viz.renderString("digraph { a -> b }"); - - let svgElementResult: SVGSVGElement = viz.renderSVGElement("digraph { a -> b }"); - - let version: string = viz.graphvizVersion; - - let supportedEngines: Array = viz.engines; - - let supportedFormats: Array = viz.formats; -}); diff --git a/packages/viz/test/types/package.json b/packages/viz/test/types/package.json index e1e9dfec..f79306a4 100644 --- a/packages/viz/test/types/package.json +++ b/packages/viz/test/types/package.json @@ -5,6 +5,6 @@ "typescript": "^5.1.3" }, "scripts": { - "check-types": "tsc --strict --lib es2015,dom --noEmit index.ts" + "check-types": "tsc --strict --lib es2015,dom --noEmit *.ts" } } diff --git a/packages/viz/test/types/render-options.ts b/packages/viz/test/types/render-options.ts new file mode 100644 index 00000000..5260e281 --- /dev/null +++ b/packages/viz/test/types/render-options.ts @@ -0,0 +1,47 @@ +import { type RenderOptions } from "@viz-js/viz"; + +let options: RenderOptions = {}; + +options.format = "svg"; + +options.engine = "dot"; + +options.yInvert = true; + +options.reduce = true; + +options.graphAttributes = { + rankdir: "LR", + width: 2, + label: { html: "test" }, + test: true +}; + +options.nodeAttributes = { + rankdir: "LR", + width: 2, + label: { html: "test" }, + test: true +}; + +options.edgeAttributes = { + rankdir: "LR", + width: 2, + label: { html: "test" }, + test: true +}; + +// @ts-expect-error +options.format = false; + +// @ts-expect-error +options.engine = 123; + +// @ts-expect-error +options.yInvert = 1; + +// @ts-expect-error +options.whatever = 123; + +// @ts-expect-error +options.graphAttributes = { something: { whatever: 123 } }; diff --git a/packages/viz/test/types/render-result.ts b/packages/viz/test/types/render-result.ts new file mode 100644 index 00000000..a28f486a --- /dev/null +++ b/packages/viz/test/types/render-result.ts @@ -0,0 +1,45 @@ +import { instance, type RenderResult, type RenderError } from "@viz-js/viz"; + +instance().then(viz => { + let result: RenderResult = viz.render("digraph { a -> b }"); + + switch (result.status) { + case "success": + { + let output: string = result.output; + break; + } + + case "failure": + { + // @ts-expect-error + let output: string = result.output; + break; + } + + // @ts-expect-error + case "invalid": + break; + } + + let error: RenderError | undefined = result.errors[0]; + + if (typeof error !== "undefined") { + let message: string = error.message; + + switch (error.level) { + case "error": + break; + + case "warning": + break; + + case undefined: + break; + + // @ts-expect-error + case "invalid": + break; + } + } +}); diff --git a/packages/viz/test/types/top-level.ts b/packages/viz/test/types/top-level.ts new file mode 100644 index 00000000..d1d7e530 --- /dev/null +++ b/packages/viz/test/types/top-level.ts @@ -0,0 +1,23 @@ +import { instance, graphvizVersion, formats, engines, type RenderOptions, type RenderResult, type RenderError } from "@viz-js/viz"; + +// @ts-expect-error +import { Viz } from "@viz-js/viz"; + +// @ts-expect-error +import { type Viz } from "@viz-js/viz"; + +// @ts-expect-error +import { type SuccessResult } from "@viz-js/viz"; + +// @ts-expect-error +import { type FailureResult } from "@viz-js/viz"; + +let version: string = graphvizVersion; + +let supportedEngines: Array = engines; + +let supportedFormats: Array = formats; + +instance().then(viz => { + viz.render("digraph { a -> b }"); +}); diff --git a/packages/viz/test/types/viz.ts b/packages/viz/test/types/viz.ts new file mode 100644 index 00000000..95cb1ca6 --- /dev/null +++ b/packages/viz/test/types/viz.ts @@ -0,0 +1,35 @@ +import { instance } from "@viz-js/viz"; + +instance().then(viz => { + viz.render("digraph { a -> b }"); + + viz.render("digraph { a -> b }", { format: "svg" }); + + viz.render("digraph { a -> b }", { format: "svg", engine: "dot", yInvert: false }); + + viz.render("digraph { a -> b }", { nodeAttributes: { shape: "circle" } }); + + viz.render({ edges: [{ tail: "a", head: "b" }] }); + + // @ts-expect-error + viz.render("digraph { a -> b }", { format: false }); + + // @ts-expect-error + viz.render("digraph { a -> b }", { engine: 123 }); + + // @ts-expect-error + viz.render("digraph { a -> b }", { yInvert: 1 }); + + // @ts-expect-error + viz.render("digraph { a -> b }", { whatever: 123 }); + + let stringResult: string = viz.renderString("digraph { a -> b }"); + + let svgElementResult: SVGSVGElement = viz.renderSVGElement("digraph { a -> b }"); + + let version: string = viz.graphvizVersion; + + let supportedEngines: Array = viz.engines; + + let supportedFormats: Array = viz.formats; +});