Solid Test Recorder
Chrome extension to generate UI unit/integration tests for solidjs
You can also use it for react or preact with little config tweaks.
- Generates UI tests which relay on vitest and msw which follow solidjs guidelines.
- Uses a combination of Chrome DevTools element inspector and console which gives great recording control e.g. terminal-like auto-completion.
- Auto-generates the most specific selector for inspected element.
- Records network requests and generates mocks and spies for them.
Writing UI tests is boring yet extremely important. This extension is meant to make it more fun and attract developers to write more tests.
First, you need to build it.
You can use Docker:
$ docker-compose up $ docker exec -it docker solid_test_recorder yarn build
or run these on your machine:
$ yarn install $ yarn build
Then, upload /dist directory as an unpacked extension. See this link.
As soon as you open Chrome DevTools, in console, you’ll get access to
$str (Solid Test Recorder) global var. You can execute
$str.help command for available commands.
The usual flow would be:
$str.clear // to start new test file $str.describe = 'my component' $str.it = 'should do something' $str.expect.toBeInTheDocument = true // use element inspector to choose the element, assert type and whether it's positive or negation
You’ll be also often capturing events e.g.:
$str.capture.click // or any available DOM event // click at the button in the browser $str.stopCapturing // and then again... $str.expect.toBeChecked = false // or any availble assert type in testing library
To see the results which will open as 2 vertical editors:
$str.seeResult // to close $str.closeEditor
In the first one you’ll see your test file, and the second is API mock data generated from the actual network requests.
In order to use the test, your
setupVitest.ts in the root directory should look like this
and you should create a
. ├── test │ └── mocked-requests.json └── setupVitest.ts
||allows to edit the code template used when generation test file|
||allows to specify list of URLs to ignore when capturing requests|
||creates a new test file with a given description|
||creates a new test case with a given description|
||adds a new asser on a currently selected element|
||starts event capturing i.e. auto-generation user events and subsequent requests|
||stops event capturing|
||opens editor with a generated test file and request mock|
||allows to reposition or remove test cases and test steps and setting their active cursors|
|Changing current test file/case:|
||allows to switch to a given test file|
||allows to switch to a given test case|
||saves changes and closes editor(s)|
||discards any changes and closes editor(s)|
||captured HTTP requests|
$str.clear– removes all the test data
- Produce short video tutorials as documentation.
- Convert it to TypeScript.
- Write e2e tests (how ironic?).
- Store tests in files which can be then uploaded (and sort of replayed).
Visit solidjs discord channel where I’ll be posting updates. Don’t hesitate to DM for any questions related to the project.
The codebase needs to be converted to TypeScript before it can be workable by a team. Also, I have an idea how to e2e test it, and this would also need to happen before any major logic changes. Anyway, feel free to create issues and PRs, just want to highlight the priorities.