Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteXyy committed Dec 22, 2023
0 parents commit fa51449
Show file tree
Hide file tree
Showing 9 changed files with 2,158 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "vitest-hang",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"test": "vitest run"
},
"dependencies": {
"dompurify": "^3.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@types/dompurify": "^3.0.5",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.1",
"jsdom": "^23.0.1",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vitest": "^1.1.0"
}
}
27 changes: 27 additions & 0 deletions src/Message.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { cleanup, render, screen } from "@testing-library/react";
import Message from "./Message";
import { describe, it, expect, beforeEach } from "vitest";

beforeEach(cleanup);

describe(
"test",
() => {
it("1", () => {
const fakeSystemText = `<b>test</b> abc<script>alert("")</script>`;
render(<Message text={fakeSystemText} />);
const messageElement = screen.getByTestId("message");
expect(messageElement).toBeVisible();
expect(messageElement.innerHTML).toBe("<b>test</b> abc");
});

it("2", () => {
const fakeSystemText = `<b>test</b> abc<script>alert("")</script>`;
render(<Message text={fakeSystemText} />);
const messageElement = screen.getByTestId("message");
expect(messageElement).toBeVisible();
expect(messageElement.innerHTML).toBe("<b>test</b> abc");
});
},
{ repeats: 200 }
);
14 changes: 14 additions & 0 deletions src/Message.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import DOMPurify from 'dompurify';

const dompurify = DOMPurify();

const SystemMessage = ({ text }: { text: string }) => {
return (
<div
// data-testid="message"
dangerouslySetInnerHTML={{ __html: dompurify.sanitize(text) }}
/>
);
};

export default SystemMessage;
1 change: 1 addition & 0 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest';
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

"types": ["vitest/globals"]
},
"include": ["src", "vite.config.ts"]
}
11 changes: 11 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [react()],
test: {
// globals: true,
setupFiles: ["./src/setupTests.ts"],
environment: "jsdom",
},
});
Loading

0 comments on commit fa51449

Please sign in to comment.