Page speed reported initial load JS for Walcron was large.
Page load was slow when throttled with slow 3G.
Analysis did
Check on browser the file size loaded. Found one of the big chunk goes up-to 837kb.
Ran `npm run analyze`, which was configured in next.config.js. Shows the big chunk was due to typescript ~902kb to load.
The whole project was written in typescript, but strangely it should was imported and wasn' compiled! Then did a search and found a file importing the WHOLE typescript !
Check alternative to find how 'eval' can be replaced. Unlike lodash, transpile is included only in typescript. Apparently eval can be replaced, it's actually Function.
Replaced code with Function and file size was fixed!
Testing with Object.defineProperty
Test suite that have Object.definedProperty override on certain behaviours cannot be redefined. If test case runs after it's used hence it cannot be erased.
Jest mocked import for library order is important and must always be the first to override the import of the original 3rd party library.
import "../__mocked__/pusherMock"; //mock library must be the first.
import X from "someComponentThatUsesPusher"
--OR--
jest.mock('pusher', () => class Pusher{});
import Pusher from 'pusher'; //then only it takes effect.
Jest library with 3rd party library import under NEXT.JS is unsolvable
Error of `Cannot use import statement outside a module`, cannot be solved at the moment when 3rd party library are executed via mock. Only solution is to mock the whole library with jest.mock('whole library').