Skip to content

Commit

Permalink
refactor: rewrite entry for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Jun 1, 2024
1 parent cec726d commit 0afea02
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 234 deletions.
4 changes: 3 additions & 1 deletion ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ dist-ssr
*.sw?

data.json
gsa.wasm
gsa.wasm

coverage/
20 changes: 20 additions & 0 deletions ui/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {codecovVitePlugin} from "@codecov/vite-plugin";
import * as path from "node:path";
import react from "@vitejs/plugin-react-swc";
import {execSync} from "node:child_process";
import type { InlineConfig } from 'vitest';

export function getSha(): string | undefined {
const envs = process.env;
Expand Down Expand Up @@ -72,3 +73,22 @@ export function build(dir: string): BuildOptions {
},
}
}

export function testConfig(): InlineConfig {
return {
coverage: {
provider: "v8",
enabled: true,
exclude: [
"node_modules",
"dist",
"coverage",
"vite.config.ts",
"vite.config-explorer.ts",
"common.ts",
"src/tool/wasm_exec.js"
]
}
}
}

4 changes: 3 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dev:explorer": "vite -c vite.config-explorer.ts",
"generate": "typia generate --input src/schema --output src/generated --project tsconfig.json",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "vitest"
"test:ui": "vitest -c vite.config.ts",
"test:explorer": "vitest -c vite.config-explorer.ts"
},
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down Expand Up @@ -39,6 +40,7 @@
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
Expand Down
125 changes: 125 additions & 0 deletions ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui/src/explorer/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {ReactNode, useEffect, useMemo} from "react";
import {useAsync} from "react-use";
import gsa from "../../gsa.wasm?init";
import {Entry} from "../tool/entry.ts";
import {createEntry} from "../tool/entry.ts";
import {Dialog, DialogContent, DialogContentText, DialogTitle} from "@mui/material";
import {FileSelector} from "./file_selector.tsx";
import TreeMap from "../TreeMap.tsx";
Expand Down Expand Up @@ -51,7 +51,7 @@ export const App: React.FC = () => {
return null
}

return new Entry(result)
return createEntry(result)
}, [result])

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import ReactDOM from 'react-dom/client'

import TreeMap from './TreeMap.tsx'
import {loadDataFromEmbed} from "./tool/utils.ts";
import {Entry} from "./tool/entry.ts";
import {createEntry} from "./tool/entry.ts";

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<TreeMap entry={new Entry(loadDataFromEmbed())}/>
<TreeMap entry={createEntry(loadDataFromEmbed())}/>
</React.StrictMode>,
)
23 changes: 23 additions & 0 deletions ui/src/tool/aligner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {max} from "d3-array";

export class aligner {
private pre: string[] = [];
private post: string[] = [];

public add(pre: string, post: string): aligner {
this.pre.push(pre);
this.post.push(post);
return this;
}

public toString(): string {
// determine the maximum length of the pre-strings
const maxPreLength = max(this.pre, (d) => d.length) ?? 0;
let ret = "";
for (let i = 0; i < this.pre.length; i++) {
ret += this.pre[i].padEnd(maxPreLength + 1) + this.post[i] + "\n";
}
ret = ret.trimEnd();
return ret;
}
}
Loading

0 comments on commit 0afea02

Please sign in to comment.