use vitest
This commit is contained in:
parent
021bccb216
commit
ad2cb213c0
|
|
@ -7,7 +7,7 @@
|
|||
"scripts": {
|
||||
"build": "pnpm db-generate && next build",
|
||||
"dev": "next",
|
||||
"test-unit": "uvu src .test.ts -r esbuild-register",
|
||||
"test-unit": "vitest run",
|
||||
"test-e2e": "playwright test",
|
||||
"db-generate": "prisma generate",
|
||||
"start": "node server.js",
|
||||
|
|
@ -101,7 +101,7 @@
|
|||
"tailwindcss": "^3.0.24",
|
||||
"typescript": "^4.5.5",
|
||||
"unocss": "^0.34.1",
|
||||
"uvu": "^0.5.3"
|
||||
"vitest": "^0.12.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
|
|
|
|||
135
pnpm-lock.yaml
135
pnpm-lock.yaml
|
|
@ -84,6 +84,7 @@ specifiers:
|
|||
use-onclickoutside: ^0.4.0
|
||||
uuid: ^8.3.2
|
||||
uvu: ^0.5.3
|
||||
vitest: ^0.12.9
|
||||
zod: ^3.15.1
|
||||
zustand: 4.0.0-rc.1
|
||||
|
||||
|
|
@ -175,6 +176,7 @@ devDependencies:
|
|||
typescript: 4.6.4
|
||||
unocss: 0.34.1
|
||||
uvu: 0.5.3
|
||||
vitest: 0.12.9
|
||||
|
||||
packages:
|
||||
|
||||
|
|
@ -879,6 +881,16 @@ packages:
|
|||
'@types/node': 17.0.31
|
||||
dev: true
|
||||
|
||||
/@types/chai-subset/1.3.3:
|
||||
resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==}
|
||||
dependencies:
|
||||
'@types/chai': 4.3.1
|
||||
dev: true
|
||||
|
||||
/@types/chai/4.3.1:
|
||||
resolution: {integrity: sha512-/zPMqDkzSZ8t3VtxOa4KPq7uzzW978M9Tvh+j7GHKuo6k6GTLxPJ4J5gE5cjfJ26pnXst0N5Hax8Sr0T2Mi9zQ==}
|
||||
dev: true
|
||||
|
||||
/@types/cookie/0.5.1:
|
||||
resolution: {integrity: sha512-COUnqfB2+ckwXXSFInsFdOAWQzCCx+a5hq2ruyj+Vjund94RJQd4LG2u9hnvJrTgunKAaax7ancBYlDrNYxA0g==}
|
||||
dev: true
|
||||
|
|
@ -1315,6 +1327,10 @@ packages:
|
|||
es-shim-unscopables: 1.0.0
|
||||
dev: true
|
||||
|
||||
/assertion-error/1.1.0:
|
||||
resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==}
|
||||
dev: true
|
||||
|
||||
/ast-types-flow/0.0.7:
|
||||
resolution: {integrity: sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==}
|
||||
dev: true
|
||||
|
|
@ -1495,6 +1511,19 @@ packages:
|
|||
resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==}
|
||||
dev: false
|
||||
|
||||
/chai/4.3.6:
|
||||
resolution: {integrity: sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
assertion-error: 1.1.0
|
||||
check-error: 1.0.2
|
||||
deep-eql: 3.0.1
|
||||
get-func-name: 2.0.0
|
||||
loupe: 2.3.4
|
||||
pathval: 1.1.1
|
||||
type-detect: 4.0.8
|
||||
dev: true
|
||||
|
||||
/chalk/2.4.2:
|
||||
resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==}
|
||||
engines: {node: '>=4'}
|
||||
|
|
@ -1528,6 +1557,10 @@ packages:
|
|||
resolution: {integrity: sha512-iBZ4F4wRbyORVsu0jPV7gXkOsGYjGHPmAyv+HiHG8gi5PtC9KI2j1+v8/tlibRvjoWX027ypmG/n0HtO5t7unw==}
|
||||
dev: false
|
||||
|
||||
/check-error/1.0.2:
|
||||
resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==}
|
||||
dev: true
|
||||
|
||||
/chokidar/3.5.3:
|
||||
resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==}
|
||||
engines: {node: '>= 8.10.0'}
|
||||
|
|
@ -1704,6 +1737,13 @@ packages:
|
|||
character-entities: 2.0.1
|
||||
dev: false
|
||||
|
||||
/deep-eql/3.0.1:
|
||||
resolution: {integrity: sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==}
|
||||
engines: {node: '>=0.12'}
|
||||
dependencies:
|
||||
type-detect: 4.0.8
|
||||
dev: true
|
||||
|
||||
/deep-is/0.1.4:
|
||||
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
|
||||
dev: true
|
||||
|
|
@ -2543,6 +2583,10 @@ packages:
|
|||
/functions-have-names/1.2.3:
|
||||
resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==}
|
||||
|
||||
/get-func-name/2.0.0:
|
||||
resolution: {integrity: sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=}
|
||||
dev: true
|
||||
|
||||
/get-intrinsic/1.1.1:
|
||||
resolution: {integrity: sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==}
|
||||
dependencies:
|
||||
|
|
@ -3154,6 +3198,12 @@ packages:
|
|||
dependencies:
|
||||
js-tokens: 4.0.0
|
||||
|
||||
/loupe/2.3.4:
|
||||
resolution: {integrity: sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==}
|
||||
dependencies:
|
||||
get-func-name: 2.0.0
|
||||
dev: true
|
||||
|
||||
/lru-cache/6.0.0:
|
||||
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
||||
engines: {node: '>=10'}
|
||||
|
|
@ -3920,6 +3970,10 @@ packages:
|
|||
resolution: {integrity: sha512-3vUjp552BJzCw9vqKsO5sttHkbYqqsZtH0x1PNtItgqx8BXEXzoY1SYRKcL6BTyVh4lGJGLj0tM42elUDMvcYA==}
|
||||
dev: true
|
||||
|
||||
/pathval/1.1.1:
|
||||
resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==}
|
||||
dev: true
|
||||
|
||||
/perfect-debounce/0.1.3:
|
||||
resolution: {integrity: sha512-NOT9AcKiDGpnV/HBhI22Str++XWcErO/bALvHCuhv33owZW/CjH8KAFLZDCmu3727sihe0wTxpDhyGc6M8qacQ==}
|
||||
dev: true
|
||||
|
|
@ -4345,6 +4399,14 @@ packages:
|
|||
dependencies:
|
||||
glob: 7.2.0
|
||||
|
||||
/rollup/2.75.0:
|
||||
resolution: {integrity: sha512-1/wxtweHJ7YwI2AIK3ZgCBU3nbW8sLnBIFwN46cwOTnVzt8f1o6J8zPKjwoiuADvzSjmnLqJce31p0q2vQ+dqw==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
hasBin: true
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/run-parallel/1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
dependencies:
|
||||
|
|
@ -4592,6 +4654,16 @@ packages:
|
|||
resolution: {integrity: sha512-1Uhn/aqw5C6RI4KejVeTg6mIS7IqxnLJ8Mv2tV5rTc0qWobay7pDUz6Wi392Cnc8ak1H0F2cjoRzb2/AW4+Fvg==}
|
||||
dev: false
|
||||
|
||||
/tinypool/0.1.3:
|
||||
resolution: {integrity: sha512-2IfcQh7CP46XGWGGbdyO4pjcKqsmVqFAPcXfPxcPXmOWt9cYkTP9HcDmGgsfijYoAEc4z9qcpM/BaBz46Y9/CQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
dev: true
|
||||
|
||||
/tinyspy/0.3.2:
|
||||
resolution: {integrity: sha512-2+40EP4D3sFYy42UkgkFFB+kiX2Tg3URG/lVvAZFfLxgGpnWl5qQJuBw1gaLttq8UOS+2p3C0WrhJnQigLTT2Q==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
dev: true
|
||||
|
||||
/to-fast-properties/2.0.0:
|
||||
resolution: {integrity: sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=}
|
||||
engines: {node: '>=4'}
|
||||
|
|
@ -4643,6 +4715,11 @@ packages:
|
|||
prelude-ls: 1.2.1
|
||||
dev: true
|
||||
|
||||
/type-detect/4.0.8:
|
||||
resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/type-fest/0.20.2:
|
||||
resolution: {integrity: sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==}
|
||||
engines: {node: '>=10'}
|
||||
|
|
@ -4903,6 +4980,64 @@ packages:
|
|||
vfile-message: 3.1.2
|
||||
dev: false
|
||||
|
||||
/vite/2.9.9:
|
||||
resolution: {integrity: sha512-ffaam+NgHfbEmfw/Vuh6BHKKlI/XIAhxE5QSS7gFLIngxg171mg1P3a4LSRME0z2ZU1ScxoKzphkipcYwSD5Ew==}
|
||||
engines: {node: '>=12.2.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
less: '*'
|
||||
sass: '*'
|
||||
stylus: '*'
|
||||
peerDependenciesMeta:
|
||||
less:
|
||||
optional: true
|
||||
sass:
|
||||
optional: true
|
||||
stylus:
|
||||
optional: true
|
||||
dependencies:
|
||||
esbuild: 0.14.39
|
||||
postcss: 8.4.13
|
||||
resolve: 1.22.0
|
||||
rollup: 2.75.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/vitest/0.12.9:
|
||||
resolution: {integrity: sha512-1NtyUANS72Qw5PwYvoztk067NX4fSiis2xQxhByOWS33eL2er/yupHyLxlBCOkF2ANe0dLFRvT1GVb+nczL5aw==}
|
||||
engines: {node: '>=v14.16.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@vitest/ui': '*'
|
||||
c8: '*'
|
||||
happy-dom: '*'
|
||||
jsdom: '*'
|
||||
peerDependenciesMeta:
|
||||
'@vitest/ui':
|
||||
optional: true
|
||||
c8:
|
||||
optional: true
|
||||
happy-dom:
|
||||
optional: true
|
||||
jsdom:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/chai': 4.3.1
|
||||
'@types/chai-subset': 1.3.3
|
||||
chai: 4.3.6
|
||||
debug: 4.3.4
|
||||
local-pkg: 0.4.1
|
||||
tinypool: 0.1.3
|
||||
tinyspy: 0.3.2
|
||||
vite: 2.9.9
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
- sass
|
||||
- stylus
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/w3c-keyname/2.2.4:
|
||||
resolution: {integrity: sha512-tOhfEwEzFLJzf6d1ZPkYfGj+FWhIpBux9ppoP3rlclw3Z0BZv3N7b7030Z1kYth+6rDuAsXUFr+d0VE6Ed1ikw==}
|
||||
dev: false
|
||||
|
|
|
|||
|
|
@ -1,60 +1,66 @@
|
|||
import { test } from "uvu"
|
||||
import assert from "uvu/assert"
|
||||
import { test, describe, expect } from "vitest"
|
||||
import { renderPageContent } from "./index"
|
||||
|
||||
test("simple", async () => {
|
||||
const { contentHTML, excerpt } = await renderPageContent(`
|
||||
# Hello
|
||||
|
||||
This is the **excerpt**
|
||||
describe("html", () => {
|
||||
test("simple", async () => {
|
||||
const { contentHTML, excerpt } = await renderPageContent(`
|
||||
# Hello
|
||||
|
||||
> Hello Blockquote <sup>foo</sup>
|
||||
This is the **excerpt**
|
||||
|
||||
> Hello Blockquote <sup>foo</sup>
|
||||
|
||||
- [ ] task list
|
||||
- [x] done
|
||||
|
||||
<script>alert('xss')</script>
|
||||
|
||||
<img src="foo.png" alt="my image" onerror="console.log(1)" />
|
||||
|
||||
<figcaption><a href="https://example.com">my caption</a></figcaption>
|
||||
|
||||
<img src />
|
||||
|
||||
\`\`\`js
|
||||
function foo() {}
|
||||
|
||||
<script>alert('xss')</script>
|
||||
\`\`\`
|
||||
|
||||
\`\`\`
|
||||
<script>alert('xss')</script>
|
||||
\`\`\`
|
||||
`)
|
||||
|
||||
- [ ] task list
|
||||
- [x] done
|
||||
expect(contentHTML).not.toMatch(/<script>/)
|
||||
expect(excerpt).toEqual(`This is the excerpt`)
|
||||
})
|
||||
|
||||
<script>alert('xss')</script>
|
||||
test("wrap table", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
|a|b|
|
||||
|---|---|
|
||||
|c|d|
|
||||
`)
|
||||
expect(contentHTML).toMatch(`<div class="table-wrapper">`)
|
||||
})
|
||||
|
||||
<img src="foo.png" alt="my image" onerror="console.log(1)" />
|
||||
|
||||
<figcaption><a href="https://example.com">my caption</a></figcaption>
|
||||
|
||||
<img src />
|
||||
|
||||
\`\`\`js
|
||||
function foo() {}
|
||||
|
||||
<script>alert('xss')</script>
|
||||
\`\`\`
|
||||
|
||||
\`\`\`
|
||||
<script>alert('xss')</script>
|
||||
\`\`\`
|
||||
`)
|
||||
|
||||
assert.not.match(contentHTML, /<script>/)
|
||||
assert.equal(excerpt, `This is the excerpt`)
|
||||
test("callout", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
> TIP:
|
||||
> Some tip!
|
||||
|
||||
> WARN:
|
||||
>
|
||||
> Some warning!
|
||||
`)
|
||||
expect(contentHTML).toMatchInlineSnapshot(`
|
||||
"<blockquote class=\\"callout callout-tip\\">
|
||||
<p>Some tip!</p>
|
||||
</blockquote>
|
||||
<blockquote class=\\"callout callout-warn\\">
|
||||
<p>Some warning!</p>
|
||||
</blockquote>"
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
test("wrap table", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
|a|b|
|
||||
|---|---|
|
||||
|c|d|
|
||||
`)
|
||||
assert.match(contentHTML, `<div class="table-wrapper">`)
|
||||
})
|
||||
|
||||
test("callout", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
> TIP:
|
||||
> Some tip!
|
||||
|
||||
> WARN:
|
||||
>
|
||||
> Some warning!
|
||||
`)
|
||||
console.log(contentHTML)
|
||||
})
|
||||
|
||||
test.run()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import path from "path"
|
||||
import { defineConfig } from "vitest/config"
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
"~": path.resolve("./src"),
|
||||
},
|
||||
},
|
||||
test: {
|
||||
include: ["src/**/*.test.ts"],
|
||||
deps: {
|
||||
external: ["rehype-prism-plus"],
|
||||
inline: ["react-avatar-editor"],
|
||||
},
|
||||
},
|
||||
})
|
||||
Loading…
Reference in New Issue