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 aaf6ad0

Browse files
authoredJul 3, 2024··
fix: fix error when testing cross-origin code (#685)
1 parent 5b07e59 commit aaf6ad0

File tree

6 files changed

+8974
-43701
lines changed

6 files changed

+8974
-43701
lines changed
 

‎.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040
steps:
4141
- checkout
4242
- run:
43-
name: Install node 16
44-
command: nvm install 16.16.0
43+
name: Install node 20
44+
command: nvm install 20.12.1
4545
- run:
46-
name: Use node 16
47-
command: nvm use 16.16.0
46+
name: Use node 20
47+
command: nvm use 20.12.1
4848
- run:
4949
name: Install deps for code coverage
5050
command: npm ci

‎package-lock.json

Lines changed: 8948 additions & 43694 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎support.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ const registerHooks = () => {
6666
windowCoverageObjects = []
6767

6868
const saveCoverageObject = (win) => {
69-
// if application code has been instrumented, the app iframe "window" has an object
70-
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 {
74+
applicationSourceCoverage = win?.__coverage__
75+
} catch {}
7176
if (!applicationSourceCoverage) {
7277
return
7378
}

‎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.