Playwright has really good codegen tool, but you are stuck with Puppeteer. So I have written little library to use codegen’s output in Puppeteer. However this post is not about this library, but how I have written it.
What I have really enjoyed while writing this library that it has no direct dependencies (only dev dependencies) and writing library this way has several benefits:
-
I have defined interfaces using Typescript what my library expects. That’s all I need when I am using this library somewhere as Typescript will validate for me if parameters that I am passing are matching the interface. In my case it is Puppeteer page. As developer I don’t care what will be passed to my library:
-
It can be some brand new Puppeteer version that has methods I expect to be removed. Then user of my library will get Typescript error. As library’s developer I don’t need to worry about tracking which versions are supported.
-
It does not event have to be Puppeteer at all in case interface matches.
-
-
As there is no dependencies it is really fast and fun to work on it. This includes:
-
Installation for development.
-
Creating build.
-
Writing and running tests.
-
-
Output result is small as well.
Overall this is really nice way to write libraries and I recommend to try it out.