-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for multiple output formats
- Loading branch information
Showing
6 changed files
with
144 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { instance } from "../../src/standalone.mjs"; | ||
import { measure, randomGraph, dotStringify } from "./utils.mjs"; | ||
|
||
const tests = [ | ||
{ nodeCount: 100, randomEdgeCount: 10 }, | ||
{ nodeCount: 1000, randomEdgeCount: 50 }, | ||
{ nodeCount: 1000, randomEdgeCount: 500 }, | ||
{ nodeCount: 1000, randomEdgeCount: 1000 } | ||
]; | ||
|
||
tests.forEach(test => { | ||
test.input = dotStringify(randomGraph(test.nodeCount, test.randomEdgeCount)); | ||
}); | ||
|
||
const timeLimit = 5000; | ||
|
||
for (const { input, nodeCount, randomEdgeCount } of tests) { | ||
const viz = await instance(); | ||
const result = measure(() => { | ||
viz.render(input, { format: "svg" }); | ||
viz.render(input, { format: "cmapx" }); | ||
}, timeLimit); | ||
console.log(`render, ${nodeCount} nodes, ${randomEdgeCount} edges: ${result}`); | ||
} | ||
|
||
for (const { input, nodeCount, randomEdgeCount } of tests) { | ||
const viz = await instance(); | ||
const result = measure(() => { | ||
viz.renderFormats(input, ["svg", "cmapx"]); | ||
}, timeLimit); | ||
console.log(`renderFormats, ${nodeCount} nodes, ${randomEdgeCount} edges: ${result}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import assert from "node:assert/strict"; | ||
import * as VizPackage from "../src/standalone.mjs"; | ||
|
||
describe("Viz", function() { | ||
let viz; | ||
|
||
beforeEach(async function() { | ||
viz = await VizPackage.instance(); | ||
}); | ||
|
||
describe("renderFormats", function() { | ||
it("renders multiple output formats", function() { | ||
const result = viz.renderFormats("graph a { }", ["dot", "cmapx"]); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "success", | ||
output: [ | ||
"graph a {\n\tgraph [bb=\"0,0,0,0\"];\n\tnode [label=\"\\N\"];\n}\n", | ||
"<map id=\"a\" name=\"a\">\n</map>\n" | ||
], | ||
errors: [] | ||
}); | ||
}); | ||
|
||
it("renders with the same format twice", function() { | ||
const result = viz.renderFormats("graph a { }", ["dot", "dot"]); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "success", | ||
output: [ | ||
"graph a {\n\tgraph [bb=\"0,0,0,0\"];\n\tnode [label=\"\\N\"];\n}\n", | ||
"graph a {\n\tgraph [bb=\"0,0,0,0\"];\n\tnode [label=\"\\N\"];\n}\n" | ||
], | ||
errors: [] | ||
}); | ||
}); | ||
|
||
it("renders with an empty array of formats", function() { | ||
const result = viz.renderFormats("graph a { }", []); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "success", | ||
output: [], | ||
errors: [] | ||
}); | ||
}); | ||
|
||
it("accepts options", function() { | ||
const result = viz.renderFormats("graph a { b }", ["dot", "cmapx"], { engine: "neato", reduce: true }); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "success", | ||
output: [ | ||
"graph a {\n\tgraph [bb=\"0,0,0,0\"];\n\tnode [label=\"\\N\"];\n}\n", | ||
"<map id=\"a\" name=\"a\">\n</map>\n" | ||
], | ||
errors: [] | ||
}); | ||
}); | ||
|
||
it("returns error messages for invalid input", function() { | ||
const result = viz.renderFormats("invalid", ["dot", "cmapx"]); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "failure", | ||
output: undefined, | ||
errors: [ | ||
{ level: "error", message: "syntax error in line 1 near 'invalid'" } | ||
] | ||
}); | ||
}); | ||
|
||
it("returns error messages for invalid input and an empty array of formats", function() { | ||
const result = viz.renderFormats("invalid", []); | ||
|
||
assert.deepStrictEqual(result, { | ||
status: "failure", | ||
output: undefined, | ||
errors: [ | ||
{ level: "error", message: "syntax error in line 1 near 'invalid'" } | ||
] | ||
}); | ||
}); | ||
}); | ||
}); |