Mock Grist Plugin Api to improve dev experience

Hello everyone,

I’m currently learning how to develop a custom widget for Grist, and I’m wondering if anyone knows a good solution for mocking the Grist API.

So far, I’ve been deploying my web page (the Grist widget), grabbing the link, and then checking what happens directly inside Grist… which is obviously not very practical.

I suppose I could write a small JS mock like this:

if (window.self !== window.top) return; // running inside Grist, do nothing

window.grist = {
  ready() {},

  onRecord(fn) {
    callbacks.record.push(fn);
    fireCurrentRecord();
  },

  onRecords(fn) {
    callbacks.records.push(fn);
    fn(mockData.records.map(r => r.fields));
  },

  onOptions(fn) {
    callbacks.options.push(fn);
    fn({});
  },

  getTable() {
    return {
      fetchRecords: async () => mockData.records
    };
  },
};

I have a GitHub repository containing multiple widgets, each using different kinds of data and interacting differently with the Grist API.

So I was wondering whether someone has already thought about a clean way to organize and manage this kind of setup.

Running Grist and a little webserver locally is how I develop widgets. Grist itself is a good mock for the Grist API :). One path is described in GitHub - gristlabs/grist-widget: A repository of custom widgets to embed in Grist documents · GitHub if you haven’t already seen it.

I do think there’s an opportunity to do something better and more user-friendly with GitHub - gristlabs/grist-static: Showing Grist spreadsheets on a static website, without a special backend. · GitHub

1 Like

I’ll look into this, thank you.
Do you set up E2E tests as well?

the grist-widget repo does have some end-to-end browser tests.

at my company, we have a local Grist on docker. I create a server at pythin serving a directory with the code.

at home, I do the same, but use Grist Desktop

when all is fine and dandy, I send to github.

Was able to develop some pretty neat stuff that way

like this SWOT

and this indicators panel

2 Likes