Skip to content

Commit 8a3ac7e

Browse files
committed
feat: e2e cypress
1 parent d57208d commit 8a3ac7e

File tree

11 files changed

+411
-18
lines changed

11 files changed

+411
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = api => {
2+
api.render('./template', {
3+
hasTS: api.hasPlugin('typescript')
4+
})
5+
6+
api.extendPackage({
7+
scripts: {
8+
e2e: 'vue-cli-service e2e',
9+
'e2e:open': 'vue-cli-service e2e:open'
10+
}
11+
})
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pluginsFile": "test/e2e/plugins/index.js"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://docs.cypress.io/guides/guides/plugins-guide.html
2+
3+
module.exports = (on, config) => {
4+
config.fixturesFolder = 'test/e2e/fixtures'
5+
config.integrationFolder = 'test/e2e/specs'
6+
config.screenshotsFolder = 'test/e2e/screenshots'
7+
config.videosFolder = 'test/e2e/videos'
8+
config.supportFile = 'test/e2e/support/index.js'
9+
return config
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://docs.cypress.io/api/introduction/api.html
2+
3+
describe('My First Test', () => {
4+
it('Visits the Kitchen Sink', () => {
5+
cy.visit(Cypress.env('VUE_DEV_SERVER_URL'))
6+
cy.contains('h1', 'Welcome to Your Vue.js <%- hasTS ? '+ TypeScript ' : '' %>App')
7+
})
8+
})
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) => { ... })
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')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module.exports = (api, options) => {
2+
const chalk = require('chalk')
3+
4+
function run (command, args, rawArgs) {
5+
if (args.url) {
6+
const i = rawArgs.findIndex(arg => /^--url/.test(arg))
7+
rawArgs.splice(i, /^--url=/.test(rawArgs[i]) ? 1 : 2)
8+
}
9+
10+
const serverPromise = args.url
11+
? Promise.resolve({ url: args.url })
12+
: api.service.run('serve', { mode: 'production' })
13+
14+
return serverPromise.then(({ url, server }) => {
15+
const { info } = require('@vue/cli-shared-utils')
16+
info(`Starting e2e tests...`)
17+
18+
const cyArgs = [
19+
command, // open or run
20+
'--env', `VUE_DEV_SERVER_URL=${url}`,
21+
...rawArgs
22+
]
23+
24+
const execa = require('execa')
25+
const cypressBinPath = require.resolve('cypress/bin/cypress')
26+
const runner = execa(cypressBinPath, cyArgs, { stdio: 'inherit' })
27+
if (server) {
28+
runner.on('exit', () => server.close())
29+
runner.on('error', () => server.close())
30+
}
31+
return runner
32+
})
33+
}
34+
35+
api.registerCommand('e2e', {
36+
description: 'run e2e tests headlessly with `cypress run`',
37+
usage: 'vue-cli-service e2e [options]',
38+
options: {
39+
'--url': 'run e2e tests against given url instead of auto-starting dev server',
40+
'-s, --spec': 'runs a specific spec file. defaults to "all"'
41+
},
42+
details:
43+
`All Cypress CLI options are also supported:\n` +
44+
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-run`)
45+
}, (args, rawArgs) => run('run', args, rawArgs))
46+
47+
api.registerCommand('e2e:open', {
48+
description: 'run e2e tests in interactive mode with `cypress open`',
49+
usage: 'vue-cli-service e2e:open [options]',
50+
options: {
51+
'--url': 'run e2e tests against given url instead of auto-starting dev server'
52+
},
53+
details:
54+
`All Cypress CLI options are supported:\n` +
55+
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-open`)
56+
}, (args, rawArgs) => run('open', args, rawArgs))
57+
}

packages/@vue/cli-plugin-e2e-cypress/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"homepage": "https://github.com/vuejs/vue-cli/packages/@vue/cli-plugin-e2e-cypress#readme",
2121
"publishConfig": {
2222
"access": "public"
23+
},
24+
"dependencies": {
25+
"cypress": "^1.4.1"
2326
}
2427
}

packages/@vue/cli-plugin-e2e-nightwatch/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
module.exports = (api, options) => {
22
api.registerCommand('e2e', {
33
description: 'run e2e tests with nightwatch',
4+
usage: 'vue-cli-service e2e [options]',
45
options: {
56
'--url': 'run e2e tests against given url instead of auto-starting dev server',
67
'-e, --env': 'specify comma-delimited browser envs to run in (default: chrome)',
78
'-t, --test': 'sepcify a test to run by name',
89
'-f, --filter': 'glob to filter tests by filename'
910
},
10-
usage: 'vue-cli-service e2e [options]'
11+
details:
12+
`All Nightwatch CLI options are also supported.\n` +
13+
`https://github.com/nightwatchjs/nightwatch/blob/master/lib/runner/cli/cli.js`
1114
}, (args, rawArgs) => {
1215
if (args.url) {
1316
const i = rawArgs.findIndex(arg => /^--url/.test(arg))

packages/@vue/cli-service/generator/template/.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ node_modules
33
/dist
44
<%_ if (rootOptions.plugins && rootOptions.plugins['@vue/cli-plugin-e2e-nightwatch']) { _%>
55

6-
# e2e reports & log
76
/test/e2e/reports/
87
selenium-debug.log
98
<%_ } _%>
9+
<%_ if (rootOptions.plugins && rootOptions.plugins['@vue/cli-plugin-e2e-cypress']) { _%>
10+
11+
/test/e2e/videos/
12+
/test/e2e/screenshots/
13+
<%_ } _%>
1014

1115
# local env files
1216
.env.local

0 commit comments

Comments
 (0)