Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Applying polyfill before loading mocha

See original GitHub issue

I am trying to run emulated IE9- tests for my error manager lib using the folowing custom launcher:

            IE9: {
                base: 'IE',
                'x-ua-compatible': 'IE=EmulateIE9',
                flags: ['-extoff']

I got the following error message:

IE 11.0.0 (Windows 7.0.0) ERROR: 'This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.'

IE 11.0.0 (Windows 7.0.0) ERROR
    "message": "'Uint8Array' nincs definiálva\nat node_modules/mocha/mocha.js:6676",
    "str": "'Uint8Array' nincs definiálva\nat node_modules/mocha/mocha.js:6676"

So mocha requires Uint8Array to run and I need a polyfill to fix this. I have found a typedarray polyfill, which might work on IE9- browsers too:

I just don’t know how I can apply it before running mocha. Adding it to the files array does not work, since it is loaded after mocha. Any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

dwightjackcommented, Mar 19, 2018

@maksimr @inf3rno

Thanks! Was able to fix the problem with:

const fixMocha = function(files) {
    pattern: path.resolve('./node_modules/core-js/client/core.js'),
    included: true,
    served: true,
    watched: false

fixMocha.$inject = ['config.files'];

module.exports = (config) => {
     frameworks: ['mocha', 'inline-mocha-fix'],

     plugins: [
            'framework:inline-mocha-fix': ['factory', fixMocha]

I’m using core-js but I think it should work with other libraries as well

jslegerscommented, Apr 24, 2019

Anyway, do I understand correctly that the described approach polyfills everything that is loaded instead of just mocha?

If that is indeed the expected behavior, I don’t think this is a suitable approach for a test runner.

The whole point of testing in IE9 & IE10 is usually to detect whether those browsers don’t break because you rely on features not present in such old browsers. Adding a polyfill for ES6 features in your test environment kinda prevents you from detecting this problem.

I’d rather just use Mocha v4 instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Mocha 6 ES6 tests with Babel 7, how to set up?
Below steps are for applying Babel transformations & core-js polyfills for your tests file: All transformations are only done per current ...
Read more >
Building: Polyfills loader - Modern Web
The polyfills loader makes it easy to manage loading polyfills and/or serving different versions of your application based on browser support.
Read more >
Testing in ES6 with Mocha and Babel 6 - James K Nelson
Loading babel-polyfill in your tests won't load it for your consumers too. Be careful.
Read more >
Shimming - webpack
To be safe and robust, polyfills/shims must run before all other code, and thus either need to load synchronously, or, all app code...
Read more >
Shimming - webpack 3 documentation
Before we do anything let's take another look at our project: project ... we can add the logic to conditionally load our new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found