Giter Site home page Giter Site logo

jest-os-detection's Introduction

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

# with npm
npm install jest-os-detection

# with yarn
yarn add jest-os-detection

Setup

In your package.json

"jest": {
    "setupFilesAfterEnv": ["jest-os-detection"],
  }

Usage

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:

  • <command>.onWindows()
  • <command>.onMac()
  • <command>.onLinux()
  • <command>.skipWindows()
  • <command>.skipMac()
  • <command>.skipLinux()

Supported sub-commands:

  • <command>.<platform>.each()
  • <command>.<platform>.only()
  • <command>.<platform>.skip()
  • <command>.<platform>.skip.each()
  • <command>.<platform>.only.each()

TypeScript

To avoid type errors globally, you can add this to your tsconfig:

{
  "files": [
    "node_modules/jest-os-detection/index.d.ts"
  ]
}

jest-os-detection's People

Contributors

corresponsible avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.