Skip to content

Commit 7ae7442

Browse files
bahmutovrndmerle
authored andcommitted
fix: better filtering of support files (cypress-io#177)
* add filtering example with support files * working example * run example job on CI * start the server before testing * update support file filtering
1 parent e8c0720 commit 7ae7442

File tree

12 files changed

+120
-10
lines changed

12 files changed

+120
-10
lines changed

.circleci/config.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ workflows:
209209
- run:
210210
command: npx nyc report --check-coverage true --lines 100
211211
working_directory: examples/same-folder
212-
# how to fail if the specific file coverage is not found?!
213212
- run:
214213
command: npx nyc report --check-coverage true --lines 100 --include unit-utils.js
215214
working_directory: examples/same-folder
@@ -221,6 +220,37 @@ workflows:
221220
node ../../scripts/only-covered main.js unit-utils.js
222221
working_directory: examples/same-folder
223222

223+
- cypress/run:
224+
attach-workspace: true
225+
name: example-support-files
226+
requires:
227+
- cypress/install
228+
# there are no jobs to follow this one
229+
# so no need to save the workspace files (saves time)
230+
no-workspace: true
231+
start: npm start --prefix examples/support-files
232+
wait-on: 'http://localhost:1234'
233+
command: npx cypress run --project examples/support-files
234+
# store screenshots and videos
235+
store_artifacts: true
236+
post-steps:
237+
- run: cat examples/support-files/.nyc_output/out.json
238+
# store the created coverage report folder
239+
# you can click on it in the CircleCI UI
240+
# to see live static HTML site
241+
- store_artifacts:
242+
path: examples/support-files/coverage
243+
# make sure the examples captures 100% of code
244+
- run:
245+
command: npx nyc report --check-coverage true --lines 100
246+
working_directory: examples/support-files
247+
- run:
248+
name: Check code coverage 📈
249+
command: |
250+
node ../../scripts/check-coverage main.js
251+
node ../../scripts/only-covered main.js
252+
working_directory: examples/support-files
253+
224254
- publish:
225255
filters:
226256
branches:
@@ -235,3 +265,4 @@ workflows:
235265
- example-before-all-visit
236266
- example-ts-example
237267
- example-same-folder
268+
- example-support-files

examples/support-files/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["istanbul"]
3+
}

examples/support-files/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example: support-files
2+
3+
Filtering out support files

examples/support-files/cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"fixturesFolder": false,
3+
"pluginsFile": "cypress/plugins/index.js",
4+
"baseUrl": "http://localhost:1234"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="cypress" />
2+
it('works', () => {
3+
cy.visit('/')
4+
cy.contains('Page body')
5+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = (on, config) => {
2+
on('task', require('../../../../task'))
3+
on('file:preprocessor', require('../../../../use-babelrc'))
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../../../../support'
2+
console.log('this is commands file')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./commands')

examples/support-files/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<body>
2+
Page body
3+
<script src="main.js"></script>
4+
<script>
5+
// use functions creates in "main.js"
6+
if (add(2, 3) !== 5) {
7+
throw new Error('wrong addition')
8+
}
9+
if (sub(2, 3) !== -1) {
10+
throw new Error('wrong subtraction')
11+
}
12+
</script>
13+
</body>

examples/support-files/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.add = (a, b) => a + b
2+
3+
window.sub = (a, b) => a - b

0 commit comments

Comments
 (0)