Vue: Runtime exception: performance is not defined - with v2.6.9

Created on 14 Mar 2019  ·  12Comments  ·  Source: vuejs/vue

Version

2.6.8

Reproduction link

https://jsfiddle.net/chrisvfritz/50wL7mdz/

Steps to reproduce

It is throwing from the vue/dist/vue.js file of the latest version I am currently trying to isolate it, yet it seems connected with the new code added recently. Will add more steps ASAP if you still don't observe it.
1) replicated with this repo - https://github.com/vuejs/vue-test-utils-mocha-webpack-example
2) clone it
3) npm i
4) npm test - no error
4) npm update vue
5) npm test - ReferenceError: performance is not defined

Greetings,
Plamen

What is expected?

no error observed

What is actually happening?

an error is observed

bug has PR has workaround improvement

Most helpful comment

It seems that in jsdom environment:

> window.performance
Performance {}
> performance
ReferenceError: performance is not defined

So we have to use window.performace instead of calling performance directly to make the code run correctly in jsdom.

All 12 comments

Please provide a repro when reporting bugs

Hi @posva,
The issue is not replicated with an online editor yet I have provided steps with a project from github under the Steps to reproduce section.
Greetings,
Plamen

The thing you linked to is an archived and deprecated example. A repro doesn't have to be jsfiddle, it can be an HTML file (or just the contents of it). It also shouldn't include other dependencies like mocha or vue-test-utils (it could be a problem on that package). Cheers.

Thanks for writing back!
Hm - I will try another approach - 'performance' that is at this line is not declared anywhere in the file. We have a window.performance and config.performance yet I don't see any global 'performance'. It came with the latest release because here is not present.

Once you run a static analyze on the file and it throws.

Greetings,
Plamen

Also getting this. Got a warning from my CI after Vue got upgraded to 2.6.9 (I use Renovate to keep deps up to date).

It seems that in jsdom environment:

> window.performance
Performance {}
> performance
ReferenceError: performance is not defined

So we have to use window.performace instead of calling performance directly to make the code run correctly in jsdom.

Okay, I think I opened the menu before you added the label improvement and clicked outside after you added the has PR label, so it removed it. Funny edge case

It should be noted that though JSDOM has a performance support via process.hrtime, I don't think we can guarantee current hack with performance will always work as expected in JSDOM environment (it's different from browsers' implementation after all).

@posva 😂

Until this is released, a workaround is to add the following lines after JSDOM registration:

// eslint-disable-next-line no-undef
global.performance = window.performance;

Until this is released, a workaround is to add the following lines after JSDOM registration:

// eslint-disable-next-line no-undef
global.performance = window.performance;

Sorry for being stupid but where do I add the following line since JSDOM registration is abstracted away in Vue CLI 3 and cli-plugin-unit-mocha (no setup.js)?

Thanks for the help...

// eslint-disable-next-line no-undef 
global.performance = window.performance;

Same question. Where do I add the following lines?

@theonlychase I placed it in my main test entry point test/setup.js it the same directory that contains your require('jsdom-global')

Referenced below at --require flag.

"test": "mocha-webpack --webpack-config webpack/webpack.config.test.js --require test/setup.js reporter mocha-bamboo-reporter"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wufeng87 picture wufeng87  ·  3Comments

lmnsg picture lmnsg  ·  3Comments

Jokcy picture Jokcy  ·  3Comments

hiendv picture hiendv  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments