storyblok / field-plugin

Create and deploy Storyblok Field Plugin
https://www.storyblok.com/docs/plugins/field-plugins/introduction
25 stars 3 forks source link

fix(template): testing helper PoC #2 #316

Closed eunjae-lee closed 8 months ago

eunjae-lee commented 9 months ago

What?

This is a different approach. Instead of mocking postMessage and addEventListener, this actually changes createFieldPlugin().

We used to have only createFieldPlugin() and now we also have internalCreateFieldPlugin(). The internalCreateFieldPlugin() accepts two more options:

The createFieldPlugin calls the internalCreateFieldPlugin with those implementations, but in our testing helper, we mock @storyblok/field-plugin, and replaces createFieldPlugin with different implementations of postToContainer and listenToContainer.

But this requires us to actually export internalCreateFieldPlugin from the library, which is not that big of a deal, in my opinion. (of course, we could rename it)

Not sure which take I prefer (the previous one and this)

but probably a good food for thought :)

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plugin-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2023 1:17pm
BibiSebi commented 9 months ago

I think this implementation is much easier to follow from the developer/consumer perspective.

I will create a stacked branch on top of this, and continue this approach. Maybe I will find out if there are any restrictions. :)

BibiSebi commented 9 months ago

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

BibiSebi commented 9 months ago

In the end I abstracted the first approach because I was struggling the extract the vi.mock from the file as it is hoisted. You can find more information here (https://storyblok.slack.com/archives/C04P3JBHWHW/p1700068753644059)