-
Notifications
You must be signed in to change notification settings - Fork 111
fix: code coverage incomplete on redirect #660
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
emilyrohrbough
merged 15 commits into
cypress-io:master
from
fvclaus:fix/coverage-on-application-reload
Oct 25, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
61b65d1
fix: Coverage on application reload
fvclaus 170a13e
fix: Add test for coverage with redirect
fvclaus f72fa04
fix: Add test config for return-to-application
fvclaus 688444d
fix: Failing return-to-application test
fvclaus bee4f56
fix: Prettier and code coverage
fvclaus 30133ba
Merge branch 'master' into fix/coverage-on-application-reload
mschile afcf617
Update test-apps/new-cypress-config/returning-to-application/app.js
fvclaus 62a85b7
Merge branch 'master' into fix/coverage-on-application-reload
cacieprins 634b511
Merge branch 'master' into fix/coverage-on-application-reload
mschile cecc79b
renaming example to redirect
mschile 9afb4e4
renaming to redirect
mschile 216a537
updating circleci config
mschile 3a47754
exclude support.js
mschile 998d58b
removing support-utils
mschile efddda5
removing unneeded package-lock
mschile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"exclude": [ | ||
"support-utils.js", | ||
"support.js", | ||
"task-utils.js" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["istanbul"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"exclude": [ | ||
"app.js" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# example: redirect | ||
|
||
Tests a frontend app that redirects, through un-instrumented code, back to itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This redirect code needs to be un-instrumented (excluded in .nycrc.json) | ||
// - If the redirect code is instrumented, Cypress would then treat them as different coverage objects and merge the code coverage (not testing what we want). | ||
// - If the redirect code is un-instrumented, Cypress can't tell them apart and will update the existing coverage object to point to the correct one (testing what we want). | ||
|
||
import { returnToApp } from './utils' | ||
|
||
// Timeouts are necessary to allow cypress to pick up the "initial" coverage object and compare it to the existing coverage objects. | ||
new Promise((resolve) => { | ||
if (window.location.port === '1234' && !localStorage.getItem('visited')) { | ||
localStorage.setItem('visited', true) | ||
console.log('Not visited. Redirecting') | ||
setTimeout(() => { | ||
window.location.href = 'http://localhost:1235' | ||
}, 500) | ||
} else if (window.location.port === '1235') { | ||
console.log('Redirecting back.') | ||
setTimeout(() => { | ||
window.location.href = 'http://localhost:1234' | ||
}, 500) | ||
} else { | ||
console.log('Visited'); | ||
setTimeout(() => { | ||
resolve() | ||
}, 500) | ||
} | ||
}).then(() => { | ||
returnToApp() | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
fixturesFolder: false, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
require('@cypress/code-coverage/task')(on, config) | ||
return config | ||
}, | ||
baseUrl: 'http://localhost:1234', | ||
env: { | ||
codeCoverage: { | ||
exclude: ['cypress/**/*.*'] | ||
} | ||
}, | ||
chromeWebSecurity: false | ||
} | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// enables intelligent code completion for Cypress commands | ||
// https://on.cypress.io/intelligent-code-completion | ||
/// <reference types="Cypress" /> | ||
|
||
context('Page test', () => { | ||
it('redirects back to the app', function() { | ||
cy.clearLocalStorage() | ||
cy.visit("http://localhost:1234") | ||
cy.contains("Returned to app") | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@cypress/code-coverage/support' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<body> | ||
<h2>Test page</h2> | ||
<script src="app.js"></script> | ||
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "example-redirect", | ||
"description": "Tests a frontend app that redirects, through un-instrumented code, back to itself.", | ||
"devDependencies": { | ||
"@babel/core": "^7.12.0" | ||
}, | ||
"scripts": { | ||
"cy:run": "cypress run", | ||
"start:app": "parcel serve -p 1234 index.html", | ||
"start:other-app": "parcel serve -p 1235 index.html", | ||
"pretest": "rimraf .nyc_output .cache coverage dist", | ||
"test": "start-test start:app http://localhost:1234 start:other-app http://localhost:1235 cy:run", | ||
"coverage:verify": "npx nyc report --check-coverage true --lines 100", | ||
"coverage:check-files": "check-coverage utils.js && only-covered utils.js" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const returnToApp = () => { | ||
document.body | ||
.appendChild(document.createTextNode('Returned to app')) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.