Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 2d74195

Browse files
authored
docs(screener-io): added documentation on how to write tests with steps (#856)
* draft change for the docs * added doctoc generated links * added changelog * fixed a comment * a few improvements in the docs
1 parent fc0d558 commit 2d74195

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

.github/test-a-feature.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Test a feature
1111
- [isConformant (required)](#isconformant-required)
1212
- [Writing tests](#writing-tests)
1313
- [Running tests](#running-tests)
14+
- [Screener Tests](#screener-tests)
15+
- [Tests with Steps API](#tests-with-steps-api)
16+
- [Example for a test file:](#example-for-a-test-file)
17+
- [Important mentions:](#important-mentions)
18+
- [Run Screener tests](#run-screener-tests)
19+
- [Local run command](#local-run-command)
1420

1521
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1622

@@ -103,4 +109,49 @@ yarn test
103109
yarn test:watch
104110
```
105111

106-
[1]: https://github.com/stardust-ui/react/tree/master/test/specs/commonTests
112+
[1]: https://github.com/stardust-ui/react/tree/master/test/specs/commonTests
113+
114+
## Screener Tests
115+
116+
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.
117+
118+
### Tests with Steps API
119+
120+
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:
121+
- the test file should be placed at the same location as the component example under test.
122+
- 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`.
123+
- 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`.
124+
125+
#### Example for a test file:
126+
127+
```tsx
128+
import { Dropdown } from '@stardust-ui/react'
129+
130+
const steps = [
131+
steps => steps.click(`.${Dropdown.slotClassNames.triggerButton}`)
132+
.snapshot('Opens dropdown list'),
133+
steps => steps.hover(`.${Dropdown.slotClassNames.itemsList} li:nth-child(2)`)
134+
.snapshot('Highlights an item'),
135+
]
136+
137+
export default steps
138+
```
139+
140+
#### Important mentions:
141+
142+
- by convention, each test is written as a different callback and added to the steps array.
143+
- 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.
144+
- a test can have as many snapshots as needed.
145+
- 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.)
146+
- 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.
147+
148+
### Run Screener tests
149+
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>`.
150+
151+
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.)
152+
153+
#### Local run command
154+
155+
```bash
156+
yarn test:visual
157+
```

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2929
### Fixes
3030
- Focus the last focused element which triggered `Popup` on ESC @sophieH29 ([#861](https://github.com/stardust-ui/react/pull/861))
3131

32+
### Documentation
33+
- Add screener with steps testing documentation @silviuavram ([#856](https://github.com/stardust-ui/react/pull/856))
34+
3235
<!--------------------------------[ v0.20.0 ]------------------------------- -->
3336
## [v0.20.0](https://github.com/stardust-ui/react/tree/v0.20.0) (2019-02-06)
3437
[Compare changes](https://github.com/stardust-ui/react/compare/v0.19.2...v0.20.0)

0 commit comments

Comments
 (0)