From df7647b26852640a6c99e958cd8e321afcf6132e Mon Sep 17 00:00:00 2001 From: Steven Vachon Date: Mon, 1 Jun 2020 13:55:37 -0400 Subject: [PATCH] @grafana/e2e: improvements and dumb fixes for #25203 (#25269) * Fix type definitions * Fix typo * Added support for fetch() within tests --- packages/grafana-e2e/cypress/plugins/compareScreenshots.js | 4 ++-- packages/grafana-e2e/cypress/support/commands.ts | 6 +++--- packages/grafana-e2e/cypress/support/index.d.ts | 2 +- packages/grafana-e2e/cypress/support/index.ts | 6 ++++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/grafana-e2e/cypress/plugins/compareScreenshots.js b/packages/grafana-e2e/cypress/plugins/compareScreenshots.js index 3ca9bf397cb..426d12adac5 100644 --- a/packages/grafana-e2e/cypress/plugins/compareScreenshots.js +++ b/packages/grafana-e2e/cypress/plugins/compareScreenshots.js @@ -3,7 +3,7 @@ const BlinkDiff = require('blink-diff'); const { resolve } = require('path'); // @todo use npmjs.com/pixelmatch or an available cypress plugin -const compareSceenshots = async ({ config, screenshotsFolder, specName }) => { +const compareScreenshots = async ({ config, screenshotsFolder, specName }) => { const name = config.name || config; // @todo use `??` const threshold = config.threshold || 0.001; // @todo use `??` @@ -46,4 +46,4 @@ const compareSceenshots = async ({ config, screenshotsFolder, specName }) => { } }; -module.exports = compareSceenshots; +module.exports = compareScreenshots; diff --git a/packages/grafana-e2e/cypress/support/commands.ts b/packages/grafana-e2e/cypress/support/commands.ts index d281d26229f..9c91b079f32 100644 --- a/packages/grafana-e2e/cypress/support/commands.ts +++ b/packages/grafana-e2e/cypress/support/commands.ts @@ -1,10 +1,10 @@ -interface CompareSceenshotsConfig { +interface CompareScreenshotsConfig { name: string; threshold?: number; } -Cypress.Commands.add('compareSceenshots', (config: CompareSceenshotsConfig | string) => { - cy.task('compareSceenshots', { +Cypress.Commands.add('compareScreenshots', (config: CompareScreenshotsConfig | string) => { + cy.task('compareScreenshots', { config, screenshotsFolder: Cypress.config('screenshotsFolder'), specName: Cypress.spec.name, diff --git a/packages/grafana-e2e/cypress/support/index.d.ts b/packages/grafana-e2e/cypress/support/index.d.ts index 9f3ed2fb449..3a559aa5430 100644 --- a/packages/grafana-e2e/cypress/support/index.d.ts +++ b/packages/grafana-e2e/cypress/support/index.d.ts @@ -2,7 +2,7 @@ declare namespace Cypress { interface Chainable { - compareSnapshot(args: CompareSnapshotArgs): void; + compareScreenshots(config: CompareScreenshotsConfig | string): Chainable; logToConsole(message: string, optional?: any): void; readProvisions(filePaths: string[]): Chainable; } diff --git a/packages/grafana-e2e/cypress/support/index.ts b/packages/grafana-e2e/cypress/support/index.ts index 0ef7bbe7a29..aab52a33f06 100644 --- a/packages/grafana-e2e/cypress/support/index.ts +++ b/packages/grafana-e2e/cypress/support/index.ts @@ -24,6 +24,12 @@ if (Cypress.env('SLOWMO')) { } } +// @todo remove when possible: https://github.com/cypress-io/cypress/issues/95 +Cypress.on('window:before:load', win => { + // @ts-ignore + delete win.fetch; +}); + // uncomment below to prevent Cypress from failing tests when unhandled errors are thrown // Cypress.on('uncaught:exception', (err, runnable) => { // // returning false here prevents Cypress from