cypress-plugin-snapshots
Plugin for snapshot tests in Cypress.io.
Installation
npm i cypress-plugin-snapshots -S
Usage
describe('data test', () => {
it('test data', () => {
return cy.request('data.json')
.its('body')
.toMatchSnapshot();
});
});
Config Cypress.io
Add this to your cypress.json
configuration file:
"ignoreTestFiles": [
"**/*.snap",
"**/__snapshot__/*"
]
Plugin
Find your cypress/plugins/index.js
file and change it to look like this:
const { initPlugin } = require('cypress-plugin-snapshots/plugin');
module.exports = (on, config) => {
initPlugin(on, config);
return config;
};
Command
Find your cypress/support/index.js
file and add the following line:
import 'cypress-plugin-snapshots/commands';
Make changes to default configuration
You can customize the configuration in the cypress.json
file in the root of your Cypress project.
Add the configuration below to your cypress.json
file to make changes to the default values.
"env": {
"cypress-plugin-snapshot": {
"autopassNewSnapshots": true,
"diffLines": 3,
"normalizeJson": true,
"serverEnabled": true,
"serverHost": "localhost",
"serverPort": 2121,
"updateSnapshots": false
}
}
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
License
This plugin is released under the MIT license.