jest-preset-ts
v1.0.1
Published
A Jest preset geared towards TypeScript, Angular, and Node.js projects
Downloads
12
Maintainers
Readme
A Jest preset geared towards TypeScript, Angular, and Node.js projects
Table of Contents
Overview
This is a Jest preset that is used in all of the Megabyte Labs projects that use Jest. Jest is a JavaScript/TypeScript testing framework maintained by Facebook. This particular Jest preset is built with support for TypeScript, Node.js, and Angular in mind. It includes several Jest plugins as well as improved HTML reports. Out of the box, it lints .spec.ts
files, runs the tests, and includes fancy reporting.
Requirements
If you are simply including this library in your project, all you need is a recent version of Node.js. Node.js >14.18.0 is sometimes required and is the only version range we actively support. Albeit, it is highly probable that lower versions will work as well depending on the requirements that this project imports.
Developer Requirements
The following versions of Node.js and Python are required for development:
Other versions may work, but only the above versions are supported. Most development dependencies are installed automatically by our Taskfile.yml
set-up (even Node.js and Python). Run bash start.sh
to install Bodega (an improved fork of go-task) and run the initialization sequence. The taskfiles will automatically install dependencies as they are needed, based on what development tasks you are running. For more information, check out the CONTRIBUTING.md or simply run:
npm run help
npm run help
will ensure Bodega is installed and then open an interactive dialog where you can explore and learn about various developer commands.
Installation
To use this Jest preset/configuration in your project, first install the NPM package in your NPM project with:
npm install --save-dev jest-preset-ts
Then, add the configuration to your package.json
file. Your package.json
might look something like:
{
"name": "mypackage",
"version": "1.0.4"
...
"jest": {
"preset": "@megabytelabs/jest-preset",
"reporters": [
"default",
[
"jest-html-reporters",
{
"filename": "index.html",
"openReport": true,
"pageTitle": "Code Coverage Report",
"publicPath": "./coverage"
}
]
]
}
}
There are of course other ways of including the Jest preset.
Usage
With the preset/configuration set up, you can now run jest
commands and Jest will automatically detect and use the configuration stored in your package.json
file. For instance, you can run Jest in watch mode with:
jest --watch
The Jest preset will scan your src/
directory for test files and show the results after every time you make a file change in --watch
mode.
Plugins
This Jest preset/configuration includes all the best Jest plugins that have a decent amount of stars on GitHub. The plugins are listed below for your convenience:
| Jest Plugin | Description |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| @jest-runner/electron
| custom test runner for Jest that allows tests to be run in Electron environment |
| @storybook/addon-storyshots
| StoryShots adds automatic Jest Snapshot Testing for Storybook |
| expect-puppeteer
| Run the tests using Jest & Puppeteer |
| jest-chain
| Chain Jest matchers together to create one powerful assertion |
| jest-dom
| Custom jest matchers to test the state of the DOM |
| jest-html-reporters
| Jest test results processor for generating a summary in HTML |
| jest-image-snapshot
| Jest matcher for image comparisons |
| jest-json-schema
| JSON schema matcher for Jest |
| jest-preset-angular
| A preset of Jest configuration for Angular projects |
| jest-puppeteer
| Jest preset containing all required configuration for writing integration tests using Puppeteer |
| jest-runner-eslint
| ESLint runner for Jest |
| jest-runner-groups
| A custom runner that allows to tag test files and run groups of tests with Jest |
| jest-runner-prettier
| Prettier runner for Jest |
| jest-runner-stylelint
| Stylelint runner for Jest |
| jest-runner-tsc
| A Jest runner for the TypeScript compiler |
| jest-watch-master
| Jest watch plugin for checking changes since master |
| jest-watch-select-projects
| Select which Jest projects to run |
| jest-watch-typeahead
| Jest watch plugin for filtering test by file name or test name |
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you would like to contribute, please take a look at the contributing guide.
Brian Zalewski
License
Copyright © 2020-2021 Megabyte LLC. This project is MIT licensed.