Running tests using Jest framework
If you’re using the Jest testing framework, Sealights-jest-plugin can be directly integrated into your project.
See https://www.npmjs.com/package/sealights-jest-plugin for details.
Sealights-jest-plugin is a standalone plugin for use with slnodejs, it’s not meant to replace it.
Jest framework is used for unit tests
Instructions
Running tests:
Install
npm install sealights-jest-plugin
In the jest.config.js import configCreator and wrap jest config object in it:
const {configCreator} = require('sealights-jest-plugin') module.exports = configCreator({ //... jest configuration });
From the command line run jest and add sealights parameters with --sl- prefix
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)
In order for sealights-jest-plugin to work you need a token, seeGenerating an Agent token and scan a build Using Node.js Agents - Scanning a build
Create-react-app 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 calledjest.config.js
Wrap the config in sealights:
in config/webpack.config.js
change
after project is setup add following params to the test script:
Note
If you notice that watch mode does not collect the coverage disable it:
Typescipt usage
If your project uses typescript, only thing you need to do is add this to your tsconfig.json
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.
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
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
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.
Related articles
Filter by label
There are no items with the selected labels at this time.