Skip to content

Commit 7aeac79

Browse files
amirrustambahmutov
authored andcommitted
Fix RouterLink issue and item-spec test (#1)
* Add Cypress commands to scripts * Add Cypress specific webpack config We need a base config but with an alias for ‘create-api’. * Set Cypress ’baseUrl’ to local dev server * Fix Vue Router integeration - add `VueRouter` to plugins option - generate router instance with `createRouter` - include router instance in component object
1 parent 7d9074a commit 7aeac79

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

Diff for: build/webpack.cypress.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path')
2+
const merge = require('webpack-merge')
3+
const base = require('./webpack.base.config')
4+
5+
const config = merge(base, {
6+
resolve: {
7+
alias: {
8+
'create-api': './create-api-client.js'
9+
}
10+
}
11+
})
12+
13+
module.exports = config

Diff for: cypress.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"baseUrl": "https://vue-hn.now.sh",
2+
"baseUrl": "http://localhost:8080",
33
"projectId": "b1sfu5"
44
}

Diff for: cypress/integration/item-spec.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import VueRouter from 'vue-router'
22
import router from '../../src/router'
33
import Item from '../../src/components/Item.vue'
44
import { timeAgo, host } from '../../src/util/filters'
5+
import { createRouter } from '../../src/router'
6+
import VueRouter from 'vue-router'
7+
import mountVue from 'cypress-vue-unit-test'
58

6-
const mountVue = require('cypress-vue-unit-test')
79
/* eslint-env mocha */
810
/* global cy, Cypress */
911
describe('Item', () => {
@@ -22,6 +24,7 @@ describe('Item', () => {
2224
descendants: 42
2325
}
2426
}
27+
2528
const extensions = {
2629
plugins: [VueRouter],
2730
filters: { timeAgo, host }
@@ -31,6 +34,8 @@ describe('Item', () => {
3134
extensions
3235
}
3336

37+
const router = createRouter()
38+
3439
beforeEach(() => {
3540
cy.viewport(400, 200)
3641
})
@@ -41,6 +46,6 @@ describe('Item', () => {
4146
})
4247

4348
it('has link to comments', () => {
44-
cy.contains('router-link', '42 comments')
49+
cy.contains('.comments-link > a', '42 comments')
4550
})
4651
})

Diff for: cypress/plugins/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const join = require('path').join
22
const {
33
onFilePreprocessor
44
} = require('cypress-vue-unit-test/preprocessor/webpack')
5-
const config = join(__dirname, '../../build/webpack.base.config')
5+
const config = join(__dirname, '../../build/webpack.cypress.config')
66
module.exports = on => {
77
on('file:preprocessor', onFilePreprocessor(config))
88
}

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"author": "Evan You <[email protected]>",
55
"private": true,
66
"scripts": {
7+
"cy:open": "cypress open",
8+
"cy:run": "cypress run",
79
"dev": "node server",
810
"start": "cross-env NODE_ENV=production node server",
911
"build": "rimraf dist && npm run build:client && npm run build:server",

0 commit comments

Comments
 (0)