Map/Reduce Script Testing and Troubleshooting
You can test and debug your map/reduce script in several ways:
-
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.
The SuiteScript Debugger can't be used for deployed map/reduce script debugging. However, you may want to test any dependencies on other types of scripts. To test existing scripts, set the Script Deployment Status to Testing and ensure the logged-in user is the script 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, split it into entry point sections. Use these sections to create 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, use assertion statements to check the states, behavior, inputs, and outputs. 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 files serve as a schema for testing or mocking properties and methods. To access the files, follow these steps:
-
From NetSuite, select Documents > Files > File Cabinet.
-
Select SuiteScript 2.0 API to download the zip folder.
-
Extract the mapReduceContext and mapReduceSummary .js files.