|
Testing scriptsThe quickest way to test that scripts work as expected, is to click the Preview tab at the bottom of the workspace. You can even do this while creating a new script, either with a Script Wizard or in the expanded script editor. Click Apply at the bottom of the script editor to see the effect of the script on the Preview tab of the Designer. Note that scripts that use values of data fields can only be effective when a data file Test for errorsAnother way to 'test' a script is to take a look at the Scripts pane. Hover over the name of a script in the Scripts pane to highlight parts of the template that are affected by the script.
Icons on the name of scripts in the Scripts pane can show a warning, information or error icon.
In addition to the icons and messages in the Scripts pane, there is another way to see if your scripts function as expected before generating output:
Preflight executes the template without actually producing output and it displays any issues once it’s done. It will tell, for example, which selectors were not encountered in the template. Test for speed issuesTo measure the time that the execution of scripts will take:
Profiling means running the scripts in the template, to see how fast scripts in the Scripts pane execute. It helps greatly in troubleshooting performance issues caused by scripts. After running the Script Profiler you can see in which sections the script has run:
You can also see the breakdown of the execution time across different execution stages:
The script execution stages are: Query: the time it takes to find the selector in the template. Looking for text is a rather lengthy operation. Use an ID (possibly in combination with a text) instead of a text selector to make the query faster. For more tips, see Optimizing scripts. Execution: the time it takes to execute the script. If you are an experienced JavaScript coder you may be able to optimize the code to speed up the execution of the script. Functions that actually change the content of the template (for example,append()) are comparatively time consuming. Avoid using such functions in a loop. For more tips, see Optimizing scripts. Note that the times vary slightly per run of the Script Profiler. Run the Script Profiler a number of times and calculate an average from the results, before trying to speed up the execution of a script. Script Profiler settingsNumber of runsBy default, the Script Profiler runs on 1000 instances of all the scripts. To test on a higher or lower number of instances:
SortingIn the Scripts Profiler, the scripts are by default sorted based on the values in the Elapsed column, from high to low. Click any of the columns to sort the scripts according to the values in that column. |
|