You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I found that esbuild-jest doesn't work with binary loaders, i.e., it results in incorrect data.
It turns out this, it's because rather than using the source code text that jest provides (which seems to have certain encoding), esbuild-jest should pass the actual file contents to esbuild.transformSync().
I have a working solution, and tried to contribute back, but there were other package version changes, so I was afraid of breaking other things unintentionally. So, decided to raise an issue here instead.
Here's my workaround by adding a custom jest transformer:
const{ transformSync }=require('esbuild');const{ readFileSync }=require('fs');/** * This transformer is used to transform binary files using esbuild. * * This is needed because esbuild-jest currently does not handle binary files transformation properly. */module.exports={process(sourceText,sourcePath){// read the file contents directly rather than using sourceText,// which is a string rather than the actual dataconstfileData=readFileSync(sourcePath);const{ code }=transformSync(fileData,{loader: 'binary'});return{
code,};},};
The text was updated successfully, but these errors were encountered:
jameschao
changed the title
Not working for binary loaders
Issue with binary loaders + workaround
Aug 14, 2023
Hi, I found that
esbuild-jest
doesn't work withbinary
loaders, i.e., it results in incorrect data.It turns out this, it's because rather than using the source code text that jest provides (which seems to have certain encoding),
esbuild-jest
should pass the actual file contents toesbuild.transformSync()
.esbuild
v0.14.52 added a fix for handling binary contents properly intransform
, and this was referenced evanw/esbuild#2424 also.I have a working solution, and tried to contribute back, but there were other package version changes, so I was afraid of breaking other things unintentionally. So, decided to raise an issue here instead.
Here's my workaround by adding a custom jest transformer:
The text was updated successfully, but these errors were encountered: