Map/Reduce Script Testing and Troubleshooting
You have several options to test and debug your map/reduce script:
-
Make a separate unit test suite as you develop and modify your map/reduce script. See Map/Reduce Script Unit Testing.
-
Check the execution logs. See N/log Module.
-
Monitor the script status. See Map/Reduce Script Status Page and Programmatically Retrieving Script Instance Details.
-
Detect any server restarts that interrupted map/reduce script execution. See inputContext.isRestarted, mapContext.isRestarted, reduceContext.isRestarted, and summaryContext.isRestarted.
You cannot use the SuiteScript Debugger for deployed debugging of a map/reduce script type. However, you may want to test any dependencies on other types of scripts. Remember that to test existing scripts, the Script Deployment Status must be set to Testing and the currently logged in user must be listed as the script record owner. For information about the SuiteScript Debugger, see SuiteScript Debugger.
Map/Reduce Script Unit Testing
You cannot use the SuiteScript Debugger for deployed debugging of a map/reduce script type.
To test a map/reduce script on demand, you should split the script into entry point level sections. Use the sections to form unit tests. Each section should function as an entry point script that can be executed without external dependencies. If passing in modules, make sure that you use the require function and absolute paths.
To test map or reduce stages, you will need to create a mock context that seeds values and provides the dependent objects and parameters. Then, check the states, behavior, inputs, and outputs of map/reduce functions using assertion statements. Note that the getInputData stage does not take parameters, so it will not require mock context and can be tested more conventionally.
To test a summarize stage, if it contains logic operating on a final set of data that has no return, use assertions and logs to gather information.
To assist development of your unit test, download the SuiteScript 2.x API files, specifically those representing the mapContext, reduceContext, and summaryContext objects. These file can act as a schema for the properties and methods you want to test or mock. To access the files, do the following:
-
From NetSuite, select Documents > Files > File Cabinet.
-
Select SuiteScript 2.0 API to download the zip folder.
-
Extract the mapReduceContext and mapReduceSummary .js files.