Unable to test Netsuite scripts with Jest

Hi!
I’m having a problem testing my netsuite scripts using Jest because of how netsuite scripts import other files.
In our SDF project, We have several scripts, that are our “main logic” – our script deployments, And we also have some util scripts and configuration files, that are used by our script deployments.
We started working on unit testing with jest (suitecloud new project added jest to the project), and discovered that when running the tests on our scripts, Jest doesn’t recognize the imported util scripts and config files, as it does not support such imports with define([<path_to_file>], (<reference_to_file)).
We tried using other JS forms of import, such as:
const <refrense_to_file> = require(“<path_to_file>”)
or
import <refrense_to_file> from “<path_to_file>”
and they work perfectly with Jest, but when running the scripts in Netsuite itself, we got those error (in order of the examples above)
type”:”error.SuiteScriptModuleLoaderError”,”name”:”INCORRECT_SUITESCRIPT_CONFIGURATION”,”message”:”Incorrect SuiteScript configuration for module: ../Config/Config.js”,”stack”:[“at /SuiteScripts/Utils/Util.js:19:57”]}
type”:”error.SuiteScriptModuleLoaderError”,”name”:”SyntaxError: /SuiteScripts/Utils/Util.js:6:0 Expected an operand but found import\nimport Config from ‘../Config/config.js’;\n^\n”,”message”:””,”stack”:[]}
does anyone know how to make both jest (or any other unit testing) and Netsuite work sumultaneously?
Rookie Asked on July 12, 2023 in SuiteScript.

This repo contains a working example of Jest unit tests for modules which include other modules, including custom and native modules.

on July 12, 2023.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor