Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/natterstefan/jest-preset-ns
An opinionated Jest preset for both react and non-react projects.
https://github.com/natterstefan/jest-preset-ns
babel jest jest-config jest-configuration jest-preset jest-preset-react typescript
Last synced: 7 days ago
JSON representation
An opinionated Jest preset for both react and non-react projects.
- Host: GitHub
- URL: https://github.com/natterstefan/jest-preset-ns
- Owner: natterstefan
- License: apache-2.0
- Created: 2020-02-22T19:38:29.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-23T03:27:20.000Z (about 1 year ago)
- Last Synced: 2024-09-22T11:05:59.413Z (about 2 months ago)
- Topics: babel, jest, jest-config, jest-configuration, jest-preset, jest-preset-react, typescript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/jest-preset-ns
- Size: 563 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# jest-preset-ns
[![npm version](https://badge.fury.io/js/jest-preset-ns.svg)](https://badge.fury.io/js/jest-preset-ns)
[![Node CI](https://github.com/natterstefan/jest-preset-ns/actions/workflows/ci.yml/badge.svg)](https://github.com/natterstefan/jest-preset-ns/actions/workflows/ci.yml)An opinionated
[Jest preset](https://facebook.github.io/jest/docs/configuration.html#preset-string)
for both react and non-react projects.It comes with two default presets with both babel and typescript support.
## Features
- default preset and preset for react are available
- modern javascript (babel) and typescript (ts-jest) support
- mocks files (eg. png, gif, jpg, ...) and date ([jest-date-mock][2])
automatically
- looks for tests in `__tests__` and for `*.(spec|test).[jt]s(x)?` files
- easy extendable## Installation
```bash
npm install --save-dev jest-preset-ns jest
# or
yarn add jest-preset-ns jest --dev
```## Usage
Add `jest-preset-ns` as
[preset](https://facebook.github.io/jest/docs/en/configuration.html#preset-string)
to your Jest config. This can be done by adding it to your `package.json` or
`jest.config.js`:```json
// package.json
{
"jest": {
"preset": "jest-preset-ns"
}
}
``````js
// jest.config.js
module.exports = {
preset: 'jest-preset-ns',
// or: preset: 'jest-preset-ns/presets/default'
// [...]
}
```Feel free to extend the `"jest"`-configuration object along the way with your
own settings.For running tests, use the [Jest CLI](https://jestjs.io/docs/en/cli).
## Compatibility
This package is compatible only with React 16+.
## Helpful tips
- [extend and adjust ts configuration][1]
- [prevent logging all the JSDOM internal errors](https://gist.github.com/natterstefan/8294b498afa35723ca92f3bf8451e533#file-jest-setup-ts)## How to Publish
```bash
# create the tags and the version
yarn lerna:version# create the changelog entry
npx lerna-changelog --from --to
git add CHANGELOG.md && git commit -m "chore: updated CHANGELOG"# push the tags and the changelog update
git push --follow-tags# publish to npm
yarn lerna:publish
```## References
- [jest getting-started](https://jestjs.io/docs/en/22.x/getting-started.html)
- [ts-jest preset][1]
([ts-jest presets source](https://github.com/kulshekhar/ts-jest/tree/v25.2.0/presets),
[ts-jest config source](https://github.com/kulshekhar/ts-jest/tree/v25.2.0/src/config))
- [jest defaults](https://github.com/facebook/jest/blob/v25.1.0/packages/jest-config/src/Defaults.ts)
- [hops jest-preset](https://github.com/xing/hops/blob/v12.1.1/packages/jest-preset)
- [amex-jest-preset](https://github.com/americanexpress/amex-jest-preset/tree/v6.0.0)
- [amex-jest-preset-react](https://github.com/americanexpress/amex-jest-preset-react/tree/v6.0.0)[1]: https://kulshekhar.github.io/ts-jest/user/config/
[2]: https://www.npmjs.com/package/jest-date-mock