Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doctolib/jest-os-detection
Allow to specify on which platform to run jest tests
https://github.com/doctolib/jest-os-detection
jest jest-os-detection linux macos windows
Last synced: 6 days ago
JSON representation
Allow to specify on which platform to run jest tests
- Host: GitHub
- URL: https://github.com/doctolib/jest-os-detection
- Owner: doctolib
- License: mit
- Created: 2019-11-27T17:52:03.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-05T01:33:09.000Z (about 1 year ago)
- Last Synced: 2024-10-04T00:47:43.312Z (about 1 month ago)
- Topics: jest, jest-os-detection, linux, macos, windows
- Language: TypeScript
- Homepage:
- Size: 1.45 MB
- Stars: 14
- Watchers: 3
- Forks: 3
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-jest - jest-os-detection
README
# Jest OS detection
This module allows you to specify on which OS your tests should run.
A common use case would be to have a CI running on different OS
(say mac and windows) but you want to have all your tests in the same file.
Unfortunately, some of your tests should only run on a specific platform
due to OS specific features.All tests that should not be run on the current
platform will be automatically skipped.## Install
```bash
# with npm
npm install jest-os-detection# with yarn
yarn add jest-os-detection
```## Setup
In your package.json
```json
"jest": {
"setupFilesAfterEnv": ["jest-os-detection"],
}
```## Usage
```js
describe.onWindows('this describe is only interpreted on Windows', () => {
it.onMac('this test is only interpreted on Mac', () => {})
test.onLinux('this test is only interpreted on Linux', () => {})
it.onMac.skip('this test is only interpreted on Mac but skipped', () => {})
test.onLinux.skip('this test is only interpreted on Linux but skipped', () => {})
it.onMac.only('only this test is executed on Mac', () => {})
test.onLinux.only('only this test is executed on Linux', () => {})
})describe.onWindows.each([1, 2, 3])('several describe on windows', describeValue => {
it.onMac.each([1, 2, 3, 4])('several tests on windows', testValue => {})
test.onLinux.each([1, 2, 3, 4])('several tests on windows', testValue => {})
it.onMac.each.skip([1, 2, 3, 4])('several tests skipped on windows', testValue => {})
test.onLinux.each.skip([1, 2, 3, 4])('several tests skipped on windows', testValue => {})
it.onMac.each.only([1, 2, 3, 4])('only these tests will be executed on windows', testValue => {})
test.onLinux.each.only([1, 2, 3, 4])('only these tests will be executed on windows', testValue => {})
})
```## Supported features
Supported commands:
* `describe()`
* `it()`
* `test()`Supported platform:
* `.onWindows()`
* `.onMac()`
* `.onLinux()`
* `.skipWindows()`
* `.skipMac()`
* `.skipLinux()`Supported sub-commands:
* `..each()`
* `..only()`
* `..skip()`
* `..skip.each()`
* `..only.each()`## TypeScript
To avoid type errors globally, you can add this to your tsconfig:
```json
{
"files": [
"node_modules/jest-os-detection/index.d.ts"
]
}
```