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
This is discussed more thoroughly in #993. I'm going to break out the discussion into a new issue. There are currently some issues when using ArcGIS REST JS v4 with Jest:
You need to use >jest@28.0.0 to get support for conditional imports. This allows Jest to properly load the CJS or ESM modules.
Doing all the config steps for ESM in Jest/ts-jest doesn't seem entirely necessary. For example https://github.com/sandromartis/arcgis-rest-js-segfault/pull/1 I was able to not include the recommended transform config and it still worked. I was also able to leave module: commonjs in the package.json. Your mileage may vary on these things.
It would be great if Jest worked OOTB either by supporting ESM OOTB or if the seg faul bug was fixed. We can either:
Hope the segmentation fault bug is resolved in Node JS 20. this should resolve the issue but would require users to upgrade to Jest 28+ and Node 20+ which would be April 2023 at the earliest.
Split the @esri/arcgis-rest-fetch package into 3 packages.
A @esri/arcgis-rest-fetch package which loads:
@esri/arcgis-rest-fetch-esm which uses node-fetch@3 for ESM environments
@esri/arcgis-rest-fetch-cjs which uses node-fetch@2 for Common JS environments
This avoids the dynamic import which avoids the segmentation fault error.
Switch to Undici and work on ArcGIS REST JS 5.0.0. This would require Node 16+ (the current LTS) and use Undici which is a CommonJS module in Node 16 and optionally use the built in fetch at Node 18+. Since you can import CJS into
modules into ESM this avoids a dynamic import.
I don't really like any of these, however with lots of teams using Jest inside Esri this will hinder adoption of v4.
Seems like we are just waiting for a fix for FAR to long. If this doesn't get released in April 2023 this might persist until 2025 and we just have to implement other options anyway.
This seems like a maintenance nightmare and reverting to node-fetch@2 might introduce who-knows-what security and other bugs.
This seems premature given that we just released v4 and wanted to wait on v5 so we could incorporate some other work. Rushing v5 to fix what might just be a shoddy implementation in a popular test framework doesn't feel right.
I think my final call would be to see if this gets fixed in Node 20. If it does great. If it doesn't start work on ArcGIS REST JS 5 and switch to Undici. The other option is to just make your Jest tests use ES modules which does work today.
The text was updated successfully, but these errors were encountered:
With the recent success of these configs I think we are OK to just tell people to enable the ESM support and hope that the Node JS team stabilizes it soon.
TL:DR; if you want to use ArcGIS REST JS v4 in Jest you need to enable the experimental support for ESM in Jest. If you also using ts-jest you need to enable support for ESM in ts-jest as well.
This is discussed more thoroughly in #993. I'm going to break out the discussion into a new issue. There are currently some issues when using ArcGIS REST JS v4 with Jest:
>jest@28.0.0
to get support for conditional imports. This allows Jest to properly load the CJS or ESM modules.@esri/arcgis-rest-fetch.
This runs into Segmentation fault withimport()
instead of callingimportModuleDynamically
nodejs/node#35889.Doing all the config steps for ESM in Jest/ts-jest doesn't seem entirely necessary. For example https://github.com/sandromartis/arcgis-rest-js-segfault/pull/1 I was able to not include the recommended
transform
config and it still worked. I was also able to leavemodule: commonjs
in the package.json. Your mileage may vary on these things.It would be great if Jest worked OOTB either by supporting ESM OOTB or if the seg faul bug was fixed. We can either:
Hope the segmentation fault bug is resolved in Node JS 20. this should resolve the issue but would require users to upgrade to Jest 28+ and Node 20+ which would be April 2023 at the earliest.
Split the
@esri/arcgis-rest-fetch
package into 3 packages.@esri/arcgis-rest-fetch
package which loads:@esri/arcgis-rest-fetch-esm
which usesnode-fetch@3
for ESM environments@esri/arcgis-rest-fetch-cjs
which usesnode-fetch@2
for Common JS environmentsThis avoids the dynamic import which avoids the segmentation fault error.
Switch to Undici and work on ArcGIS REST JS 5.0.0. This would require Node 16+ (the current LTS) and use Undici which is a CommonJS module in Node 16 and optionally use the built in
fetch
at Node 18+. Since you canimport
CJS intomodules into ESM this avoids a dynamic import.
I don't really like any of these, however with lots of teams using Jest inside Esri this will hinder adoption of v4.
node-fetch@2
might introduce who-knows-what security and other bugs.I think my final call would be to see if this gets fixed in Node 20. If it does great. If it doesn't start work on ArcGIS REST JS 5 and switch to Undici. The other option is to just make your Jest tests use ES modules which does work today.
The text was updated successfully, but these errors were encountered: