test: add search fm e2e test for theme-yun

This commit is contained in:
YunYouJun 2023-10-29 01:53:29 +08:00
parent 0f6332a8b8
commit 3d76f57be1
15 changed files with 433 additions and 352 deletions

View File

@ -128,10 +128,17 @@ jobs:
- name: Cypress PNPM Patch
run: cp pnpm-lock.yaml package-lock.json
- name: Cypress
- name: Cypress Yun
uses: cypress-io/github-action@v4
with:
install-command: echo
build: pnpm run build
start: pnpm demo
start: pnpm fuse && pnpm demo
wait-on: 'http://localhost:3333'
- name: Cypress Docs
uses: cypress-io/github-action@v4
with:
install-command: echo
start: pnpm run docs:dev
wait-on: 'http://localhost:4859'

View File

@ -7,4 +7,8 @@ export default defineConfig({
specPattern: 'cypress/e2e/**/*.spec.*',
supportFile: false,
},
env: {
'theme-yun': 'http://localhost:3333/',
'docs': 'http://localhost:4859/',
},
})

View File

@ -1,4 +1,6 @@
context('Docs', () => {
context('Docs', {
baseUrl: Cypress.env('docs'),
}, () => {
beforeEach(() => {
cy.visit('/')
})

View File

@ -0,0 +1,24 @@
context('Frontmatter', {
baseUrl: Cypress.env('docs'),
}, () => {
beforeEach(() => {
cy.visit('/')
})
it('basic', () => {
cy.url()
.should('eq', Cypress.env('docs'))
})
it('get started', () => {
cy.get('.sese-btn')
.first()
.click()
.url()
.should('eq', 'http://localhost:4859/guide/getting-started')
})
it('time warning', () => {
cy.visit('/test/time-warning')
})
})

View File

@ -0,0 +1,20 @@
context('Frontmatter', {
baseUrl: Cypress.env('theme-yun'),
}, () => {
beforeEach(() => {
cy.visit('/')
})
it('basic', () => {
cy.url()
.should('eq', Cypress.env('theme-yun'))
})
// time warning in post
it('time warning', () => {
cy.visit('/test/time_warning')
cy.get('.yun-time-warning')
.should('exist')
})
})

View File

@ -1,4 +1,6 @@
context('Demo Yun', () => {
context('Theme Yun', {
baseUrl: Cypress.env('theme-yun'),
}, () => {
beforeEach(() => {
cy.visit('/')
})
@ -48,4 +50,19 @@ context('Demo Yun', () => {
cy.get('.comment')
.should('exist')
})
// search
it('search', () => {
cy.get('.yun-search-btn')
.should('exist')
.click()
.get('.yun-search-input')
.should('exist')
cy.get('.yun-search-btn')
.should('exist')
.click()
.get('.yun-search-input')
.should('not.exist')
})
})

View File

@ -23,7 +23,7 @@
"@iconify-json/simple-icons": "^1.1.76",
"nodemon": "^3.0.1",
"vite": "^4.5.0",
"vitepress": "1.0.0-rc.23",
"vitepress": "1.0.0-rc.24",
"vue": "^3.3.7"
}
}

View File

@ -184,7 +184,6 @@ onMounted(() => {
</template>
```
### ValaxyMain
你需要自定义一个 `ValaxyMain` 组件来决定主题的文章渲染部分。
@ -215,8 +214,6 @@ defineProps<{
> 示例可参考 [ValaxyMain.vue | valaxy-theme-yun](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy-theme-yun/components/ValaxyMain.vue)
## 样式
### Markdown 样式
@ -228,6 +225,28 @@ Markdown 样式是主题呈现文章样式的部分,需要由主题自定义
> 如果你想先使用常见的默认样式(后续再进行定制),你可以直接使用 [star-markdown-css](https://github.com/YunYouJun/star-markdown-css)。
> 使用方式可参见 [valaxy-theme-yun/styles](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy-theme-yun/styles/index.scss)
### NProgress 进度条
内置了基础的 [nprogress](https://github.com/rstacruz/nprogress) 样式,你可以通过覆盖 nprogress 的默认样式进行定制:
```scss
// your-theme/styles/index.scss
#nprogress {
pointer-events: none;
.bar {
background: var(--va-c-primary);
opacity: 0.75;
position: fixed;
z-index: 1024;
top: 0;
left: 0;
width: 100%;
height: 2px;
}
}
```
## 功能
### API

View File

@ -192,7 +192,7 @@ export default defineValaxyConfig<PressTheme.Config>({
icon: 'i-carbon-warning',
},
info: {
text: 'i-carbon-information',
icon: 'i-carbon-information',
},
},

View File

@ -35,6 +35,7 @@
"docs": "pnpm -C docs run dev",
"docs:dev": "pnpm -C docs run dev",
"docs:build": "pnpm -C docs run build",
"docs:serve": "pnpm -C docs run serve",
"docs:vitepress": "pnpm -C docs run vitepress:dev",
"lint": "eslint .",
"stylelint": "stylelint --fix \"**/*.{scss,vue}\"",
@ -48,7 +49,7 @@
"prepare": "husky install"
},
"devDependencies": {
"@antfu/eslint-config": "1.0.0-beta.27",
"@antfu/eslint-config": "1.0.0-beta.29",
"@iconify-json/logos": "^1.1.37",
"@iconify-json/vscode-icons": "^1.1.29",
"@microsoft/api-extractor": "^7.38.0",
@ -86,7 +87,7 @@
"valaxy-theme-press": "workspace:*",
"valaxy-theme-yun": "workspace:*",
"vitest": "^0.34.6",
"vue-tsc": "1.8.19",
"vue-tsc": "1.8.22",
"zx": "^7.2.3"
},
"pnpm": {

View File

@ -1,7 +1,9 @@
# valaxy
fuse-list.json
valaxy-fuse-list.json
# vite-ssg
.vite-ssg-dist
.vite-ssg-temp

View File

@ -27,7 +27,7 @@ const time_warning = computed(() => {
</script>
<template>
<blockquote v-if="time_warning" op="80">
<blockquote v-if="time_warning" class="yun-time-warning" op="80">
{{ t('post.time_warning', { ago: dayjs(fm.updated).fromNow() }) }}
</blockquote>
</template>

View File

@ -1,6 +1,6 @@
import path from 'node:path'
import fs from 'fs-extra'
import type { ResolvedValaxyOptions } from 'valaxy'
import { ensurePrefix } from '@antfu/utils'
import consola from 'consola'
import fg from 'fast-glob'
import matter from 'gray-matter'
@ -77,20 +77,27 @@ export function registerFuseCommand(cli: Argv<object>) {
const fuseList = await generateFuseList(options)
await fs.ensureDir('./dist')
const dataPath = ensurePrefix('/', options.config.siteConfig.fuse.dataPath)
const publicRelativeFolder = `public${dataPath}`
const publicFolder = `${options.userRoot}/${publicRelativeFolder}`
const publicFolder = path.resolve(options.userRoot, 'public')
const publicFuseFile = path.resolve(publicFolder, options.config.siteConfig.fuse.dataPath)
const publicRelativeFile = path.join('public', options.config.siteConfig.fuse.dataPath)
await fs.ensureFile(publicFolder)
fs.writeJSONSync(publicFolder, fuseList)
await fs.ensureFile(publicFuseFile)
fs.writeJSONSync(publicFuseFile, fuseList)
consola.success(`Generate fuse list in ${dim(publicFolder)}`)
// copy to dist
const distFolder = path.resolve(options.userRoot, 'dist')
const distFuseFile = path.resolve(distFolder, options.config.siteConfig.fuse.dataPath)
await fs.ensureDir(distFolder)
fs.writeJSONSync(distFuseFile, fuseList)
consola.success(`Generate fuse list in ${dim(distFolder)}`)
try {
const gitignore = await fs.readFile(`${options.userRoot}/.gitignore`, 'utf-8')
const publicRelativeFolder = `public${dataPath}`
if (!gitignore.includes(publicRelativeFolder)) {
await fs.appendFile(`${options.userRoot}/.gitignore`, `\n# valaxy\n${publicRelativeFolder}\n`)
consola.success(`Add ${dim(dataPath)} to ${dim('.gitignore')}`)
if (!gitignore.includes(publicRelativeFile)) {
const ignorePath = publicRelativeFile.replace(/\\/g, '/')
await fs.appendFile(`${options.userRoot}/.gitignore`, `\n# valaxy\n${ignorePath}\n`)
consola.success(`Add ${dim(ignorePath)} to ${dim('.gitignore')}`)
}
}
catch {}

View File

@ -110,13 +110,13 @@
"shiki": "^0.14.5",
"star-markdown-css": "^0.4.2",
"unconfig": "^0.3.11",
"unocss": "^0.56.5",
"unocss": "^0.57.1",
"unplugin-vue-components": "^0.25.2",
"vanilla-lazyload": "^17.8.5",
"vite": "^4.5.0",
"vite-plugin-pages": "^0.31.0",
"vite-plugin-vue-layouts": "^0.8.0",
"vite-ssg": "0.23.3",
"vite-ssg": "0.23.4",
"vite-ssg-sitemap": "0.6.0",
"vue": "^3.3.7",
"vue-i18n": "^9.6.1",

File diff suppressed because it is too large Load Diff