fix: unit test and add ci

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2023-04-10 22:22:12 +08:00
parent 1364424a6d
commit 34dfb5d876
6 changed files with 406 additions and 452 deletions
+48
View File
@@ -0,0 +1,48 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js Build CI
on:
push:
branches:
- main
- dev
pull_request:
branches: [main, dev]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v3
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- uses: pnpm/action-setup@v2.2.4
with:
version: 8.x
run_install: false
- name: Install Dependencies
run: |
pnpm i --no-optional
- name: Test
run: |
pnpm run test-unit
+2 -1
View File
@@ -7,7 +7,7 @@
"scripts": {
"build": "next build",
"dev": "next -p 2222",
"test-unit": "vitest run",
"test-unit": "vitest",
"test-e2e": "playwright test",
"start": "node server.js",
"uno-generate": "unocss \"src/**/*.{ts,tsx}\" -o src/generated/uno.css",
@@ -138,6 +138,7 @@
"@types/uuid": "9.0.1",
"@unocss/cli": "0.50.6",
"@unocss/preset-icons": "0.50.6",
"@vitejs/plugin-react": "3.1.0",
"autoprefixer": "10.4.14",
"babel-loader": "^9.1.2",
"cross-spawn": "7.0.3",
+308 -441
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
import getConfig from "next/config"
const config = getConfig()
const config = getConfig() || {}
export const REDIS_URL = config.ENV_REDIS_URL || process.env.REDIS_URL
export const REDIS_EXPIRE =
+45 -9
View File
@@ -3,8 +3,9 @@ import { renderPageContent } from "./index"
describe("html", () => {
test("simple", async () => {
const { contentHTML, excerpt } = await renderPageContent(`
# Hello
const { contentHTML, excerpt } = await renderPageContent(
`
# Hello
This is the **excerpt**
@@ -30,30 +31,65 @@ describe("html", () => {
\`\`\`
<script>alert('xss')</script>
\`\`\`
`)
`,
true,
)
expect(contentHTML).not.toMatch(/<script>/)
expect(excerpt).toEqual(`This is the excerpt`)
expect(excerpt).toMatchInlineSnapshot(`
"This is the excerpt Hello Blockquote foo
task list done
my caption
Copy
function foo() {}
<script>alert('xss')</script>
C…"
`)
})
test("wrap table", async () => {
const { contentHTML } = await renderPageContent(`
|a|b|
const { contentHTML } = await renderPageContent(
`|a|b|
|---|---|
|c|d|
`,
true,
)
expect(contentHTML).toMatchInlineSnapshot(`
"
<div class=\\"table-wrapper\\"><table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>c</td><td>d</td></tr></tbody></table></div>"
`)
expect(contentHTML).toMatch(`<div class="table-wrapper">`)
})
test("callout", async () => {
const { contentHTML } = await renderPageContent(`
const { contentHTML } = await renderPageContent(
`
> TIP:
>
> Some tip!
> WARN:
>
> Some warning!
`)
`,
true,
)
expect(contentHTML).toMatchInlineSnapshot(`
"<blockquote class=\\"callout callout-tip\\">
<p>Some tip!</p>
+2
View File
@@ -1,5 +1,6 @@
import path from "path"
import { defineConfig } from "vitest/config"
import react from "@vitejs/plugin-react"
export default defineConfig({
resolve: {
@@ -7,6 +8,7 @@ export default defineConfig({
"~": path.resolve("./src"),
},
},
plugins: [react()],
test: {
include: ["src/**/*.test.ts"],
deps: {