Skip to content

Commit a63e7ca

Browse files
authored
test: add cypress for e2e test (#10)
1 parent 75280f4 commit a63e7ca

File tree

11 files changed

+541
-56
lines changed

11 files changed

+541
-56
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/node:latest
5+
- image: circleci/node:latest-browsers
66
branches:
77
ignore:
88
- gh-pages # list of branches to ignore

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe('My First Test', () => {
2+
it('Does not do much!', () => {
3+
cy.visit('http://localhost:4000')
4+
cy.wait(1000)
5+
cy.window().then(({ pages }) => {
6+
expect([...pages]).to.deep.equal([1, 2, 3])
7+
})
8+
cy.get('#bottom').then($ => {
9+
$[0].scrollIntoView()
10+
})
11+
cy.wait(1000)
12+
cy.window().then(({ pages }) => {
13+
expect([...pages]).to.deep.equal([1, 2, 3, 4, 5, 6])
14+
})
15+
})
16+
})

cypress/plugins/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example plugins/index.js can be used to load plugins
3+
//
4+
// You can change the location of this file or turn off loading
5+
// the plugins file with the 'pluginsFile' configuration option.
6+
//
7+
// You can read more here:
8+
// https://on.cypress.io/plugins-guide
9+
// ***********************************************************
10+
11+
// This function is called when a project is opened or re-opened (e.g. due to
12+
// the project's config changing)
13+
14+
module.exports = () => {
15+
// `on` is used to hook into various events Cypress emits
16+
// `config` is the resolved Cypress config
17+
}

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

cypress/videos/prefetch_spec.js.mp4

55.2 KB
Binary file not shown.

example/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import RoutePrefetch from '../src'
55
Vue.use(Router)
66
Vue.use(RoutePrefetch)
77

8+
window.pages = new Set()
9+
810
const Nav = {
911
render() {
1012
return (
@@ -20,7 +22,7 @@ const Nav = {
2022
<router-link to="/page/3">page 3</router-link>
2123
</li>
2224
</ul>
23-
<ul style="margin-top: 110vh;">
25+
<ul style="margin-top: 110vh;" id="bottom">
2426
<li>
2527
<router-link to="/page/4" prefetchFiles={['/foo']}>
2628
page 4
@@ -46,6 +48,7 @@ const Nav = {
4648

4749
const createPage = id => async () => {
4850
console.log(`fetching page ${id}`)
51+
window.pages.add(id)
4952
return {
5053
render() {
5154
return (

package.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
"types"
1111
],
1212
"scripts": {
13-
"test": "npm run lint",
13+
"test": "npm run lint && npm run test:e2e",
1414
"lint": "xo",
1515
"build": "bili --format esm,cjs,esm-min --minimal",
1616
"prepublishOnly": "npm run build",
1717
"example": "poi example/index.js --serve --jsx vue",
18-
"commit": "git-cz"
18+
"commit": "git-cz",
19+
"cy:run": "cypress run",
20+
"cy:open": "cypress open",
21+
"test:e2e": "run-p --race example cy:run"
1922
},
2023
"repository": {
2124
"url": "egoist/vue-router-prefetch",
@@ -27,13 +30,16 @@
2730
"babel-eslint": "^10.0.1",
2831
"bili": "^4.0.9",
2932
"commitizen": "^3.0.5",
33+
"cypress": "^3.3.2",
3034
"cz-conventional-changelog": "^2.1.0",
3135
"eslint-config-prettier": "^3.3.0",
3236
"eslint-config-rem": "^4.0.0",
37+
"eslint-plugin-cypress": "^2.2.1",
3338
"eslint-plugin-prettier": "^3.0.0",
3439
"eslint-plugin-vue": "^5.1.0",
3540
"husky": "^1.0.0-rc.13",
3641
"lint-staged": "^7.2.0",
42+
"npm-run-all": "^4.1.5",
3743
"poi": "^12.4.6",
3844
"prettier": "^1.15.2",
3945
"semantic-release": "^15.13.3",
@@ -54,12 +60,17 @@
5460
"plugin:prettier/recommended"
5561
],
5662
"envs": [
57-
"browser"
63+
"browser",
64+
"cypress/globals"
5865
],
5966
"rules": {
6067
"no-new": "off",
61-
"no-unused-expressions": "off"
62-
}
68+
"no-unused-expressions": "off",
69+
"import/no-unassigned-import": "off"
70+
},
71+
"plugins": [
72+
"cypress"
73+
]
6374
},
6475
"husky": {
6576
"hooks": {

0 commit comments

Comments
 (0)