Skip to content

fix: improve spec filtering #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ workflows:
command: npm run coverage:check
working_directory: examples/ts-example

- cypress/run:
attach-workspace: true
name: example-same-folder
requires:
- cypress/install
# there are no jobs to follow this one
# so no need to save the workspace files (saves time)
no-workspace: true
command: npx cypress run --project examples/same-folder
# store screenshots and videos
store_artifacts: true
post-steps:
- run: cat examples/same-folder/.nyc_output/out.json
# store the created coverage report folder
# you can click on it in the CircleCI UI
# to see live static HTML site
- store_artifacts:
path: examples/same-folder/coverage
# make sure the examples captures 100% of code
- run:
command: npx nyc report --check-coverage true --lines 100
working_directory: examples/same-folder
# how to fail if the specific file coverage is not found?!
- run:
command: npx nyc report --check-coverage true --lines 100 --include unit-utils.js
working_directory: examples/same-folder

- publish:
filters:
branches:
Expand All @@ -181,3 +208,4 @@ workflows:
- example-before-each-visit
- example-before-all-visit
- example-ts-example
- example-same-folder
3 changes: 3 additions & 0 deletions examples/same-folder/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["istanbul"]
}
3 changes: 3 additions & 0 deletions examples/same-folder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# example: same-folder

Check if test files are correctly filtered out
6 changes: 6 additions & 0 deletions examples/same-folder/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"integrationFolder": ".",
"testFiles": "**/spec.js",
"supportFile": "support.js",
"pluginsFile": "plugins.js"
}
5 changes: 5 additions & 0 deletions examples/same-folder/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
4 changes: 4 additions & 0 deletions examples/same-folder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<body>
Page body
<script src="main-instrumented.js"></script>
</body>
146 changes: 146 additions & 0 deletions examples/same-folder/main-instrumented.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/same-folder/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.add = (a, b) => a + b

window.sub = (a, b) => a - b
8 changes: 8 additions & 0 deletions examples/same-folder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "example-same-folder",
"description": "Check if test files are correctly filtered out",
"devDependencies": {},
"scripts": {
"cy:open": "../../node_modules/.bin/cypress open"
}
}
4 changes: 4 additions & 0 deletions examples/same-folder/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (on, config) => {
on('task', require('../../task'))
on('file:preprocessor', require('../../use-babelrc'))
}
26 changes: 26 additions & 0 deletions examples/same-folder/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference types="cypress" />

import { reverse } from './unit-utils'

describe('coverage information', () => {
before(() => {
cy.log('visiting index.html')
cy.visit('index.html')
})

it('calls add', () => {
cy.window()
.invoke('add', 2, 3)
.should('equal', 5)
})

it('calls sub', () => {
cy.window()
.invoke('sub', 2, 3)
.should('equal', -1)
})

it('reverses a string', () => {
expect(reverse('Hello')).to.equal('olleH')
})
})
1 change: 1 addition & 0 deletions examples/same-folder/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../support'
5 changes: 5 additions & 0 deletions examples/same-folder/unit-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const reverse = s =>
s
.split('')
.reverse()
.join('')
8 changes: 4 additions & 4 deletions support.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ if (Cypress.env('coverage') === false) {

after(function mergeUnitTestCoverage() {
// collect and merge frontend coverage
const specFolder = Cypress.config('integrationFolder')
const supportFolder = Cypress.config('supportFolder')

// if spec bundle has been instrumented (using Cypress preprocessor)
// then we will have unit test coverage
Expand All @@ -145,10 +143,12 @@ if (Cypress.env('coverage') === false) {
if (unitTestCoverage) {
// remove coverage for the spec files themselves,
// only keep "external" application source file coverage
const supportFile = Cypress.config('supportFile')
const testFilePattern = Cypress.config('testFiles')

// does this handle unset support file?
const isTestFile = (fileCoverage, filename) =>
filename.startsWith(specFolder) || filename.startsWith(supportFolder)
Cypress.minimatch(filename, testFilePattern) || filename === supportFile

const coverage = Cypress._.omitBy(window.__coverage__, isTestFile)
sendCoverage(coverage, 'unit')
}
Expand Down