How to silence warnings in the tests

I am getting warnings when running my tests in Jest saying TextDecoder module doesn’t exist pc.Untar may not work. The warnings still persist when I mock the console. They also persist when I add empty object as TextDecoder in global variables…

What lines and files do these warnings come from?

well I am rendering a React application that starts playcanvas application in it’s componentDidMount method which is basically called as soon as the canvas is mounted to the DOM. and in the tests I am using react-testing-library and jest but I keep getting this warning each time I render the application. Also leaks to test suites that have nothing to do with playcanvas sometimes…

There’s no line / file shown in the warning? Trying to track back to what is doing the console.warn? Can you post a screenshot of the whole warning please?

Sorry @yaustar I took a while but these are the line warnings in my jest files

      TextDecoder not supported - pc.Untar module will not work

      at UntarScope (node_modules/playcanvas/build/output/playcanvas.js:42187:15)
      at node_modules/playcanvas/build/output/playcanvas.js:42390:3
      at node_modules/playcanvas/build/output/playcanvas.js:42392:2
      at node_modules/playcanvas/build/output/playcanvas.js:9:26
      at Object.<anonymous> (node_modules/playcanvas/build/output/playcanvas.js:13:2)

Looks like whatever work pipeline doesn’t have TextDecoder support which PlayCanvas uses for asset bundles.

Unfortunately, the only way to get rid of that warning is to remove a function call in the engine (UntarScope())

If you do mock TextDecoder function, you have to do it before the PlayCanvas engine include.

Ohhhhhh thanks @yaustar I just sorted it by using

// jest.config.json
"setupFilesAfterEnv": ["jest-expect-message", "./tests/setup"], 
// ./tests/setup.json
global.TextDecoder = jest.fn()
1 Like