Skip to content

Commit baf1645

Browse files
committed
docs: update the documentation of the tests
1 parent e1158fb commit baf1645

File tree

7 files changed

+162
-694
lines changed

7 files changed

+162
-694
lines changed

docs/testing/converting-old-tests.md

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: Real-world component testing
2+
title: Cypress component testing
33
category: Testing
4-
order: 5
4+
order: 3
55
---
66

7-
# Real-world component testing
7+
# Cypress component testing
88

99
Sometimes unit test behaviour doesn't match how our components work in the browser (e.g. no ResizeObserver)
10-
InstUI uses [Cypress Component Testing](https://docs.cypress.io/guides/component-testing/overview) for these cases. These are located at `instructure-ui/cypress/component/`.
10+
InstUI uses [Cypress Component Testing](https://docs.cypress.io/guides/component-testing/overview) in these cases to run tests in a real-world environment.
1111

1212
### Running tests
1313

@@ -17,9 +17,14 @@ You can run them from the root with the following command:
1717
npm run cy:component
1818
```
1919

20+
Run specific test file:
21+
```
22+
npm run cy:component -- --spec "cypress/component/Alerts.cy.tsx"
23+
```
2024
### Creating new tests
2125

22-
New tests should be added under `instructure-ui/cypress/component/[ComponentName].cy.tsx`
26+
New tests should be added under `cypress/component/`
27+
By convention we name test files after the component they are testing like `cypress/component/[ComponentName].cy.tsx`
2328

2429
Cypress tests usually have a structure like this:
2530

@@ -28,7 +33,7 @@ Cypress tests usually have a structure like this:
2833
type: code
2934
---
3035
import React from 'react'
31-
import { ComponentToTest } from '../../packages/ui'
36+
import { ComponentToTest } from '@instructure/ui'
3237
import '../support/component'
3338

3439
describe('<ComponentToTest/>', () => {
@@ -38,9 +43,12 @@ describe('<ComponentToTest/>', () => {
3843
})
3944
})
4045
```
41-
4246
You can read more about cypress testing from their [docs](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Writing-tests) and their [React Examples](https://docs.cypress.io/guides/component-testing/react/examples).
4347

48+
### Example
49+
You can view our code base on GitHub. The component tests can be found [here](https://github.com/instructure/instructure-ui/tree/master/cypress/component).
50+
51+
4452
### Debugging tests
4553

4654
To run cypress in a non-headless mode, use the following command:
@@ -78,3 +86,9 @@ describe('real events testing', () => {
7886
})
7987
})
8088
```
89+
90+
91+
### Configuration Setup
92+
Here you can find the key configuration files and folder locations used for our test environment:
93+
- [cypress/support](https://github.com/instructure/instructure-ui/tree/master/cypress/support)
94+
- [cypress.config.ts](https://github.com/instructure/instructure-ui/blob/master/cypress.config.ts)

docs/testing/testing-components.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

docs/testing/testing-overview.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Testing
3+
category: Testing
4+
order: 1
5+
---
6+
7+
## Testing
8+
9+
This page provides an overview of the testing strategies we use to ensure the quality and stability of our components. We use a combination of modern tools to support our testing needs. Each tool serves a different purpose in our testing pyramid, from unit-level validations to full-blown visual and behavioral regression tests.
10+
11+
### Technologies Used:
12+
13+
#### Vitest + React Testing Library:
14+
15+
These tools are our primary stack for writing component-level unit tests. They are lightweight and fast. [Vitest](https://vitest.dev/guide/) is one of the fastest modern testing framework. It offers a Jest-like API and runs in a Node.js environment, making it ideal for testing individual components and functions in isolation. Paired with [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), Vitest encourages accessible and maintainable test practices by querying elements the way users interact with them. It's best suited for testing component logic, rendering conditions, and props/state changes without needing a full browser environment. For a deeper dive into Vitest unit testing, check out our [detailed guides and examples.](/#vitest-unit-testing)
16+
17+
#### Cypress Component Testing:
18+
19+
[Cypress Component Testing](https://docs.cypress.io/app/component-testing/get-started) allows you to mount individual components in a real browser environment for precise interaction testing. Unlike traditional unit tests, it renders with full CSS and browser APIs, offering more realistic behavior. This makes it ideal for testing user interactions like clicks, keyboard navigation, focus traps, and animations. While a bit heavier than Vitest, it provides greate visibility and debugging capabilities for complex UI logic. For a deeper dive into Cypress component testing, check out our [detailed guides and examples.](#cypress-component-testing)
20+
21+
#### Chromatic Visual Regression Testing with Cypress:
22+
23+
We use [Cypress](https://docs.cypress.io/app/tooling/visual-testing) end-to-end tests to generate structured layouts and capture screenshots of components. [Chromatic](https://www.chromatic.com/docs/diff-inspector/) handles the visual diffing and review process. It's especially effective for catching layout shifts, styling regressions, or broken UI elements that don’t trigger functional test failures. Tests are run after changes are pushed, comparing the new screenshots to a baseline stored from a previously verified state. When differences are detected, the test fails and provides side-by-side diffs for easy review. This type of testing is particularly valuable for pixel-perfect components, design systems, or any feature with strict visual requirements.
24+
25+
#### Cypress Behavioral Regression Testing:
26+
27+
[Cypress Behavioral Regression Testing](https://docs.cypress.io/app/end-to-end-testing/writing-your-first-end-to-end-test) focuses on simulating realistic user flows across complex components or pages to ensure key behaviors remain stable. These tests often replicate critical workflows like navigation, and keyboard interactions. They are useful after feature changes or refactors, as they verify that the components still behaves correctly from the user’s perspective. Since the tests run in a real browser, they provide visibility into full-stack behavior, including browser APIs. These more complex end-to-end style tests are helps catch integration issues or regressions that unit and visual tests may overlook.

docs/testing/ui-test-utils.md

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)