-
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 6 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,7 @@ | ||
{ | ||
"exclude": [ | ||
"support-utils.js", | ||
"task-utils.js" | ||
"task-utils.js", | ||
"support.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
3 changes: 3 additions & 0 deletions
3
test-apps/new-cypress-config/returning-to-application/.babelrc
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"] | ||
} |
3 changes: 3 additions & 0 deletions
3
test-apps/new-cypress-config/returning-to-application/README.md
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: frontend | ||
|
||
Tests a frontend app that redirects, through un-instrumented code, back to itself. |
34 changes: 34 additions & 0 deletions
34
test-apps/new-cypress-config/returning-to-application/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,34 @@ | ||
import { map } from 'lodash' | ||
|
||
// The redirect code needs to be un-instrumented, otherwise the statement map will be different | ||
// depending on which code path the redirect took. | ||
// Cypress will then correctly treat them as different coverage objects and merge the code coverage. | ||
// If the redirect code is un-instrumented, Cypress can't tell them apart and will keep referencing to the (stale) first coverage object. | ||
fvclaus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Timeouts are necessary to allow cypress to pick up the "initial" coverage object | ||
// and compare it to the existing coverage objects. | ||
eval(` | ||
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(() => { | ||
document.body | ||
.appendChild(document.createTextNode('Returned to app')) | ||
}); | ||
|
||
|
17 changes: 17 additions & 0 deletions
17
test-apps/new-cypress-config/returning-to-application/cypress.config.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,17 @@ | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
fixturesFolder: false, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
return require('./cypress/plugins/index.js')(on, config) | ||
}, | ||
baseUrl: 'http://localhost:1234', | ||
env: { | ||
codeCoverage: { | ||
exclude: ['cypress/**/*.*'] | ||
} | ||
}, | ||
chromeWebSecurity: false | ||
} | ||
}) |
13 changes: 13 additions & 0 deletions
13
test-apps/new-cypress-config/returning-to-application/cypress/e2e/spec.cy.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,13 @@ | ||
// enables intelligent code completion for Cypress commands | ||
// https://on.cypress.io/intelligent-code-completion | ||
/// <reference types="Cypress" /> | ||
|
||
context('Page test', () => { | ||
|
||
it('logs names', function() { | ||
cy.clearLocalStorage(); | ||
cy.visit("http://localhost:1234") | ||
cy.contains("Returned to app") | ||
}) | ||
|
||
}) |
4 changes: 4 additions & 0 deletions
4
test-apps/new-cypress-config/returning-to-application/cypress/plugins/index.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 @@ | ||
module.exports = (on, config) => { | ||
require('@cypress/code-coverage/task')(on, config) | ||
return config | ||
} |
2 changes: 2 additions & 0 deletions
2
test-apps/new-cypress-config/returning-to-application/cypress/support/commands.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,2 @@ | ||
import '@cypress/code-coverage/support' | ||
console.log('this is commands file') |
1 change: 1 addition & 0 deletions
1
test-apps/new-cypress-config/returning-to-application/cypress/support/e2e.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 @@ | ||
require('./commands') |
4 changes: 4 additions & 0 deletions
4
test-apps/new-cypress-config/returning-to-application/index.html
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> |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being excluded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you run the unit-tests, support.js is reported as having too little coverage, but support.js is not even being tested (only support-utils.js). I thought that this is an issue with my code, but I get the same result on the main branch.