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

create-jest-runner-with-skip

v0.1.1

Published

A simple way of creating a Jest runner

Downloads

9

Readme

create-jest-runner

A highly opinionated way for creating Jest Runners

Install

yarn add create-jest-runner

Usage

create-jest-runner takes care of handling the appropriate parallelization and creating a worker farm for your runner.

You simply need two files:

  • Entry file: Used by Jest as an entrypoint to your runner.
  • Run file: Runs once per test file, and it encapsulates the logic of your runner

1) Create your entry file

// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));

2) Create your run file

module.exports = (options) => {
};

Run File API

This file should export a function that receives one parameter with the options

options: { testPath, config, globalConfig }

  • testPath: Path of the file that is going to be tests
  • config: Jest Project config used by this file
  • globalConfig: Jest global config

You can return one of the following values:

  • testResult: Needs to be an object of type https://github.com/facebook/jest/blob/master/types/TestResult.js#L131-L157
  • Promise<testResult|Error>: needs to be of above type.
  • Error: good for reporting system error, not failed tests.

Example of a runner

This runner "blade-runner" makes sure that these two emojis ⚔️ 🏃 are present in every file

// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));
// run.js
const fs = require('fs');
const { pass, fail } = require('create-jest-runner');

module.exports = ({ testPath }) => {
  const start = +new Date();
  const contents = fs.readFileSync(testPath, 'utf8');
  const end = +new Date();

  if (contents.includes('⚔️🏃')) {
    return pass({ start, end, test: { path: testPath } });
  }
  const errorMessage = 'Company policies require ⚔️ 🏃 in every file';
  return fail({
    start,
    end,
    test: { path: testPath, errorMessage, title: 'Check for ⚔️ 🏃' },
  });
};

Add your runner to Jest config

Once you have your Jest runner you can add it to your Jest config.

In your package.json

{
  "jest": {
    "runner": "/path/to/my-runner"
  }
}

Or in jest.config.js

module.exports = {
  runner: '/path/to/my-runner',
}

Run Jest

yarn jest