Skip to content

Commit

Permalink
build: setup e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Dec 10, 2023
1 parent 5abdcdf commit 7820399
Show file tree
Hide file tree
Showing 44 changed files with 2,101 additions and 250 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
'vue/multi-word-component-names': 'off',
},
},
{
files: ['**/e2e/**/*.cy.ts'],
extends: 'plugin:cypress/recommended',
},
{
files: ['**/tests/**/*.ts', 'tsup.config.ts'],
rules: {
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
branches:
- main
Expand Down Expand Up @@ -42,7 +40,7 @@ jobs:
- name: Lint
run: pnpm lint

- name: Test
- name: Unit test
run: pnpm test

check-result:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
paths-ignore:
- e2e/**
- '**.md'
pull_request:
branches:
Expand Down Expand Up @@ -36,7 +37,7 @@ jobs:
- name: Build source code
run: pnpm build

- name: Test coverage
- name: Unit test coverage
run: pnpm test:cov

- name: Coveralls
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: e2e

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
e2e:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: ['18', '20']
bundler: ['vite', 'webpack']

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build source files
run: pnpm build

- name: E2E dev
working-directory: ./e2e
run: pnpm e2e:ci-dev
env:
E2E_BUNDLER: ${{ matrix.bundler }}

- name: E2E build
working-directory: ./e2e
run: pnpm e2e:ci-build
env:
E2E_BUNDLER: ${{ matrix.bundler }}

e2e-result:
if: ${{ always() }}
name: e2e result
runs-on: ubuntu-latest
needs: [e2e]
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# VuePress files
**/.vuepress/.cache/
**/.vuepress/.temp/
**/.vuepress/dist/

# Dist files
dist/

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CHANGELOG.md
pnpm-lock.yaml
*.html
*.md
9 changes: 9 additions & 0 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:8080',
specPattern: 'tests/**/*.cy.ts',
supportFile: false,
},
})
31 changes: 31 additions & 0 deletions e2e/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import process from 'node:process'
import { viteBundler } from '@vuepress/bundler-vite'
import { webpackBundler } from '@vuepress/bundler-webpack'
import { defineUserConfig } from '@vuepress/cli'
import { e2eTheme } from './theme/node/e2eTheme.js'

export default defineUserConfig({
base: '/',

head: [],

locales: {
'/': {
lang: 'en-US',
title: 'VuePress E2E',
description: 'VuePress E2E Test Site',
head: [],
},
'/zh/': {
lang: 'zh-CN',
title: 'VuePress E2E',
description: 'VuePress E2E 测试站点',
head: [],
},
},

bundler:
process.env.E2E_BUNDLER === 'webpack' ? webpackBundler() : viteBundler(),

theme: e2eTheme(),
})
22 changes: 22 additions & 0 deletions e2e/docs/.vuepress/theme/client/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineClientConfig } from '@vuepress/client'
import CustomLayout from './layouts/CustomLayout.vue'
import Layout from './layouts/Layout.vue'
import NotFound from './layouts/NotFound.vue'

import './styles/index.scss'

export default defineClientConfig({
enhance({ app, router }) {
// ...
},

setup() {
// ...
},

layouts: {
CustomLayout,
Layout,
NotFound,
},
})
7 changes: 7 additions & 0 deletions e2e/docs/.vuepress/theme/client/layouts/CustomLayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div class="e2e-theme-custom-layout">
<main class="e2e-theme-custom-layout-content">
<Content />
</main>
</div>
</template>
24 changes: 24 additions & 0 deletions e2e/docs/.vuepress/theme/client/layouts/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { Content, useSiteData } from '@vuepress/client'
const siteData = useSiteData()
</script>

<template>
<div class="e2e-theme">
<nav class="e2e-theme-nav">
<div>Languages</div>
<ul>
<li v-for="[key, value] in Object.entries(siteData.locales)" :key="key">
<RouterLink :to="key">{{ value.lang }}</RouterLink>
</li>
</ul>
</nav>

<main class="e2e-theme-content">
<Content />
</main>
</div>
</template>

<style lang="scss" scoped></style>
3 changes: 3 additions & 0 deletions e2e/docs/.vuepress/theme/client/layouts/NotFound.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div class="e2e-theme-not-found">404 Not Found</div>
</template>
Empty file.
26 changes: 26 additions & 0 deletions e2e/docs/.vuepress/theme/node/e2eTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Page, Theme } from '@vuepress/core'
import { getDirname, path } from '@vuepress/utils'

const __dirname = getDirname(import.meta.url)

export const e2eTheme = (): Theme => {
return {
name: '@vuepress/theme-e2e',

alias: {
// ...
},

define: {
// ...
},

clientConfigFile: path.resolve(__dirname, '../client/config.ts'),

extendsPage: (page: Page) => {
// ...
},

plugins: [],
}
}
1 change: 1 addition & 0 deletions e2e/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
5 changes: 5 additions & 0 deletions e2e/docs/layouts/custom-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: CustomLayout
---

Should use CustomLayout
1 change: 1 addition & 0 deletions e2e/docs/layouts/layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Should use Layout
Empty file.
Empty file added e2e/docs/markdown/emoji.md
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions e2e/docs/markdown/links/bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [foo](./foo.md)
- [baz](./baz.md)
2 changes: 2 additions & 0 deletions e2e/docs/markdown/links/baz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [foo](./foo.md)
- [bar](./bar.md)
2 changes: 2 additions & 0 deletions e2e/docs/markdown/links/foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [bar](./bar.md)
- [baz](./baz.md)
Empty file added e2e/docs/markdown/toc.md
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions e2e/docs/page-data/frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
str: str
num: 1
bool: true
arr:
- 1
- 2
- 3
obj:
foo: bar
baz: qux
---

{{ JSON.stringify($frontmatter) }}
1 change: 1 addition & 0 deletions e2e/docs/page-data/headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
1 change: 1 addition & 0 deletions e2e/docs/page-data/lang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
1 change: 1 addition & 0 deletions e2e/docs/page-data/permalink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
5 changes: 5 additions & 0 deletions e2e/docs/page-data/title-from-frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: title from frontmatter
---

# title from h1
1 change: 1 addition & 0 deletions e2e/docs/page-data/title-from-h1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# title from h1
1 change: 1 addition & 0 deletions e2e/docs/zh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
35 changes: 35 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@vuepress/e2e",
"version": "2.0.0-rc.0",
"private": true,
"type": "module",
"scripts": {
"e2e:build": "vuepress-cli build docs --clean-cache --clean-temp",
"e2e:build-webpack": "E2E_BUNDLER=webpack pnpm e2e:build",
"e2e:ci:build": "pnpm e2e:build && pnpm e2e:serve & wait-on http-get://localhost:8088 && pnpm e2e:run --config baseUrl=http://localhost:8088",
"e2e:ci:dev": "pnpm e2e:dev & wait-on http-get://127.0.0.1:8080 && pnpm e2e:run --config baseUrl=http://localhost:8080",
"e2e:clean": "rimraf .vuepress/.temp .vuepress/.cache .vuepress/dist",
"e2e:dev": "vuepress-cli dev docs --clean-cache --clean-temp",
"e2e:dev-webpack": "E2E_BUNDLER=webpack pnpm e2e:dev",
"e2e:run": "cypress run",
"e2e:serve": "anywhere -s -h localhost -p 8088 -d docs/.vuepress/dist"
},
"dependencies": {
"@vuepress/bundler-vite": "workspace:*",
"@vuepress/bundler-webpack": "workspace:*",
"@vuepress/cli": "workspace:*",
"@vuepress/client": "workspace:*",
"@vuepress/core": "workspace:*",
"@vuepress/markdown": "workspace:*",
"@vuepress/shared": "workspace:*",
"@vuepress/utils": "workspace:*",
"sass": "^1.69.5",
"sass-loader": "^13.3.2",
"vue": "^3.3.11"
},
"devDependencies": {
"anywhere": "^1.6.0",
"cypress": "^13.6.1",
"wait-on": "^7.2.0"
}
}
20 changes: 20 additions & 0 deletions e2e/tests/layouts.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
context('layouts', () => {
it('CustomLayout', () => {
cy.visit('/layouts/custom-layout.html')
cy.get('.e2e-theme-custom-layout').should('exist')
cy.get('.e2e-theme-custom-layout-content')
.contains('Should use CustomLayout')
.should('exist')
})

it('Layout', () => {
cy.visit('/layouts/layout.html')
cy.get('.e2e-theme').should('exist')
cy.get('.e2e-theme-content').contains('Should use Layout').should('exist')
})

it('NotFound', () => {
cy.visit('/404.html')
cy.get('.e2e-theme-not-found').should('have.text', '404 Not Found')
})
})
35 changes: 35 additions & 0 deletions e2e/tests/markdown/links.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('markdown > links', () => {
it('should render links and navigate between pages correctly', () => {
cy.visit('/markdown/links/foo.html')

cy.get('.e2e-theme-content ul li a')
.should('have.length', 2)
.first()
.should('have.text', 'bar')
.click()

cy.location().should((location) => {
expect(location.pathname).to.eq('/markdown/links/bar.html')
})

cy.get('.e2e-theme-content ul li a')
.should('have.length', 2)
.last()
.should('have.text', 'baz')
.click()

cy.location().should((location) => {
expect(location.pathname).to.eq('/markdown/links/baz.html')
})

cy.get('.e2e-theme-content ul li a')
.should('have.length', 2)
.first()
.should('have.text', 'foo')
.click()

cy.location().should((location) => {
expect(location.pathname).to.eq('/markdown/links/foo.html')
})
})
})
Loading

0 comments on commit 7820399

Please sign in to comment.