Skip to content

Commit

Permalink
ci: production smoke test (#1353)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
KermanX and antfu authored Mar 3, 2024
1 parent bf87a69 commit c3f1380
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Production Smoke Test

on:
push:
branches:
- main
- master

pull_request:
branches:
- main
- master

workflow_dispatch:

jobs:
test:
timeout-minutes: 10
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [18.x]
os: [ubuntu-latest, windows-latest]
pm: [yarn, npm, pnpm]
hoist: [true, false]

steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4

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

- name: Setup
run: npm i -g @antfu/ni

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: latest

- name: Install
run: nci

- name: Build
run: nr build

- name: Pack
run: node ./scripts/pack.mjs ../temp/slidev-pkgs

- name: Create new project
run: |
npm i -g ../temp/slidev-pkgs/create-app.tgz
echo "N" | create-slidev ../temp/slidev-project
- name: Remove npmrc
run: pnpx del-cli ./.npmrc
working-directory: ../temp/slidev-project
if: ${{ ! matrix.hoist }}

- name: Install project (npm, pnpm)
run: |
${{ matrix.pm }} i
${{ matrix.pm }} i ../slidev-pkgs/cli.tgz playwright-chromium
working-directory: ../temp/slidev-project
if: ${{ matrix.pm != 'yarn' }}

- name: Install project (yarn)
run: |
yarn
yarn add ../slidev-pkgs/cli.tgz playwright-chromium
working-directory: ../temp/slidev-project
if: ${{ matrix.pm == 'yarn' }}

- name: Test build command in project
run: pnpm build
working-directory: ../temp/slidev-project

- name: E2E Smoke Test
uses: cypress-io/github-action@v4
if: ${{ matrix.os != 'windows-latest' }}
with:
install-command: echo
build: echo
start: pnpm --dir ../temp/slidev-project dev
spec: cypress/e2e/examples/smoke.spec.ts

- name: Install globally
run: |
${{ matrix.pm }} i -g ${{ github.workspace }}/../temp/slidev-pkgs/cli.tgz playwright-chromium
${{ matrix.pm }} i -g @slidev/theme-seriph
if: ${{ matrix.pm != 'yarn' }}

- name: Create slide file
run: pnpm --package=cpy-cli dlx cpy ./packages/slidev/template.md ../temp/ --flat
if: ${{ matrix.pm != 'yarn' }}

- name: Test build command in global mode
run: slidev build template.md
if: ${{ matrix.pm != 'yarn' }}
working-directory: ../temp

# Commented out because it's not working
# - name: E2E test in global mode
# uses: cypress-io/github-action@v4
# if: ${{ matrix.os != 'windows' }}
# with:
# project: ${{ github.workspace }}
# install-command: echo
# build: echo
# start: ${{ 'bash -c "slidev ../template.md"' }}
# spec: cypress/e2e/examples/noError.spec.ts
32 changes: 32 additions & 0 deletions cypress/e2e/examples/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
context('Smoke test', () => {
async function testAllSlides() {
while (1) {
let oldUrl, newUrl
cy.get('body')
.url().then(url => (oldUrl = url))
.type(`{RightArrow}`)
.wait(1000)
.url().then(url => (newUrl = url))
if (oldUrl === newUrl)
break
}
}

it('should throw no error in Play mode', async () => {
cy.visit('/').wait(4000)
await testAllSlides()
})

it('should throw no error in Presenter mode', async () => {
cy.visit('/presenter').wait(4000)
await testAllSlides()
})

it('should throw no error in Overview page', async () => {
cy.visit('/overview').wait(4000)
})

it('should throw no error in Entry page', async () => {
cy.visit('/entry').wait(4000)
})
})
45 changes: 45 additions & 0 deletions scripts/pack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { join } from 'node:path'
import process from 'node:process'
import { $, argv, cd, fs } from 'zx'

const WORKSPACE_ROOT = process.cwd()
const PKG_ROOT = join(WORKSPACE_ROOT, argv._[0])

const packages = {
'types': './packages/types',
'parser': './packages/parser',
'cli': './packages/slidev',
'client': './packages/client',
'create-app': './packages/create-app',
}

async function replaceDeps() {
cd(WORKSPACE_ROOT)
for (const path of Object.values(packages)) {
console.log('[pack] replaceDeps', path)
const pkgJson = JSON.parse(await fs.readFile(`${path}/package.json`, 'utf-8'))
for (const name in packages) {
const pkg = `@slidev/${name}`
if (pkgJson.dependencies?.[pkg])
pkgJson.dependencies[pkg] = `file:${PKG_ROOT}/${name}.tgz`
if (pkgJson.devDependencies?.[pkg])
pkgJson.devDependencies[pkg] = `file:${PKG_ROOT}/${name}.tgz`
}
await fs.writeFile(`${path}/package.json`, JSON.stringify(pkgJson, null, 2))
}
}

async function pack() {
await replaceDeps()
await fs.mkdir(PKG_ROOT, { recursive: true })
for (const [name, path] of Object.entries(packages)) {
console.log('[pack] pack', path)
cd(join(WORKSPACE_ROOT, path))
const { stdout } = await $`pnpm pack`
await fs.move(stdout.trim(), `${PKG_ROOT}/${name}.tgz`)
}
}

console.log('[pack] start packing...')
await pack()
console.log('[pack] done')

0 comments on commit c3f1380

Please sign in to comment.