Skip to content

Commit

Permalink
Split type check tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaines committed Sep 7, 2023
1 parent 895d95a commit 829eabc
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 172 deletions.
106 changes: 106 additions & 0 deletions packages/viz/test/types/graph-objects.ts
Original file line number Diff line number Diff line change
@@ -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: "<b>test</b>" }
},
nodes: [
{
name: "a",
attributes: {
width: 2,
abc: true,
label: { html: "<b>test</b>" }
}
}
]
});

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" });
});
171 changes: 0 additions & 171 deletions packages/viz/test/types/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/viz/test/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
47 changes: 47 additions & 0 deletions packages/viz/test/types/render-options.ts
Original file line number Diff line number Diff line change
@@ -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: "<b>test</b>" },
test: true
};

options.nodeAttributes = {
rankdir: "LR",
width: 2,
label: { html: "<b>test</b>" },
test: true
};

options.edgeAttributes = {
rankdir: "LR",
width: 2,
label: { html: "<b>test</b>" },
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 } };
45 changes: 45 additions & 0 deletions packages/viz/test/types/render-result.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
});
Loading

0 comments on commit 829eabc

Please sign in to comment.