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

[WIP] test(e2e): added jest env and puppeteer for e2e #986

Closed
wants to merge 12 commits into from
Closed
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
packages/docsify-server-renderer/build.js
node_modules
build
server.js
test
server.js
e2e/**/*.(test|spec).(js|ts)
34 changes: 34 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Testing the e2e jest suites

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: bootstrap
run: npm run bootstrap
- name: Build
run: npm run build
- name: linting
run: npm run lint
- name: Jest + puppeteer end to end
run: npm run jest:e2e

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
node_modules
themes/
lib/

e2e/fixtures/docs
e2e/__tests__/__image_snapshots__/__diff_output__
# exceptions
!.gitkeep
!.gitkeep
19 changes: 17 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
sudo: false
language: node_js
node_js: stable

node_js:
- '10'
- '8'
- '12'
branches:
only:
- master
- develop
cache:
directories:
- node_modules
before_install:
- npm update
install:
- npm install
script:
- npm run build
- npm run test:e2e
- npm run lint
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

12 changes: 12 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions e2e/__tests__/cover.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import puppeteer from 'puppeteer'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
var browser
var page

jest.setTimeout(3000)
expect.extend({ toMatchImageSnapshot })

const expectThres = ss => {
expect(ss).toMatchImageSnapshot({
failureThreshold: 10,
failureThresholdType: 'percent'
})
}

beforeAll(async () => {
browser = await puppeteer.launch()
page = await browser.newPage()
await page.goto('http://127.0.0.1:3000')
})

afterAll(async () => {
await browser.close()
// SetTimeout(() => process.exit(0), 5000)
})

test('should click on the "get started button"', async done => {
await page.waitForSelector(
'body > section > div.cover-main > p:nth-child(5) > a:nth-child(2)'
)
await page.click(
'body > section > div.cover-main > p:nth-child(5) > a:nth-child(2)'
)
const ss = await page.screenshot()
expectThres(ss)
done()
})
80 changes: 80 additions & 0 deletions e2e/__tests__/search.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import puppeteer from 'puppeteer'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
var browser
var page

jest.setTimeout(3000)
expect.extend({ toMatchImageSnapshot })

const expectThres = ss => {
expect(ss).toMatchImageSnapshot({
failureThreshold: 10,
failureThresholdType: 'percent'
})
}

beforeAll(async () => {
browser = await puppeteer.launch()
page = await browser.newPage()
await page.goto('http://127.0.0.1:3000')
})

afterAll(async () => {
await browser.close()
// SetTimeout(() => {
// browser.close()
// }, 3000)
// SetTimeout(() => process.exit(0), 5000)
})

test('should search "awesome docsify" ', async done => {
await page.waitForSelector(
'body > main > aside > div.search > div.input-wrap > input[type=search]'
)
await page.evaluate(_ => {
window.scrollBy(0, window.innerHeight)
})
page.tap(
'body > main > aside > div.search > div.input-wrap > input[type=search]'
)
await page.keyboard.type(' awesome docsify', { delay: 100 })
// Await page.waitFor(3000)
const ss = await page.screenshot()
expectThres(ss)
done()
})

test('should click on the first link and it should be "awesome" page link', async done => {
await page.waitForSelector(
'body > main > aside > div.search > div.results-panel.show > div:nth-child(1) > a'
)
await page.click('body > main > aside > div.search > div.results-panel.show > div:nth-child(1) > a')

const ss = await page.screenshot()
expectThres(ss)
done()
})

test('should search "Markdown configuration"', async done => {
await page.goto('http://127.0.0.1:3000')
await page.evaluate(_ => {
window.scrollBy(0, window.innerHeight)
})
page.tap(
'body > main > aside > div.search > div.input-wrap > input[type=search]'
)
await page.keyboard.type(' Markdown configuration', { delay: 100 })

const ss = await page.screenshot()
expectThres(ss)
done()
})

test(' it should be "markdown configuration" page link', async done => {
await page.click(
'body > main > aside > div.search > div.results-panel.show > div:nth-child(1) > a'
)
const ss = await page.screenshot()
expectThres(ss)
done()
})
Loading