Testing (mocking calls to) pack building blocks

Has someone already gone through the work of building tests for pack building blocks. Is there a good way of testing the entire execution of a formula/sync table, i.e. with some sample inputs for the params.

As a dev I would like to be able to write testing code that:

  • mocks/stubs fetcher.fetch network calls (also being able to waive auth)
  • for formulas (or sync table “formulas”), be able to emulate an execution of the formula with the specified params, and assert the result of the execute callback. same would be nice for get schema for dynamic sync tables.

The first seems straightforward, but I don’t see a clean way of accomplishing the second as it would probably requiring building test infra to mimic actual pack execution.

Come to think of it, a programmatic way of accessing the coda execute CLI script would be great, to write automated tests directly in JS without having to interface with the CLI.

Hi @loucadufault - I think both of those requests are already possible! Information on how to test Packs in the CLI is here:

Specifically it shows how to mock fetcher requests and run a Pack formula or sync table just like code execute does and then verify the results.

You can see some of these techniques in practice in the test directory of the GitHub sample for the CLI:

1 Like

Woah that looks great! Should have read the docs :upside_down_face: