testplane-image-minifier
Overview
Use the testplane-image-minifier
plugin to compress images (screenshots) in your tests.
The plugin supports 8 compression levels: from 0 (do not apply compression) to 7 (maximum compression level).
Compression is lossless.
How does it work?
At startup, the plugin subscribes to the UPDATE_REFERENCE
event, which Testplane sends in the following cases:
- if the user started Testplane by passing the
--update-refs
option; - if the user updates or saves screenshots using the html-reporter plugin.
When the UPDATE_REFERENCE
event is received in the testplane-image-minifier
plugin, it gets a link to the image itself along with the event. Next, the plugin applies a compression algorithm to the received image with the compression level specified in the config. And saves the new image to the file system. After that, the developer can merge the updated files into the main branch of his project.
To compress images, the testplane-image-minifier
plugin uses the optipng-bin package.
When choosing the compression level for images in your project, remember that you are choosing between the speed and the space that your images will occupy on disk. The higher the compression ratio, the less space your images will occupy on disk, but the tests themselves will take longer. Since before comparing the images in the tests, the system will have to unpack them. Therefore, in order to get an acceptable test run time, match the selected compression ratio with the capacity of the servers on which these tests will be running.
Install
npm install -D testplane-image-minifier
Setup
Add the plugin to the plugins
section of the testplane
config:
module.exports = {
plugins: {
"testplane-image-minifier": {
enabled: true, // Enable the plugin.
compressionLevel: 7, // Maximum compression level, compression will take some time
},
// other Testplane plugins...
},
// other Testplane settings...
};
Description of configuration parameters
Parameter | Type | Default value | Description |
enabled | Boolean | true | Enable / disable the plugin. |
compressionLevel | Number | 2 | Image compression level: from 0 to 7 (maximum compression level). |
Passing parameters via the CLI
All plugin parameters that can be defined in the config can also be passed as command-line options or through environment variables during the launch of Testplane. Use the prefix --image-minifier-
for command line options and testplane_image_minifier_
for environment variables. For example:
npx testplane --image-minifier-compression-level 5
testplane_image_minifier_compression_level = 5 npx testplane
Debugging
Set the environment variable DEBUG=testplane:image-minifier
to see messages in the console about the application of the compression algorithm for images in tests.
DEBUG=testplane:image-minifier npx testplane --update-refs
An example of how it will look in the console:
/path/to/reference/image.png compressed by 30%
Usage
After adding the plugin to the project and configuring its parameters, run Testplane with the --update-refs
option:
npx testplane --update-refs
The images on the file system will be updated.