community-content icon indicating copy to clipboard operation
community-content copied to clipboard

[SUBMIT] How to write Jest tests for Strapi Plugins

Open cpaczek opened this issue 2 years ago • 4 comments

Introduction

If you a writing a plugin that lots of other people and companies or if other people are going to contribute to it tests are a must. We just had a security issue which could of been caught by unit tests. However, there are not guides on how to write tests for a custom Strapi plugin.

Outline

  • What is Jest
  • Add Jest to your plugin
  • Mocking the Strapi Object
  • Mocking ctx
  • Testing Controllers
  • Testing Services
  • Running Tests
  • Automatically Run Tests with Github Actions
  • Conclusion

My content is

  • [x] A Strapi Tutorial / Guide / How to article
  • [ ] About Headless, CMS, javascript, open source, or jamstack
  • [ ] Other, specify

I can write this article :) However I am curious as to what the payment structure/requirements are.

cpaczek avatar Aug 26 '22 01:08 cpaczek

Just finished up writing tests for my plugin hence why I want to write an article :) https://github.com/excl-networks/strapi-plugin-ezforms/tree/master/tests

cpaczek avatar Aug 26 '22 03:08 cpaczek

@Cpaczek great topic. You can start on it. Just confirm when you get started. Thank you. 🙂

PaulBratslavsky avatar Sep 07 '22 22:09 PaulBratslavsky

Hello @Cpaczek 👋 Could you confirm if you are writing this article?

dessireugarte avatar Sep 13 '22 12:09 dessireugarte

Hello @Cpaczek 👋 Could you confirm if you are writing this article?

Yes I plan on writing this, I don't have a firm timeline right now.

cpaczek avatar Sep 15 '22 02:09 cpaczek

Hello @Cpaczek! How is this topic doing? Let us know otherwise we will close this issue since it has taken a long time now.

dessireugarte avatar Oct 28 '22 10:10 dessireugarte

Hello @Cpaczek! How is this topic doing? Let us know otherwise we will close this issue since it has taken a long time now.

Hi, sorry been super busy, I don't have a set time to work on this so if someone else wants to take it over they can.

cpaczek avatar Nov 09 '22 18:11 cpaczek

@dessireugarte Here is the first draft, please let me know your thoughts: https://gist.github.com/Cpaczek/4c9d559cbfe13ffad5bc334ce4477ac6

I wrote it in markdown as I could not figure out how to duplicate the dropbox thing.

cpaczek avatar Nov 18 '22 06:11 cpaczek

Hello @Cpaczek 👋 Thanks for submitting the draft. We will review it, and if we have any comments or suggestions, we will let you know. Otherwise, we will publish it between the first and second week of January.

dessireugarte avatar Nov 29 '22 15:11 dessireugarte

Hello @Cpaczek 👋 Could you please register on the Write for the Community page form?

dessireugarte avatar Dec 23 '22 17:12 dessireugarte

Hello @Cpaczek 👋 Could you please register on the Write for the Community page form?

Done

cpaczek avatar Dec 23 '22 17:12 cpaczek

@Cpaczek I like your article, when reviewing it, I realized some people would like to follow along. But you only provided a completed example. I forked your repo and removed the jest, test and test.yaml file. This way folks can have a fresh start and follow along with your tutorial. I think it would be helpful to include it. Let me know what you think. Otherwise your article is all set to go.

PaulBratslavsky avatar Jan 05 '23 23:01 PaulBratslavsky

@Cpaczek I like your article, when reviewing it, I realized some people would like to follow along. But you only provided a completed example. I forked your repo and removed the jest, test and test.yaml file. This way folks can have a fresh start and follow along with your tutorial. I think it would be helpful to include it. Let me know what you think. Otherwise your article is all set to go.

Ya, that's probably a good idea, the reason why I didn't include it is I assumed people already had a plugin they wanted to add tests to. Do you want to make a PR to a new branch and just have 2 branches on the same repo or just have them in 2 different repos? Either way works for me.

cpaczek avatar Jan 05 '23 23:01 cpaczek

You can just share the link https://github.com/PaulBratslavsky/strapi-jest-tutorial just to keep it simple. Thank you.

PaulBratslavsky avatar Jan 05 '23 23:01 PaulBratslavsky

You can just share the link https://github.com/PaulBratslavsky/strapi-jest-tutorial just to keep it simple. Thank you.

Okay I added it to the Gist

cpaczek avatar Jan 06 '23 00:01 cpaczek

@Cpaczek this has been reviewed and scheduled for publishing will let you know when it goes live.

PaulBratslavsky avatar Jan 06 '23 23:01 PaulBratslavsky

Hello @Cpaczek! Thanks for submitting your invoice.

You should register yourself once as an "Individual Vendor" in this form, please let me know if you have any questions about the form. Just be aware that in the W-8BEN form:

  • 5 is not mandatory
  • 6a & 6b are only necessary if you have a tax number in your own country.

If you already did that step, then I would only be missing your proof of bank details (bank statement, bank letter, online screenshot). You can send the bank account details to my email address [email protected]

Please feel free to reach out to me if you have any questions!

dessireugarte avatar Jan 19 '23 19:01 dessireugarte

Hello @Cpaczek! Could you please confirm for us when you receive your payment?

dessireugarte avatar Feb 03 '23 17:02 dessireugarte

Hello @Cpaczek! Could you please confirm for us when you receive your payment?

Yes thank you

cpaczek avatar Feb 03 '23 20:02 cpaczek