netsuite-suitecloud-sdk icon indicating copy to clipboard operation
netsuite-suitecloud-sdk copied to clipboard

Allow custom stubs to have ES6 module syntax

Open dylbarne opened this issue 3 years ago • 0 comments

Your environment

OS : Windows 10 Node.js version : v16.13.0 suitecloud-cli version : 1.3.1 Terminal/CMD tool : VSCodeTerminal

Describe the bug

When attempting to create a custom stub using ES6 module syntax, does appear in callback dependency of AMD Suitescript module in a usable way - is instead having .default property.

To Reproduce

Steps to reproduce the behavior:

  1. Create a simple NetSuite module custom stub in ES6 module syntax
    • setup custom stub in jest.config.json using documented SuiteCloudJestConfiguration.build
  2. leverage mock of stub in sample SuiteScript code
    • attempt to run test on SuiteScript file
  3. debug test and observe mock is not of a usable format - has .default instead

Actual Behavior

Unable to effectively use ES6 style custom stubs

Expected Behavior

Should be able to use ES6 style custom stubs

Additional context

  • from my initial investigation, issue is the same underlying cause described by : https://stackoverflow.com/questions/33704714/cant-require-default-export-value-in-babel-6-x
  • similarly, solution would be to use https://www.npmjs.com/package/babel-plugin-add-module-exports as an additional plugin in SuiteCloudJestTransformer.js https://github.com/oracle/netsuite-suitecloud-sdk/blob/master/packages/unit-testing/jest-configuration/SuiteCloudJestTransformer.js
  • you can observe behavior in Babel repl https://babeljs.io/en/repl , copying existing plugin used for Transformer https://www.npmjs.com/package/babel-plugin-transform-amd-to-commonjs
    • initially there is only exports.default with new instance of class image but then after adding recommended additional plugin 'babel-plugin-add-module-exports' it will include line module.exports = exports.default; which is needed to use externally in standard testing flow leveraging custom stubs as documented

dylbarne avatar Nov 17 '21 18:11 dylbarne