Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab9868a

Browse files
committedJun 19, 2024·
adding test
1 parent 1e036ad commit ab9868a

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed
 

‎support.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,11 @@ const registerHooks = () => {
6666
windowCoverageObjects = []
6767

6868
const saveCoverageObject = (win) => {
69-
// accessing win.__coverage__ will error when testing cross-origin code
70-
// because we don't control cross-origin code anyway, we can safely return
71-
try {
72-
win.__coverage__
73-
} catch {
74-
return
75-
}
76-
77-
// if application code has been instrumented, the app iframe "window" has an object
78-
const applicationSourceCoverage = win.__coverage__
69+
// if the application code has been instrumented, then the app iframe "win.__coverage__" will be available,
70+
// in addition, accessing win.__coverage__ can throw when testing cross-origin code,
71+
// because we don't control the cross-origin code, we can safely return
72+
let applicationSourceCoverage
73+
try { applicationSourceCoverage = win?.__coverage__ } catch {}
7974
if (!applicationSourceCoverage) {
8075
return
8176
}

‎test-apps/frontend/.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"plugins": ["istanbul"]
2+
"plugins": ["istanbul"],
3+
"ignore": ["**/*.cy.js"]
34
}

‎test-apps/frontend/cypress.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports = defineConfig({
66
setupNodeEvents(on, config) {
77
return require('./cypress/plugins/index.js')(on, config)
88
},
9+
hosts: {
10+
'foobar.com': '127.0.0.1',
11+
},
912
baseUrl: 'http://localhost:1234',
1013
env: {
1114
codeCoverage: {

‎test-apps/frontend/cypress/e2e/spec.cy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ context('Page test', () => {
2525
cy.contains('h2', 'About')
2626
cy.contains('Est. 2019')
2727
})
28+
29+
it('loads cross origin page using cy.origin', () => {
30+
cy.origin('http://foobar.com:1234', () => {
31+
cy.visit('/')
32+
})
33+
})
34+
35+
it('loads cross origin page without cy.origin', () => {
36+
cy.visit('http://foobar.com:1234')
37+
})
2838
})
2939

3040
context('Unit tests', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.