diff --git a/cypress/about.html b/cypress/about.html new file mode 100644 index 00000000..7316e847 --- /dev/null +++ b/cypress/about.html @@ -0,0 +1,5 @@ +
+Open the DevTools to see console messages
diff --git a/cypress/integration/spec.js b/cypress/integration/spec.js index 4aa19ae0..c353c07d 100644 --- a/cypress/integration/spec.js +++ b/cypress/integration/spec.js @@ -12,6 +12,8 @@ context('Page test', () => { cy.spy(win.console, 'log').as('log') } }) + + cy.contains('About').click() }) it('logs names', function () { diff --git a/support.js b/support.js index c1a6e1e0..04c2e650 100644 --- a/support.js +++ b/support.js @@ -19,6 +19,8 @@ const sendCoverage = coverage => { if (Cypress.env('coverage') === false) { console.log('Skipping code coverage hooks') } else { + let windowCoverageObjects + before(() => { // we need to reset the coverage when running // in the interactive mode, otherwise the counters will @@ -26,20 +28,28 @@ if (Cypress.env('coverage') === false) { cy.task('resetCoverage', { isInteractive: Cypress.config('isInteractive') }) }) - afterEach(() => { - // save coverage after each test - // because the entire "window" object is about - // to be recycled by Cypress before next test - cy.window().then(win => { + beforeEach(() => { + windowCoverageObjects = [] + + // save reference to coverage for each app window loaded in the test + cy.on('window:load', win => { // if application code has been instrumented, the app iframe "window" has an object const applicationSourceCoverage = win.__coverage__ if (applicationSourceCoverage) { - sendCoverage(applicationSourceCoverage) + windowCoverageObjects.push(applicationSourceCoverage) } }) }) + afterEach(() => { + // save coverage after the test + // because now the window coverage objects have been updated + windowCoverageObjects.forEach(coverage => { + sendCoverage(coverage) + }) + }) + after(() => { // there might be server-side code coverage information // we should grab it once after all tests finish