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

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

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Nov 10, 2023

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:

  • postToContainer
  • listenToContainer

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 :)

Copy link

vercel bot commented Nov 10, 2023

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

@eunjae-lee eunjae-lee changed the base branch from main to EXT-2048-test-helper-for-field-plugin November 10, 2023 16:55
@BibiSebi
Copy link
Contributor

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 BibiSebi force-pushed the EXT-2048-test-helper-for-field-plugin branch from 0368d2d to 7f7df22 Compare November 14, 2023 13:15
@BibiSebi BibiSebi force-pushed the chore/testing-helper-take-2 branch from 876280f to 9330de9 Compare November 14, 2023 13:15
@BibiSebi
Copy link
Contributor

BibiSebi commented Nov 14, 2023

@BibiSebi
Copy link
Contributor

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)

@eunjae-lee eunjae-lee force-pushed the EXT-2048-test-helper-for-field-plugin branch from 7f7df22 to 4bbec28 Compare November 28, 2023 15:49
@eunjae-lee eunjae-lee closed this Nov 28, 2023
@BibiSebi BibiSebi deleted the chore/testing-helper-take-2 branch February 8, 2024 16:34
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

Successfully merging this pull request may close these issues.

2 participants