Running Cloud Code In Testing

Is there a way to know if we are running cloud code in the editor itself for testing purposes? I want to be able to setup specific parameters for my Cloud Code Test

Yes. CloudCode exposes the source of the task execution. These can be tested by comparing, e.g. this.source === CloudCode.* with the following options:

CloudCode.EDITOR_TEST -> The developer pushed the "Test Task" Button.
CloudCode.ENQUEUE -> This task was called from another CloudCode task.
CloudCode.SCHEDULER -> This task was executed on a schedule configured in the config tab.
CloudCode.WEB -> Task executed from a web call
CloudCode.WEBHOOK -> Task executed via webhook.

This can be useful for tasks with multiple activation paths, so that the task will be able to function in a deterministic way whether the task is triggered with the context of a given object, or is being used to test, etc.

2 Likes