Added jest config to support test utility modules. (#6154) [deploy]
This commit is contained in:
parent
086b6ab202
commit
9630a174f9
4 changed files with 48 additions and 34 deletions
41
docs/tests/frontend-tests.md
Normal file
41
docs/tests/frontend-tests.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
title: Frontend Tests
|
||||
---
|
||||
|
||||
# Frontend Tests
|
||||
|
||||
The test code is located within the same directory as each component, inside a
|
||||
`__tests__` directory.
|
||||
|
||||
```shell
|
||||
$ tree app/javascript/article-form -L 1
|
||||
app/javascript/article-form
|
||||
├── __tests__
|
||||
└── articleForm.jsx
|
||||
```
|
||||
|
||||
The testing library being used is [Jest](https://jestjs.io/).
|
||||
|
||||
- For unit tests, use jest's [expect API](https://jestjs.io/docs/en/expect)
|
||||
- For snapshot testing of Preact components, use
|
||||
[preact-render-spy](https://github.com/mzgoddard/preact-render-spy) and
|
||||
[preact-render-to-json](https://github.com/nathancahill/preact-render-to-json).
|
||||
|
||||
You can run those tests with:
|
||||
|
||||
```shell
|
||||
npm run test
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
yarn test
|
||||
```
|
||||
|
||||
At the end of the test's execution, you will see the code coverage for the
|
||||
Preact components in our codebase.
|
||||
|
||||
If tests require utility modules, create them in a `utilities` folder under the
|
||||
`__tests__` folder. Jest is configured to not treat the `utilities` folder as a
|
||||
test suite.
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
---
|
||||
title: Preact Tests
|
||||
---
|
||||
|
||||
# Preact Tests
|
||||
|
||||
The test code is located within the same directory as each component, inside a
|
||||
`__tests__` directory.
|
||||
|
||||
```shell
|
||||
$ tree app/javascript/article-form -L 1
|
||||
app/javascript/article-form
|
||||
├── __tests__
|
||||
└── articleForm.jsx
|
||||
```
|
||||
|
||||
The testing library being used is [Jest](https://jestjs.io/).
|
||||
|
||||
You can run those tests with:
|
||||
|
||||
```shell
|
||||
npm run test
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
yarn test
|
||||
```
|
||||
|
||||
At the end of the test's execution, you will see the code coverage for the Preact
|
||||
components in our codebase.
|
||||
|
|
@ -4,7 +4,7 @@ items:
|
|||
- acceptance-tests.md
|
||||
- integration-tests.md
|
||||
- unit-functional-tests.md
|
||||
- preact-tests.md
|
||||
- frontend-tests.md
|
||||
- accessibility-tests.md
|
||||
- regression-tests.md
|
||||
- code-coverage.md
|
||||
|
|
|
|||
|
|
@ -12,5 +12,10 @@ module.exports = {
|
|||
snapshotSerializers: ['preact-render-spy/snapshot'],
|
||||
// The webpack config folder for webpacker is excluded as it has a test.js file that gets
|
||||
// picked up by jest if this folder is not excluded causing a false negative of a test suite failing.
|
||||
testPathIgnorePatterns: ['/node_modules/', './config/webpack'],
|
||||
testPathIgnorePatterns: [
|
||||
'/node_modules/',
|
||||
'./config/webpack',
|
||||
// Allows developers to add utility modules that jest won't run as test suites.
|
||||
'/__tests__/utilities/',
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue