diff --git a/core/.eslintrc.js b/core/.eslintrc.js index 44443d098f..7b2a4188ed 100644 --- a/core/.eslintrc.js +++ b/core/.eslintrc.js @@ -46,7 +46,8 @@ module.exports = { { "files": ["*.e2e.ts"], "rules": { - "custom-rules/await-playwright-promise-assertion": "error" + "custom-rules/await-playwright-promise-assertion": "error", + "custom-rules/no-playwright-to-match-snapshot-assertion": "error" } } ] diff --git a/core/custom-rules/index.js b/core/custom-rules/index.js index 56bddacafa..a66ad5bba0 100644 --- a/core/custom-rules/index.js +++ b/core/custom-rules/index.js @@ -1,6 +1,7 @@ module.exports = { rules: { 'no-component-on-ready-method': require('./no-component-on-ready-method.js'), - 'await-playwright-promise-assertion': require('./await-playwright-promise-assertion.js') + 'await-playwright-promise-assertion': require('./await-playwright-promise-assertion.js'), + 'no-playwright-to-match-snapshot-assertion': require('./no-playwright-to-match-snapshot-assertion.js') } } diff --git a/core/custom-rules/no-playwright-to-match-snapshot-assertion.js b/core/custom-rules/no-playwright-to-match-snapshot-assertion.js new file mode 100644 index 0000000000..e05134359b --- /dev/null +++ b/core/custom-rules/no-playwright-to-match-snapshot-assertion.js @@ -0,0 +1,29 @@ +module.exports = { + meta: { + messages: { + noPlaywrightToMatchSnapshotAssertion: '"toHaveScreenshot" assertions should be used in favor of "toMatchSnapshot". "toHaveScreenshot" brings file size reductions and anti-flake behaviors such as disabling animations by default.', + }, + }, + create(context) { + return { + ExpressionStatement(node) { + if (node.expression.callee === undefined) { + return; + } + + const { property } = node.expression.callee; + + /** + * Check to see if toMatchSnapshot is being used + */ + if ( + property !== undefined && + property.type === 'Identifier' && + property.name === 'toMatchSnapshot' + ) { + context.report({ node: node, messageId: 'noPlaywrightToMatchSnapshotAssertion' }); + } + } + } + } +}; diff --git a/core/playwright.config.ts b/core/playwright.config.ts index 1fa886c512..9cfb9fb810 100644 --- a/core/playwright.config.ts +++ b/core/playwright.config.ts @@ -55,9 +55,6 @@ const config: PlaywrightTestConfig = { timeout: 5000, toHaveScreenshot: { threshold: 0.1 - }, - toMatchSnapshot: { - threshold: 0.1 } }, /* Fail the build on CI if you accidentally left test.only in the source code. */