javascriptreactjstypescriptjestjsjszip

JSZip generateAsync times out when run in jest


Very strange issue when I try to upgrade jest from v26 to v29.

A test executes

    console.log("before fzip", JSZip.support.blob);
    const fzip = await zip.generateAsync({ type: "blob" });
    console.log("fzip", fzip);

  1. If I run jest v26.6.x, it succeeds as long as I have jest-environment-jsdom v26.5.x in `package.json'
  2. If I remove jest-environment-jsdom, the call fails (goes to catch):
 error! TypeError: this._timerAPIs.setImmediate is not a function
          at FakeTimers._fakeSetImmediate 
  1. If I upgrade jest and jest-environment-jsdom to v29.0.x, the call times out. I can see the first log message but not the second.

Any ideas are greatly appreciated!


Solution

  • Just in case someone is interested.

    Apparently, JSZip.generateAsync calls setImmediate internally, so the following works:

    import {setImmediate} from “timers”
    …
    global.setImmediate = setImmediate
    

    (jest v27 was failing as it had an issue with setImmediate)