Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test the library? Can we collect some ideas? #16

Open
didoo opened this issue Mar 31, 2021 · 3 comments
Open

How to test the library? Can we collect some ideas? #16

didoo opened this issue Mar 31, 2021 · 3 comments

Comments

@didoo
Copy link
Owner

didoo commented Mar 31, 2021

I have worked a little bit on the library (see #13) and it would have been super helpful to have a suite of tests to be sure that I was not breaking anything during the refactoring. I want to collect here some ideas, to see if we can come up with something that can be useful.

Jest testing + Mocks
Potentially we could use Jest to test the API calls (using mocks for the API responses), even if I am not 100% sure how much this would be helpful (eg. we would not notice a change a break in the code if Figma updates their APIs, because we're mocking them). Any ideas of possible workaround or approaches for testing API interfaces?

Figma file
We could have a Figma file (.fig) attached to repo, that one can import and then, updating the file ID/key in a specific file, one can run a set of tests against that file (eg. during the development I created a script that listed/posted/deleted comments to a file). Of course, we can't test every API method (eg. we would need a team) but maybe a subset of calls could be tested directly using the real Figma APIs (we test the requests me make, we tests the responses we receive). We could even go further, and create a Figma user (with an email owned by @Morglod) with a base license (in that case I suppose you can test even more calls).

Any other ideas, suggestions?

/cc @honzatmn maybe you have also some ideas :)

@didoo
Copy link
Owner Author

didoo commented Apr 1, 2021

For reference: jemgold/figma-js#2

@Morglod
Copy link
Collaborator

Morglod commented Apr 6, 2021

Smth like:

  1. Use figma-api-gen to generate schemas for methods & types
  2. Create readonly-public figma file with tons of different nodes, effects, properties
  3. Call api on figma file & test it with schemas

Its also necessary, because figma's api doc is not really accurate; some nodes & apis was different in real use (one of the reason for 'yet another api package')

Also with figma-api-gen is planned to use diffs on generated schemas to automatically find changes in api; it may be useful for testing suite

@gossi
Copy link
Contributor

gossi commented Nov 11, 2021

Whoops, I came here by accident, but I have an idea 😂

From what I read is what you want to do is use contract testing (instead of mocks). Tools like polly.js can do that (would be my goto). They record the API response and store it in a file (you commit that file to the repo). Next time tests are run, they use the file (if available) and replay the response. If the file cannot be found another recording will be done. The recorded response is a snapshot at a given time. To update the tests, all you have to do is delete the file and run the tests again.

... now that I describe that, it is mocks - but automated? 😅

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants