Jest framework
If you’re using the Jest testing framework, Sealights-jest-plugin can be directly integrated into your project.
Sealights-jest-plugin is a standalone plugin for use with slnodejs; it’s not meant to replace it.
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 tokensl-tokenFile
- Path to file contains the Sealights tokensl-buildSessionId
- Sealights build session idsl-buildSessionIdFile
- Path to file contains the Sealights build session idsl-testStage
- Test stage current tests are relates tosl-labId
- Pre-defined Sealights lab-id (optional)sl-proxy
- Proxy server (optional)
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:
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
If you notice that watch mode does not collect the coverage disable it with a dedicated flag --watchAll=false
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 the sealights plugin with older versions of Jest, but first, you should install the 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.
Last updated
Was this helpful?