Skip to content

Commit 9afb4e4

Browse files
committed
renaming to redirect
1 parent cecc79b commit 9afb4e4

File tree

14 files changed

+30
-32
lines changed

14 files changed

+30
-32
lines changed

test-apps/new-cypress-config/redirect/cypress/plugins/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test-apps/new-cypress-config/redirect/cypress/support/e2e.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test-apps/new-cypress-config/redirect/package.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

test-apps/new-cypress-config/redirect/app.js renamed to test-apps/redirect/app.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// The redirect code needs to be un-instrumented, otherwise the statement map will be different depending on which code path the redirect took.
2-
// 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).
3-
// 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.
4-
// Timeouts are necessary to allow cypress to pick up the "initial" coverage object and compare it to the existing coverage objects.
1+
// This redirect code needs to be un-instrumented (excluded in .nycrc.json)
2+
// - 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).
3+
// - 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).
4+
5+
import { returnToApp } from './utils'
56

7+
// Timeouts are necessary to allow cypress to pick up the "initial" coverage object and compare it to the existing coverage objects.
68
new Promise((resolve) => {
79
if (window.location.port === '1234' && !localStorage.getItem('visited')) {
810
localStorage.setItem('visited', true)
@@ -22,6 +24,5 @@ new Promise((resolve) => {
2224
}, 500)
2325
}
2426
}).then(() => {
25-
document.body
26-
.appendChild(document.createTextNode('Returned to app'))
27+
returnToApp()
2728
})

test-apps/new-cypress-config/redirect/cypress.config.js renamed to test-apps/redirect/cypress.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = defineConfig({
44
fixturesFolder: false,
55
e2e: {
66
setupNodeEvents(on, config) {
7-
return require('./cypress/plugins/index.js')(on, config)
7+
require('@cypress/code-coverage/task')(on, config)
8+
return config
89
},
910
baseUrl: 'http://localhost:1234',
1011
env: {

test-apps/new-cypress-config/redirect/cypress/e2e/spec.cy.js renamed to test-apps/redirect/cypress/e2e/spec.cy.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
/// <reference types="Cypress" />
44

55
context('Page test', () => {
6-
7-
it('logs names', function() {
6+
it('redirects back to the app', function() {
87
cy.clearLocalStorage()
98
cy.visit("http://localhost:1234")
109
cy.contains("Returned to app")
1110
})
12-
1311
})
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
import '@cypress/code-coverage/support'
2-
console.log('this is commands file')

test-apps/redirect/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "example-redirect",
3+
"description": "Tests a frontend app that redirects, through un-instrumented code, back to itself.",
4+
"devDependencies": {
5+
"@babel/core": "^7.12.0"
6+
},
7+
"scripts": {
8+
"cy:run": "cypress run",
9+
"start:app": "parcel serve -p 1234 index.html",
10+
"start:other-app": "parcel serve -p 1235 index.html",
11+
"pretest": "rimraf .nyc_output .cache coverage dist",
12+
"test": "start-test start:app http://localhost:1234 start:other-app http://localhost:1235 cy:run",
13+
"coverage:verify": "npx nyc report --check-coverage true --lines 100",
14+
"coverage:check-files": "check-coverage utils.js && only-covered utils.js"
15+
}
16+
}

test-apps/redirect/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const returnToApp = () => {
2+
document.body
3+
.appendChild(document.createTextNode('Returned to app'))
4+
}

0 commit comments

Comments
 (0)