Skip to content
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

performance.getEntriesByType is returning undefined #3625

Closed
atikenny opened this issue Mar 1, 2019 · 5 comments

Comments

3 participants
@atikenny
Copy link

commented Mar 1, 2019

Current behavior:

Overwrite window.performance.getEntriesByType with NOOP that returns undefined.

Desired behavior:

Don't overwrite window.performance.getEntriesByType.

Steps to reproduce: (app code and test code)

  • Use cy.clock to take over the timing functions
  • open a page
  • try to use methods on window.performance like getEntriesByType (you can include the Facebook JS SDK to reproduce this)

Stack trace from Facebook SDK JS

TypeError: Cannot read property 'filter' of undefined
      at c (https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:45:1484)
      at Object.<anonymous> (https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:164:238)
      at require (https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:24:620)
      at https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:165:223
      at https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:94:929
      at Array.forEach (<anonymous>)
      at c (https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:45:1604)
      at Object.fire (https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:94:894)
      at https://connect.facebook.net/en_US/sdk.js?hash=624278b338adcdb461a65444946d6779&ua=modern_es6:161:2263

Versions

Cypress 3.1.5, Chrome

@jennifer-shehane

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

@atikenny I've created a repo reproducing this bug here: https://github.com/jennifer-shehane/performance-entries

tests

it('does not call cy.clock', () => {
  // PASSES
  cy.visit('index.html')
})
  
it('calls cy.clock', () => {
  // FAILS
  cy.clock()
  cy.visit('index.html')
})

app code

var entries = window.performance.getEntriesByType("resource")
entries.length

results

screen shot 2019-03-01 at 2 17 01 pm

@atikenny

This comment has been minimized.

Copy link
Author

commented Mar 14, 2019

Forgot to post the workaround if anyone is running into the same thing:

cy.window().then(win => {
    win.performance.getEntriesByType = () => []
})

This needs to be executed after you took over the clock and the window of the page under test is loaded.

@flotwig flotwig self-assigned this May 2, 2019

@flotwig

This comment has been minimized.

Copy link
Member

commented May 2, 2019

This error comes from lolex (which provides cy.clock()'s functionality).

All performance functions are overridden with a NOOP which returns undefined: https://github.com/sinonjs/lolex/blob/53e32d410e3c0e6d18958b174394eb541d8aa71d/src/lolex-src.js#L852

Maybe I can open a PR so that the overridden functions at least return the correct type, to prevent this issue.

@cypress-bot

This comment has been minimized.

Copy link

commented Jun 4, 2019

The code for this is done in cypress-io/cypress#4108, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot

This comment has been minimized.

Copy link

commented Jun 27, 2019

Released in 3.3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.