Map/Reduce Script Testing and Troubleshooting

You have several options to test and debug your map/reduce script:

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

Note:

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:

  1. From NetSuite, select Documents > Files > File Cabinet.

  2. Select SuiteScript 2.0 API to download the zip folder.

  3. Extract the mapReduceContext and mapReduceSummary .js files.

Related Topics

SuiteScript 2.x Map/Reduce Script Reference
Map/Reduce Terminology
Map/Reduce Script Stages
Map/Reduce Yielding
Map/Reduce Script Submission
Map/Reduce Governance
Map/Reduce Script Status Page
Map/Reduce Script Error Handling

General Notices