Skip to content

Commit

Permalink
add plugin to prettify svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
leowrites committed Oct 19, 2024
1 parent 769c5ed commit 3bf8e79
Show file tree
Hide file tree
Showing 4 changed files with 608 additions and 1 deletion.
2 changes: 1 addition & 1 deletion memory-viz/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const config: Config = {
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
snapshotSerializers: ["./src/plugins/pretty_svg.ts"],

// The test environment that will be used for testing
testEnvironment: "node",
Expand Down
2 changes: 2 additions & 0 deletions memory-viz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"csstype": "^3.1.3",
"husky": "^9.1.5",
"jest": "^29.7.0",
"node-html-parser": "^6.1.13",
"pretty": "^2.0.0",
"tmp": "^0.2.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
Expand Down
19 changes: 19 additions & 0 deletions memory-viz/src/plugins/pretty_svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NewPlugin, OldPlugin } from "pretty-format";
import pretty from "pretty";
import { parse } from "node-html-parser";

export const serialize: NewPlugin["serialize"] = (val) => {
return pretty(val);
};

export const test: NewPlugin["test"] = (val: any) => {
const root = parse(val);
return root.firstChild.rawTagName === "svg";
};

export const plugin: NewPlugin = {
test,
serialize,
};

export default plugin;
Loading

0 comments on commit 3bf8e79

Please sign in to comment.