Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump to rc.1 and add e2e test #25

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = {
'vue/match-component-file-name': 'off',
},
},
{
files: ['**/e2e/**/*.cy.ts', '**/e2e/cypress/**/*.ts'],
extends: 'plugin:cypress/recommended',
},
{
files: ['**/tests/**/*.ts'],
rules: {
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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']
base: ['/', '/e2e/']
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: Get cypress cache path
working-directory: ./e2e
shell: bash
run: |
echo "CYPRESS_CACHE_PATH=$(pnpm cypress cache path)" >> $GITHUB_ENV

- name: Setup cypress cache
uses: actions/cache@v3
with:
path: ${{ env.CYPRESS_CACHE_PATH }}
key: cypress-${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
cypress-${{ runner.os }}-node-${{ matrix.node }}-
cypress-${{ runner.os }}-

- name: Install cypress binary
working-directory: ./e2e
run: pnpm cypress install

- name: Build source files
run: pnpm build

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

- name: E2E build
working-directory: ./e2e
run: pnpm e2e:ci:build
env:
E2E_BASE: ${{ matrix.base }}
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ lib/
# Test coverage files
coverage/

# E2E temp files
e2e/cypress/screenshots/

# Node modules
node_modules/

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Documentation

https://v2.vuepress.vuejs.org
<https://v2.vuepress.vuejs.org>

## Contribution

Expand Down
11 changes: 11 additions & 0 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:9080',
specPattern: 'tests/**/*.cy.ts',
},
env: {
E2E_BASE: process.env.E2E_BASE ?? '/',
},
})
8 changes: 8 additions & 0 deletions e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const URL_PREFIX = Cypress.env('E2E_BASE').replace(/\/$/, '')

// override the default cy.visit command to prepend base
// @ts-expect-error: could not type this method correctly
Cypress.Commands.overwrite('visit', (originalFn, url, options) =>
// @ts-expect-error: could not type this method correctly
originalFn(`${URL_PREFIX}${url}`, options),
)
1 change: 1 addition & 0 deletions e2e/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands'
87 changes: 87 additions & 0 deletions e2e/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import process from 'node:process'
import { viteBundler } from '@vuepress/bundler-vite'
import { webpackBundler } from '@vuepress/bundler-webpack'
import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress/cli'
import type { UserConfig } from 'vuepress/cli'
import { path } from 'vuepress/utils'

const E2E_BASE = (process.env.E2E_BASE ?? '/') as '/' | `/${string}/`
const E2E_BUNDLER = process.env.E2E_BUNDLER ?? 'vite'

export default defineUserConfig({
base: E2E_BASE,

dest: path.join(__dirname, 'dist', E2E_BASE),

port: 9080,

head: [
['meta', { name: 'foo', content: 'foo' }],
['meta', { name: 'bar', content: 'bar' }],
['meta', { name: 'baz', content: 'baz' }],
],

locales: {
'/': {
lang: 'en-US',
title: 'VuePress Ecosystem E2E',
description: 'VuePress Ecosystem E2E Test Site',
},
},

markdown: {
assets: {
// FIXME
absolutePathPrependBase: E2E_BUNDLER === 'webpack',
},
},

bundler:
E2E_BUNDLER === 'webpack'
? webpackBundler()
: viteBundler({
// TODO: Remove once upstream has a fix
viteOptions: {
optimizeDeps: {
exclude: ['vuepress/client', 'vuepress/shared'],
},
ssr: {
noExternal: ['vuepress'],
},
},
}),

theme: defaultTheme({
logo: 'https://v2.vuepress.vuejs.org/images/hero.png',
navbar: [
{
text: 'Home',
link: '/',
},
{
text: 'Dropdown',
children: [
{
text: 'sidebar',
link: '/sidebar/',
},
],
},
],

sidebar: {
'/': ['/sidebar/'],
'/sidebar/': [
{
text: 'Sidebar',
link: '/sidebar/',
children: [
{ text: 'sidebar 1', link: '/sidebar/1.html' },
{ text: 'sidebar 2', link: '/sidebar/2.html' },
],
},
],
},
}),
}) as UserConfig
6 changes: 6 additions & 0 deletions e2e/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Home
home: true
---

HomePage Content
65 changes: 65 additions & 0 deletions e2e/docs/markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Markdown

## Heading Test

### Heading 3 Test

#### Heading 4 Test

##### Heading 5 Test

###### Heading 6 Test

## Links

- [Home](./README.md)

## Emoji :tada:

## Table of Contents

[[toc]]

## Code Block

Title:

```ts title=".vuepress/config.ts"
import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress'

export default defineUserConfig({
title: 'Hello, VuePress',

theme: defaultTheme({
logo: 'https://vuejs.org/images/logo.png',
}),
})
```

Line highlighting:

```ts{1,7-9}
import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress'

export default defineUserConfig({
title: 'Hello, VuePress',

theme: defaultTheme({
logo: 'https://vuejs.org/images/logo.png',
}),
})
```

Line numbers:

```ts:no-line-numbers
// line-numbers is disabled
const line2 = 'This is line 2'
const line3 = 'This is line 3'
```

Code import:

@[code{24-30}](./.vuepress/config.ts)
5 changes: 5 additions & 0 deletions e2e/docs/sidebar/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Sidebar 1

## Sidebar 1 Heading 1

## Sidebar 1 Heading 2
5 changes: 5 additions & 0 deletions e2e/docs/sidebar/2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Sidebar 2

## Sidebar 2 Heading 1

## Sidebar 2 Heading 2
9 changes: 9 additions & 0 deletions e2e/docs/sidebar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sidebar: auto
---

# Sidebar

## Sidebar Heading 1

## Sidebar Heading 2
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/ecosystem-e2e",
"version": "2.0.0-rc.0",
"private": true,
"type": "module",
"scripts": {
"e2e:build": "vuepress build docs --clean-cache --clean-temp",
"e2e:build-webpack": "E2E_BUNDLER=webpack pnpm e2e:build",
"e2e:ci:build": "pnpm e2e:build && start-server-and-test e2e:serve http-get://localhost:9080 e2e:run",
"e2e:ci:dev": "start-server-and-test e2e:dev http-get://127.0.0.1:9080 e2e:run",
"e2e:clean": "rimraf docs/.vuepress/.temp docs/.vuepress/.cache docs/.vuepress/dist",
"e2e:dev": "vuepress dev docs --clean-cache --clean-temp",
"e2e:dev-webpack": "E2E_BUNDLER=webpack pnpm e2e:dev",
"e2e:open": "cypress open",
"e2e:run": "cypress run",
"e2e:serve": "anywhere -s -h localhost -p 9080 -d docs/.vuepress/dist"
},
"dependencies": {
"@vuepress/bundler-vite": "2.0.0-rc.1",
"@vuepress/bundler-webpack": "2.0.0-rc.1",
"@vuepress/cli": "2.0.0-rc.1",
"@vuepress/client": "2.0.0-rc.1",
"@vuepress/theme-default": "workspace:*",
"@vuepress/utils": "2.0.0-rc.1",
"sass": "^1.70.0",
"sass-loader": "^14.0.0",
"vue": "^3.4.15",
"vuepress": "2.0.0-rc.1"
},
"devDependencies": {
"anywhere": "^1.6.0",
"cypress": "^13.6.3",
"start-server-and-test": "^2.0.3"
}
}
9 changes: 9 additions & 0 deletions e2e/tests/theme-default/navbar.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
it('has navbar', () => {
cy.visit('/')
cy.get('.theme-default-content').then((el) => {
cy.wrap(el)
.get('.navbar .navbar-item')
.should('contain', 'Home')
.should('contain', 'Dropdown')
})
})
19 changes: 19 additions & 0 deletions e2e/tests/theme-default/sidebar.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
it('has heading sidebar', () => {
cy.visit('/sidebar/')
cy.get('.theme-default-content').then((el) => {
cy.wrap(el)
.get('a.sidebar-item')
.should('contain', 'Sidebar Heading 1')
.should('contain', 'Sidebar Heading 2')
})
})

it('has configured sidebar', () => {
cy.visit('/sidebar/1.html')
cy.get('.theme-default-content').then((el) => {
cy.wrap(el)
.get('a.sidebar-item')
.should('contain', 'sidebar 1')
.should('contain', 'sidebar 2')
})
})
Loading