Model based testing made easy with xstate-marionettist #1541
Replies: 8 comments 9 replies
-
Your API seems neat! Thought about using Playwright? It has similar API Puppeteer; same old devs even! But Playwright from start aimed to be cross-browser compatible, vs Puppeteer had been Chrome-focused. Has been a while since I looked at them though. |
Beta Was this translation helpful? Give feedback.
-
This looks great! I am more pro-Cypress than pro-puppeteer. Is there any way you could pass in an API via a prop and have Typescript infer which one you chose? Or are there things specific to puppeteer you need to make this work? |
Beta Was this translation helpful? Give feedback.
-
This whole thing has primarily been born out of a need to intercept and mock all network requests. The project at work didn't have good support for full end-to-end tests. But also all network responses are strictly typed and validated with io-ts so in a sense all possible responses (including failures) were known and could confidently be mocked. The tricky part is looking at the generated test model's pathway and deducing what events are going to cause network requests that should be interrupted. |
Beta Was this translation helpful? Give feedback.
-
I've got another example here https://github.com/rjdestigter/xstate-marionettist-conduit that is testing https://realworld.svelte.dev/ It was a really good exercise writing a test for something I didn't build. I found a few bugs and edge cases that need fixing. The difficult part is understanding when to defer network requests and when to continue resolving them. I would like to make that more inuitive. |
Beta Was this translation helpful? Give feedback.
-
I've added support for Playwright as well. |
Beta Was this translation helpful? Give feedback.
-
That's awesome. I had multiple attempts to start using |
Beta Was this translation helpful? Give feedback.
-
I've got some preliminary support for Cypress done! https://github.com/rjdestigter/xstate-marionettist/tree/cypress/packages/cypress I haven't published anything yet because I have to update the README and I want to add some more (edge) cases and make sure everything is stable. I am using the experimental The code has cleaned up quite a bit and shareable abstractions between all three test runners is located in a core folder. Running yarn
yarn build
cd example/app
yarn start && yarn cypress open |
Beta Was this translation helpful? Give feedback.
-
Alright, it's all out the door. Cypress' route2 API is definitely not fully stable yet though. To make it work with the conduit example I had to add an additional You can experiment with it by installing {
"experimentalNetworkStubbing": true,
} to your cypress.json configuration. |
Beta Was this translation helpful? Give feedback.
-
I've taken some boiler plate code that I have been using in projects at work and published it into a package!: https://github.com/rjdestigter/xstate-marionettist
I'm using this to make writing model based tests using Jest, XState, and Puppeteer quicker and easier. Especially if you want to write end-to-end (ish) tests that mock all possible network responses. You can try it out and have a look by cloning the project or follow the instructions on how to add it to your project. I would really love some feedback on this.
The goal is really to just have a simple "language" to create these tests and not have to worry about integrating XState with Puppeteer.
Beta Was this translation helpful? Give feedback.
All reactions