npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-os-detection

v1.3.1

Published

Allow to specify on which platform to run jest tests

Downloads

3,533

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

# 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"
  ]
}