Skip to content

Commit 69ebd80

Browse files
committed
refactor: rename test commands
BREAKING CHANGE: `cli-plugin-unit-jest` and `cli-plugin-unit-mocha` now register "test:unit" command and script instead of "test"; `cli-plugin-e2e-cypress` now register "test:e2e" with optional `--headless` flag instead of "e2e" and "e2e:open"; `cli-plugin-e2e-nightwatch` now register "test:e2e" instead of "e2e". close #876, close #878
1 parent d595ada commit 69ebd80

File tree

21 files changed

+98
-124
lines changed

21 files changed

+98
-124
lines changed

docs/env.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ Loaded variables will become available to all `vue-cli-service` commands, plugin
3030
**Mode** is an important concept in Vue CLI projects. By default, there are three modes in a Vue CLI project:
3131

3232
- `development` is used by `vue-cli-service serve`
33-
- `production` is used by `vue-cli-service build`
34-
- `test` is used by `vue-cli-service test`
33+
- `production` is used by `vue-cli-service build` and `vue-cli-service test:e2e`
34+
- `test` is used by `vue-cli-service test:unit`
3535

3636
Note that a mode is different from `NODE_ENV`, as a mode can contain multiple environment variables. That said, each mode does set `NODE_ENV` to the same value by default - for example, `NODE_ENV` will be set to `"development"` in development mode.
3737

3838
You can set environment variables only available to a certain mode by postfixing the `.env` file. For example, if you create a file named `.env.development` in your project root, then the variables declared in that file will only be loaded in development mode.
3939

40-
Passing the `--mode` option flag with [build command](https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#build) will use that mode's environment variables in the build. For example, if you want to use development variables in the build command, add this to your package.json scripts:
40+
You can overwrite the default mode used for a command by passing the `--mode` option flag. For example, if you want to use development variables in the build command, add this to your `package.json` scripts:
4141

4242
```
4343
"dev-build": "vue-cli-service build --mode development",

packages/@vue/cli-plugin-e2e-cypress/README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,24 @@ Cypress offers a rich interactive interface for running E2E tests, but currently
88

99
## Injected Commands
1010

11-
- **`vue-cli-service e2e`**
11+
- **`vue-cli-service test:e2e`**
1212

13-
run e2e tests headlessly with `cypress run`.
13+
Run e2e tests with `cypress run`.
1414

15-
Options:
16-
17-
```
18-
--url run e2e tests against given url instead of auto-starting dev server
19-
-s, --spec runs a specific spec file. defaults to "all"
20-
```
15+
By default it launches Cypress in interactive mode with a GUI. If you want to run the tests in headless mode (e.g. for CI), you can do so with the `--headless` option.
2116

22-
Additionally, [all Cypress CLI options for `cypress run` are also supported](https://docs.cypress.io/guides/guides/command-line.html#cypress-run).
23-
24-
- **`vue-cli-service e2e:open`**
25-
26-
run e2e tests in interactive mode with `cypress open`.
17+
The command automatically starts a server in production mode to run the e2e tests against. If you want to run the tests multiple times without having to restart the server every time, you can start the server with `vue-cli-service serve --mode production` in one terminal, and then run e2e tests against that server using the `--url` option.
2718

2819
Options:
2920

3021
```
22+
--headless run in headless mode without GUI
23+
--mode specify the mode the dev server should run in. (default: production)
3124
--url run e2e tests against given url instead of auto-starting dev server
25+
-s, --spec (headless only) runs a specific spec file. defaults to "all"
3226
```
3327

34-
Additionally, [all Cypress CLI options for `cypress open` are also supported](https://docs.cypress.io/guides/guides/command-line.html#cypress-open).
35-
36-
Both commands automatically starts a server in production mode to run the e2e tests against. If you want to run the tests multiple times without having to restart the server every time, you can start the server with `vue-cli-service serve --mode production` in one terminal, and then run e2e tests against that server using the `--url` option.
28+
Additionally, [all Cypress CLI options for `cypress run` are also supported](https://docs.cypress.io/guides/guides/command-line.html#cypress-run).
3729

3830
## Configuration
3931

@@ -42,6 +34,5 @@ We've pre-configured Cypress to place most of the e2e testing related files unde
4234
## Installing in an Already Created Project
4335

4436
``` sh
45-
npm install -D @vue/cli-plugin-e2e-cypress
46-
vue invoke e2e-cypress
37+
vue add e2e-cypress
4738
```

packages/@vue/cli-plugin-e2e-cypress/__tests__/cypressPlugin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ test('should work', async () => {
1414
config.videoRecording = false
1515
await project.write('cypress.json', JSON.stringify(config))
1616

17-
await project.run(`vue-cli-service e2e`)
17+
await project.run(`vue-cli-service test:e2e --headless`)
1818
})

packages/@vue/cli-plugin-e2e-cypress/generator/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ module.exports = api => {
66

77
api.extendPackage({
88
scripts: {
9-
e2e: 'vue-cli-service e2e',
10-
'e2e:open': 'vue-cli-service e2e:open'
9+
'test:e2e': 'vue-cli-service test:e2e'
1110
}
1211
})
1312
}
Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const chalk = require('chalk')
2+
13
function removeArg (rawArgs, arg) {
24
const matchRE = new RegExp(`^--${arg}`)
35
const equalRE = new RegExp(`^--${arg}=`)
@@ -8,71 +10,54 @@ function removeArg (rawArgs, arg) {
810
}
911

1012
module.exports = (api, options) => {
11-
const chalk = require('chalk')
12-
13-
function run (command, args, rawArgs) {
14-
removeArg(rawArgs, 'url')
15-
removeArg(rawArgs, 'mode')
16-
17-
const serverPromise = args.url
18-
? Promise.resolve({ url: args.url })
19-
: api.service.run('serve')
20-
21-
return serverPromise.then(({ url, server }) => {
22-
const { info } = require('@vue/cli-shared-utils')
23-
info(`Starting e2e tests...`)
24-
25-
const cyArgs = [
26-
command, // open or run
27-
'--config', `baseUrl=${url}`,
28-
...rawArgs
29-
]
30-
31-
const execa = require('execa')
32-
const cypressBinPath = require.resolve('cypress/bin/cypress')
33-
const runner = execa(cypressBinPath, cyArgs, { stdio: 'inherit' })
34-
if (server) {
35-
runner.on('exit', () => server.close())
36-
runner.on('error', () => server.close())
37-
}
38-
39-
if (process.env.VUE_CLI_TEST) {
40-
runner.on('exit', code => {
41-
process.exit(code)
42-
})
43-
}
44-
45-
return runner
46-
})
47-
}
48-
49-
const commandOptions = {
50-
'--mode': 'specify the mode the dev server should run in. (default: production)',
51-
'--url': 'run e2e tests against given url instead of auto-starting dev server'
52-
}
53-
54-
api.registerCommand('e2e', {
55-
description: 'run e2e tests headlessly with `cypress run`',
56-
usage: 'vue-cli-service e2e [options]',
57-
options: Object.assign({
58-
'-s, --spec': 'runs a specific spec file. defaults to "all"'
59-
}, commandOptions),
13+
api.registerCommand('test:e2e', {
14+
description: 'run e2e tests with Cypress',
15+
usage: 'vue-cli-service test:e2e [options]',
16+
options: {
17+
'--headless': 'run in headless mode without GUI',
18+
'--mode': 'specify the mode the dev server should run in. (default: production)',
19+
'--url': 'run e2e tests against given url instead of auto-starting dev server',
20+
'-s, --spec': '(headless only) runs a specific spec file. defaults to "all"'
21+
},
6022
details:
6123
`All Cypress CLI options are also supported:\n` +
6224
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-run`)
63-
}, (args, rawArgs) => run('run', args, rawArgs))
25+
}, async (args, rawArgs) => {
26+
removeArg(rawArgs, 'headless')
27+
removeArg(rawArgs, 'mode')
28+
removeArg(rawArgs, 'url')
6429

65-
api.registerCommand('e2e:open', {
66-
description: 'run e2e tests in interactive mode with `cypress open`',
67-
usage: 'vue-cli-service e2e:open [options]',
68-
options: commandOptions,
69-
details:
70-
`All Cypress CLI options are supported:\n` +
71-
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-open`)
72-
}, (args, rawArgs) => run('open', args, rawArgs))
30+
const { info } = require('@vue/cli-shared-utils')
31+
info(`Starting e2e tests...`)
32+
33+
const { url, server } = args.url
34+
? { url: args.url }
35+
: await api.service.run('serve')
36+
37+
const cyArgs = [
38+
args.headless ? 'run' : 'open', // open or run
39+
'--config', `baseUrl=${url}`,
40+
...rawArgs
41+
]
42+
43+
const execa = require('execa')
44+
const cypressBinPath = require.resolve('cypress/bin/cypress')
45+
const runner = execa(cypressBinPath, cyArgs, { stdio: 'inherit' })
46+
if (server) {
47+
runner.on('exit', () => server.close())
48+
runner.on('error', () => server.close())
49+
}
50+
51+
if (process.env.VUE_CLI_TEST) {
52+
runner.on('exit', code => {
53+
process.exit(code)
54+
})
55+
}
56+
57+
return runner
58+
})
7359
}
7460

7561
module.exports.defaultModes = {
76-
e2e: 'production',
77-
'e2e:open': 'production'
62+
'test:e2e': 'production'
7863
}

packages/@vue/cli-plugin-e2e-nightwatch/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
## Injected Commands
66

7-
- **`vue-cli-service e2e`**
7+
- **`vue-cli-service test:e2e`**
88

99
run e2e tests with [NightwatchJS](nightwatchjs.org).
1010

@@ -18,6 +18,8 @@
1818
-f, --filter glob to filter tests by filename
1919
```
2020

21+
> Note: this plugin currently uses Nightwatch v0.9.x. We are waiting for Nightwatch 1.0 to stabilize before upgrading.
22+
2123
Additionally, [all Nightwatch CLI options are also supported](https://github.com/nightwatchjs/nightwatch/blob/master/lib/runner/cli/cli.js).
2224

2325
## Configuration
@@ -31,6 +33,5 @@ Consult Nightwatch docs for [configuration options](http://nightwatchjs.org/gett
3133
## Installing in an Already Created Project
3234

3335
``` sh
34-
npm install -D @vue/cli-plugin-e2e-nightwatch
35-
vue invoke e2e-nightwatch
36+
vue add e2e-nightwatch
3637
```

packages/@vue/cli-plugin-e2e-nightwatch/__tests__/nightwatchPlugin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ test('should work', async () => {
99
'@vue/cli-plugin-e2e-nightwatch': {}
1010
}
1111
})
12-
await project.run(`vue-cli-service e2e`)
12+
await project.run(`vue-cli-service test:e2e`)
1313
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = api => {
55

66
api.extendPackage({
77
scripts: {
8-
e2e: 'vue-cli-service e2e'
8+
'test:e2e': 'vue-cli-service test:e2e'
99
}
1010
})
1111
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function removeArg (rawArgs, arg) {
88
}
99

1010
module.exports = (api, options) => {
11-
api.registerCommand('e2e', {
11+
api.registerCommand('test:e2e', {
1212
description: 'run e2e tests with nightwatch',
13-
usage: 'vue-cli-service e2e [options]',
13+
usage: 'vue-cli-service test:e2e [options]',
1414
options: {
1515
'--url': 'run e2e tests against given url instead of auto-starting dev server',
1616
'--config': 'use custom nightwatch config file (overrides internals)',
@@ -70,5 +70,5 @@ module.exports = (api, options) => {
7070
}
7171

7272
module.exports.defaultModes = {
73-
e2e: 'production'
73+
'test:e2e': 'production'
7474
}

packages/@vue/cli-plugin-typescript/__tests__/tsPluginE2e.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ test('cypress', async () => {
1010
'@vue/cli-plugin-e2e-cypress': {}
1111
}
1212
})
13-
await project.run(`vue-cli-service e2e`)
13+
await project.run(`vue-cli-service test:e2e --headless`)
1414
})
1515

1616
test('nightwatch', async () => {
1717
const project = await create('ts-e2e-nightwatch', {
1818
plugins: {
1919
'@vue/cli-plugin-typescript': {},
20-
'@vue/cli-plugin-e2e-cypress': {}
20+
'@vue/cli-plugin-e2e-nightwatch': {}
2121
}
2222
})
23-
await project.run(`vue-cli-service e2e`)
23+
await project.run(`vue-cli-service test:e2e`)
2424
})

packages/@vue/cli-plugin-typescript/__tests__/tsPluginUnit.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('mocha', async () => {
99
'@vue/cli-plugin-unit-mocha': {}
1010
}
1111
})
12-
await project.run(`vue-cli-service test`)
12+
await project.run(`vue-cli-service test:unit`)
1313
})
1414

1515
test('jest', async () => {
@@ -19,7 +19,7 @@ test('jest', async () => {
1919
'@vue/cli-plugin-unit-jest': {}
2020
}
2121
})
22-
await project.run(`vue-cli-service test`)
22+
await project.run(`vue-cli-service test:unit`)
2323
})
2424

2525
test('jest w/ babel', async () => {
@@ -30,5 +30,5 @@ test('jest w/ babel', async () => {
3030
'@vue/cli-plugin-unit-jest': {}
3131
}
3232
})
33-
await project.run(`vue-cli-service test`)
33+
await project.run(`vue-cli-service test:unit`)
3434
})

packages/@vue/cli-plugin-unit-jest/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
55
## Injected Commands
66

7-
- **`vue-cli-service test`**
7+
- **`vue-cli-service test:unit`**
88

9-
Run unit tests with Jest. Default files matches are:
9+
Run unit tests with Jest. Default `testMatch` is `<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))` which matches:
1010

11-
- Any files in `tests/unit` that end in `.spec.(js|ts)`;
12-
- Any js/ts files inside `__tests__` directories.
11+
- Any files in `tests/unit` that end in `.spec.(js|jsx|ts|tsx)`;
12+
- Any js(x)/ts(x) files inside `__tests__` directories.
1313

14-
Usage: `vue-cli-service test [options] <regexForTestFiles>`
14+
Usage: `vue-cli-service test:unit [options] <regexForTestFiles>`
1515

1616
All [Jest command line options](https://facebook.github.io/jest/docs/en/cli.html) are also supported.
1717

@@ -22,6 +22,5 @@ Jest can be configured via `jest.config.js` in your project root, or the `jest`
2222
## Installing in an Already Created Project
2323

2424
``` sh
25-
npm install -D @vue/cli-plugin-unit-jest
26-
vue invoke unit-jest
25+
vue add unit-jest
2726
```

packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('base', async () => {
1515
}
1616
])
1717

18-
expect(pkg.scripts.test).toBeTruthy()
18+
expect(pkg.scripts['test:unit']).toBe('vue-cli-service test:unit')
1919
expect(pkg.devDependencies).toHaveProperty('@vue/test-utils')
2020
expect(pkg.devDependencies).toHaveProperty('babel-jest')
2121
expect(files['tests/unit/.eslintrc.js']).toMatch('jest: true')

packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('should work', async () => {
99
'@vue/cli-plugin-unit-jest': {}
1010
}
1111
})
12-
await project.run(`vue-cli-service test`)
12+
await project.run(`vue-cli-service test:unit`)
1313
})
1414

1515
test('should respect jest testMatch config', async () => {
@@ -26,7 +26,7 @@ test('should respect jest testMatch config', async () => {
2626

2727
let result
2828
try {
29-
await project.run(`vue-cli-service test`)
29+
await project.run(`vue-cli-service test:unit`)
3030
} catch (e) {
3131
result = e
3232
}
@@ -50,7 +50,7 @@ test('should respect jest.config.js testMatch config', async () => {
5050

5151
let result
5252
try {
53-
await project.run(`vue-cli-service test`)
53+
await project.run(`vue-cli-service test:unit`)
5454
} catch (e) {
5555
result = e
5656
}

packages/@vue/cli-plugin-unit-jest/generator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = api => {
22
api.render('./template')
33
api.extendPackage({
44
scripts: {
5-
test: 'vue-cli-service test'
5+
'test:unit': 'vue-cli-service test:unit'
66
},
77
devDependencies: {
88
'@vue/test-utils': '^1.0.0-beta.10'
@@ -31,7 +31,7 @@ module.exports = api => {
3131
'jest-serializer-vue'
3232
],
3333
'testMatch': [
34-
'<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))'
34+
'<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))'
3535
]
3636
}
3737

0 commit comments

Comments
 (0)