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

test: add cypress for e2e test #10

Merged
merged 1 commit into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:latest
- image: circleci/node:latest-browsers
branches:
ignore:
- gh-pages # list of branches to ignore
Expand Down
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
16 changes: 16 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('My First Test', () => {
it('Does not do much!', () => {
cy.visit('http://localhost:4000')
cy.wait(1000)
cy.window().then(({ pages }) => {
expect([...pages]).to.deep.equal([1, 2, 3])
})
cy.get('#bottom').then($ => {
$[0].scrollIntoView()
})
cy.wait(1000)
cy.window().then(({ pages }) => {
expect([...pages]).to.deep.equal([1, 2, 3, 4, 5, 6])
})
})
})
17 changes: 17 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = () => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Binary file added cypress/videos/prefetch_spec.js.mp4
Binary file not shown.
5 changes: 4 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import RoutePrefetch from '../src'
Vue.use(Router)
Vue.use(RoutePrefetch)

window.pages = new Set()

const Nav = {
render() {
return (
Expand All @@ -20,7 +22,7 @@ const Nav = {
<router-link to="/page/3">page 3</router-link>
</li>
</ul>
<ul style="margin-top: 110vh;">
<ul style="margin-top: 110vh;" id="bottom">
<li>
<router-link to="/page/4" prefetchFiles={['/foo']}>
page 4
Expand All @@ -46,6 +48,7 @@ const Nav = {

const createPage = id => async () => {
console.log(`fetching page ${id}`)
window.pages.add(id)
return {
render() {
return (
Expand Down
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
"dist"
],
"scripts": {
"test": "npm run lint",
"test": "npm run lint && npm run test:e2e",
"lint": "xo",
"build": "bili --format esm,cjs,esm-min --minimal",
"prepublishOnly": "npm run build",
"example": "poi example/index.js --serve --jsx vue",
"commit": "git-cz"
"commit": "git-cz",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test:e2e": "run-p --race example cy:run"
},
"repository": {
"url": "egoist/vue-router-prefetch",
Expand All @@ -25,13 +28,16 @@
"babel-eslint": "^10.0.1",
"bili": "^4.0.9",
"commitizen": "^3.0.5",
"cypress": "^3.3.2",
"cz-conventional-changelog": "^2.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-rem": "^4.0.0",
"eslint-plugin-cypress": "^2.2.1",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-vue": "^5.1.0",
"husky": "^1.0.0-rc.13",
"lint-staged": "^7.2.0",
"npm-run-all": "^4.1.5",
"poi": "^12.4.6",
"prettier": "^1.15.2",
"semantic-release": "^15.13.3",
Expand All @@ -52,12 +58,17 @@
"plugin:prettier/recommended"
],
"envs": [
"browser"
"browser",
"cypress/globals"
],
"rules": {
"no-new": "off",
"no-unused-expressions": "off"
}
"no-unused-expressions": "off",
"import/no-unassigned-import": "off"
},
"plugins": [
"cypress"
]
},
"husky": {
"hooks": {
Expand Down