2.0.60 • Published 3 months ago

sealights-jest-plugin v2.0.60

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

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

2.0.60

3 months ago

2.0.44

3 months ago

2.0.19

7 months ago

2.0.23

6 months ago

2.0.16

8 months ago

2.0.13

10 months ago

2.0.5

12 months ago

2.0.12

10 months ago

2.0.10

10 months ago

2.0.8

10 months ago

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago