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

sealights-jest-plugin

v2.0.102

Published

Sealights Jest integration plugin

Downloads

344

Readme

sealights-jest-plugin

Sealights plugin for Jest testing framework.

Install

npm install sealights-jest-plugin

Usage

Before using it you should run config and build commands from slnodejs like you would normally.


In the jest.config.js file import configCreator and wrap jest config in it

const {configCreator} = require('sealights-jest-plugin')

module.exports = configCreator({
    //... jest configuration
});

Running tests

From the command line add sealights parameters with '--sl-' prefix

e.g:

jest __tests__ --sl-testStage='test stage name' --sl-tokenfile=sltoken.txt --sl-buildsessionidfile=buildSessionId

Supported parameters

  • sl-token - Sealights token
  • sl-tokenFile - Path to file contains the Sealights token
  • sl-buildSessionId - Sealights build session id
  • sl-buildSessionIdFile - Path to file contains the Sealights build session id
  • sl-testStage - Test stage current tests are relates to
  • sl-labId - Pre-defined Sealights lab-id (optional)
  • sl-proxy - Proxy server (optional)

Create-react-app project setup

In order to make sealights-jest-plugin work with create-react-app project you need to set it up correctly, so it produces high quality sourcemaps needed for sealights to work.

To set CRA project do the following:

  • Eject the project
  • Extract jest configuration from package.json into a separate jest config file called jest.config.js
  • Wrap the config in sealights:
const {configCreator} = require('sealights-jest-plugin')

module.exports = configCreator({
//... jest configuration
});

in config/webpack.config.js change

//...
devtool: false
//...
new TerserPlugin({
    //...
    keep_classnames: true,
    keep_fnames: true
    //...
})
//...
plugins: [
    new webpack.SourceMapDevToolPlugin({
        noSources: true,
        columns: true,
        sourceRoot: '.',
        filename: 'static/js/[name].[contenthash:8].chunk.js.map',
        moduleFilenameTemplate: '[resource-path]'
    }),
]

after project is setup add following params to the test script:

node scripts/test.js --sl-testStage='test stage name' --sl-tokenfile=sltoken.txt --sl-buildsessionidfile=buildSessionId

Note

If you notice that watch mode does not collect the coverage disable it:

node scripts/test.js --watchAll=false --sl-testStage='test stage name' --sl-tokenfile=sltoken.txt --sl-buildsessionidfile=buildSessionId

Typescipt usage

If your project uses typescript, only thing you need to do is add this to your tsconfig.json

{
  "compilerOptions": {
    //...
    "sourceMap": true,
    "sourceRoot": "."
  }
}

Older versions of jest

You can use sealights plugin with older versions of jest, but first you should install corresponding versions of dependency packages, which are official jest packages. For example to use jest v26 install the following.

npm i jest@26 jest-environment-node@26 jest-circus@26 

If you are using jsdom environment instead of node switch jest-environment-node with jest-environment-jsdom.

Note: Create-react-app uses jsdom

After all the dependencies are installed you can wrap jest config in sealights wrapper and pass the version as parameter

const {configCreator} = require('sealights-jest-plugin')

module.exports = configCreator({
    // jest config...
}, {version: 26});

Note: that you don't have to pass version number if you are using jest v27.

Note: if you are not sure which jest version you are using because you are using react-scripts, you can check it's version in package.json after ejecting the project.

Hooks dependency guard

In testing frameworks there are specific cases where the incorrectly set variables in hooks might NOT fail the tests when there is at least one passing test. When the sealights skips this test it will start failing, to avoid that there is a hook dependency guard that detects this case and injects a dummy test to avoid failure.

If it is not a desired behaviour you can disable it by passing the following parameter to sealights

const {configCreator} = require('sealights-jest-plugin')

module.exports = configCreator({
    // jest config...
}, {disableHookDependencyGuard: true});

Notes

Currently, the plugin does not support jest-workers, if you are using newer versions of jest that use multiple workers (v27, v26) plugin will configure jest to not use jest-workers.

Plugin depends on the usage of jest-circus test runner, which is the default one in the latest version of Jest. If you are using different type of test runner, the plugin won't be able to collect the test data and coverage.

Author

Sealights