This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
docs(screener-io): added documentation on how to write tests with steps #856
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9095257
draft change for the docs
5907196
added doctoc generated links
248255b
Merge branch 'master' into docs/screener-test-runs
silviuaavram 775d384
added changelog
d127157
fixed a comment
2f3e9ba
a few improvements in the docs
2f2623f
Merge branch 'master' into docs/screener-test-runs
silviuaavram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,12 @@ Test a feature | |
| - [isConformant (required)](#isconformant-required) | ||
| - [Writing tests](#writing-tests) | ||
| - [Running tests](#running-tests) | ||
| - [Screener Tests](#screener-tests) | ||
| - [Tests with Steps API](#tests-with-steps-api) | ||
| - [Example for a test file:](#example-for-a-test-file) | ||
| - [Important mentions:](#important-mentions) | ||
| - [Run Screener tests](#run-screener-tests) | ||
| - [Local run command](#local-run-command) | ||
|
|
||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
|
||
|
|
@@ -103,4 +109,49 @@ yarn test | |
| yarn test:watch | ||
| ``` | ||
|
|
||
| [1]: https://github.com/stardust-ui/react/tree/master/test/specs/commonTests | ||
| [1]: https://github.com/stardust-ui/react/tree/master/test/specs/commonTests | ||
|
|
||
| ## Screener Tests | ||
|
|
||
| For some components, it is necessary to write screenshot tests in order to check that they render properly. For each component example added to the docsite a screenshot test is automatically created. This checks if that the component is rendered in a consistent way, as it looks for visual differences between the previous rendering and the current one. We use [screener-io](https://screener.io/) to achieve screenshot testing. | ||
|
|
||
| ### Tests with Steps API | ||
|
|
||
| This default test only checks the rendering for the component in its initial state. In order to test the rendering of more complex components, such as a `Dropdown`, screener provides an [api](https://www.npmjs.com/package/screener-runner) to execute actions on the DOM, in a way similar to end-to-end tests. These tests are executed by Screener as long as both the tests and their files respect the conventions: | ||
| - the test file should be placed at the same location as the component example under test. | ||
| - the test file should be named exactly as the component example file. If `DropdownExample.shorthand.tsx` is to be tested, the screener test file should be named `DropdownExample.shorthand.steps.ts`. | ||
| - the tests should be written as an array of callbacks that accept a `steps` parameter, as all of them will be chained in `screener.config`. The `steps` parameter is actually the `Steps` object from screener, instantiated in `screener.config`. | ||
|
|
||
| #### Example for a test file: | ||
|
|
||
| ```tsx | ||
| import { Dropdown } from '@stardust-ui/react' | ||
|
|
||
| const steps = [ | ||
| steps => steps.click(`.${Dropdown.slotClassNames.triggerButton}`) | ||
| .snapshot('Opens dropdown list'), | ||
| steps => steps.hover(`.${Dropdown.slotClassNames.itemsList} li:nth-child(2)`) | ||
| .snapshot('Highlights an item'), | ||
| ] | ||
|
|
||
| export default steps | ||
| ``` | ||
|
|
||
| #### Important mentions: | ||
|
|
||
| - by convention, each test is written as a different callback and added to the steps array. | ||
| - an actual assertion is performed by taking a `.snapshot(<Your test name here>)`, as the assertion is performed by comparing the screenshot with the one taken on the previous run and considered correct. | ||
| - a test can have as many snapshots as needed. | ||
| - before the snapshot is taken, steps are added to reach the state of assertion, with methods from `screener-runner` API (`.click(<selector>)`, `.hover(<selector>)`etc.) | ||
| - tests do not perform any cleanup by default. This means a test is dependent on the state of the component in which the previous test leaves it. In the example above, the second test will receive the `Dropdown` component with the list open. | ||
|
|
||
| ### Run Screener tests | ||
| In order to run the tests locally, make sure to have a Screener API key saved in the environment variables on your machine. For instance, on MacOS/Linux you can use `export SCREENER_API_KEY=<Your screener key here>`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what is for Windows? 🔍 This should work: cross-env SCREENER_API_KEY=<Your screener key here> yarn test:visual
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oups. will address this in my arrow navigation PR :) |
||
|
|
||
| When ran locally, not all the tests may be needed to run, only the ones added/edited. This can be achieved by changing the regexp in `screener.config.js`, where the `states` property is created. Make sure not to commit that change though! Results can be viewed in the Screener online dashboard, among all the other runs (for master, pull requests, etc.) | ||
silviuaavram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #### Local run command | ||
|
|
||
| ```bash | ||
| yarn test:visual | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.