Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit 61eb3b0

Browse files
authored
feat: instrument code coverage by default (#339)
1 parent 2d486fc commit 61eb3b0

File tree

19 files changed

+273
-41
lines changed

19 files changed

+273
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ cypress/videos/
77
cypress/screenshots
88
.nyc_output
99
coverage
10+
*.tgz

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
> A little helper to unit test Vue components in the open source [Cypress.io](https://www.cypress.io/) E2E test runner **v4.5.0+**
1111
12-
**Jump to:** [Comparison](#comparison), [Blog posts](#blog-posts), Examples: [basic](#basic-examples), [advanced](#advanced-examples), [external](#external-examples), [Code coverage](#code-coverage)
12+
**Jump to:** [Comparison](#comparison), [Blog posts](#blog-posts), Examples: [basic](#basic-examples), [advanced](#advanced-examples), [full](#full-examples), [external](#external-examples), [Code coverage](#code-coverage)
1313

1414
## TLDR
1515

@@ -598,6 +598,16 @@ Spec | Description
598598
[mocking-imports](cypress/component/advanced/mocking-imports) | Stub ES6 imports from the tests
599599
<!-- prettier-ignore-end -->
600600

601+
### Full examples
602+
603+
We have several subfolders in [examples](examples) folder.
604+
605+
<!-- prettier-ignore-start -->
606+
Folder Name | Description
607+
--- | ---
608+
[cli](examples/cli) | An example app scaffolded using Vue CLI and the component testing added using `vue add cypress-experimental` command.
609+
<!-- prettier-ignore-end -->
610+
601611
### External examples
602612

603613
<!-- prettier-ignore-start -->

circle.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ workflows:
1111
- cypress/install:
1212
name: Install
1313
executor: cypress/base-12
14-
build: npm run build
14+
# creates files in "dist" folder
15+
build: |
16+
npm run build
17+
echo ""
18+
echo "Build package archive 📦"
19+
echo ""
20+
# first show the contents to be packed
21+
npm pack --dry
22+
echo ""
23+
echo "packing ..."
24+
echo ""
25+
npm pack
26+
echo ""
27+
ls -la
1528
post-steps:
1629
- run:
1730
name: Show info 📺
@@ -40,6 +53,41 @@ workflows:
4053
echo "Test files for this machine are $TESTFILES"
4154
npx cypress run --spec $TESTFILES
4255
56+
- cypress/run:
57+
name: Example CLI
58+
executor: cypress/base-12
59+
requires:
60+
- Install
61+
install-command: npm install
62+
verify-command: echo 'Already verified'
63+
no-workspace: true
64+
working_directory: examples/cli
65+
command: |
66+
echo "🦶🏻 Scaffolding component tests"
67+
echo ""
68+
# scaffolds Babel + Webpack combo
69+
npx --package @vue/cli vue add cypress-experimental
70+
echo ""
71+
echo "🦶🏻 test scaffolded project, should work"
72+
echo ""
73+
DEBUG=cypress-vue-unit-test npx cypress run --spec 'tests/components/**/*.js'
74+
# let's inspect the scaffolded app
75+
ls -la
76+
echo ""
77+
echo "🦶🏻 install the current cypress-vue-unit-test"
78+
echo ""
79+
npm install ../../cypress-vue-unit-test-0.0.0-development.tgz
80+
echo ""
81+
echo "🦶🏻 run component tests"
82+
echo ""
83+
DEBUG=cypress-vue-unit-test npx cypress run --spec 'tests/components/**/*.js'
84+
echo ""
85+
echo "🦶🏻 look at the generated files, should have coverage"
86+
# (after updating cypress-experimental)
87+
echo ""
88+
ls -la
89+
store_artifacts: true
90+
4391
# this job attaches the workspace left by the install job
4492
# so it is ready to run Cypress tests
4593
# only we will run semantic release script instead
@@ -55,6 +103,7 @@ workflows:
55103
requires:
56104
- Install
57105
- Test
106+
- Example CLI
58107
install-command: echo 'Already installed'
59108
verify-command: echo 'Already verified'
60109
no-workspace: true

cypress/plugins/index.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
// default webpack file preprocessor is good for simple cases
2-
const { onFileDefaultPreprocessor } = require('../../preprocessor/webpack')
3-
1+
/// <reference types="cypress" />
2+
const preprocessor = require('../../plugins/webpack')
43
module.exports = (on, config) => {
5-
require('@cypress/code-coverage/task')(on, config)
6-
on('file:preprocessor', onFileDefaultPreprocessor(config))
7-
8-
// IMPORTANT to return the config object
9-
// with the any changed environment variables
4+
preprocessor(on, config)
105
return config
116
}
12-
13-
/*
14-
for more complex cases, when the project already includes webpack.config.js
15-
16-
const {
17-
onFilePreprocessor
18-
} = require('cypress-vue-unit-test/preprocessor/webpack')
19-
module.exports = on => {
20-
on('file:preprocessor', onFilePreprocessor('../path/to/webpack.config'))
21-
}
22-
*/

cypress/support/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
require('@cypress/code-coverage/support')
2-
3-
beforeEach(() => {
4-
const container = document.getElementById('cypress-jsdom')
5-
if (container) {
6-
container.innerHTML = ''
7-
}
8-
})
1+
require('../../dist/support')

docs/manual-install.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
npm install -D cypress cypress-vue-unit-test
99
```
1010

11-
2. Include this plugin `cypress/plugin/index.js`
11+
2. Include this plugin from your project's `cypress/plugin/index.js` file
1212

1313
```js
14-
// default webpack file preprocessor is good for simple cases
15-
// Required to temporarily patch async components, chunking, and inline image loading
16-
import { onFileDefaultPreprocessor } from 'cypress-vue-unit-test/dist/preprocessor/webpack'
17-
18-
module.exports = (on) => {
19-
on('file:preprocessor', onFileDefaultPreprocessor)
14+
const preprocessor = require('cypress-vue-unit-test/dist/plugins/webpack')
15+
module.exports = (on, config) => {
16+
preprocessor(on, config)
17+
// IMPORTANT return the config object
18+
return config
2019
}
2120
```
2221

23-
3. Include the support file `cypress/support/index.js`
22+
3. Include the support file from your project's `cypress/support/index.js` file
2423

2524
```js
2625
import 'cypress-vue-unit-test/dist/support'

examples/cli/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
pnpm-debug.log*
14+
15+
# Editor directories and files
16+
.idea
17+
.vscode
18+
*.suo
19+
*.ntvs*
20+
*.njsproj
21+
*.sln
22+
*.sw?

examples/cli/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/cli/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# cli-example
2+
3+
Application scaffolded with Vue CLI v3

examples/cli/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

0 commit comments

Comments
 (0)