Skip to content

Commit

Permalink
test(cypress): Fail Cypress on Console errors (#24872)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusackas authored Aug 24, 2023
1 parent 60c2ac3 commit 63f24ea
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ describe('Dashboard edit', () => {
it('should not accept an invalid color scheme', () => {
openAdvancedProperties();
clearMetadata();
// allow console error
cy.allowConsoleErrors(['Error: A valid color scheme is required']);
writeMetadata('{"color_scheme":"wrongcolorscheme"}');
applyChanges();
cy.get('.ant-modal-body')
Expand Down
22 changes: 22 additions & 0 deletions superset-frontend/cypress-base/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,31 @@
*/
import '@cypress/code-coverage/support';
import '@applitools/eyes-cypress/commands';
import failOnConsoleError, { Config } from 'cypress-fail-on-console-error';

require('cy-verify-downloads').addCustomCommand();

// fail on console error, allow config to override individual tests
// these exceptions are a little pile of tech debt
const { getConfig, setConfig } = failOnConsoleError({
consoleMessages: [
/\[webpack-dev-server\]/,
'The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".',
'The pseudo class ":nth-child" is potentially unsafe when doing server-side rendering. Try changing it to ":nth-of-type".',
'Error: Unknown Error',
/Unable to infer path to ace from script src/,
],
});

// Set infividual tests to allow certain console erros to NOT fail, e.g
// cy.allowConsoleErrors(['foo', /^some bar-regex.*/]);
// This will be reset between tests.
Cypress.Commands.addAll({
getConsoleMessages: () => cy.wrap(getConfig()?.consoleMessages),
allowConsoleErrors: (consoleMessages: (string | RegExp)[]) =>
setConfig({ ...getConfig(), consoleMessages }),
});

const BASE_EXPLORE_URL = '/explore/?form_data=';
let DASHBOARD_FIXTURES: Record<string, any>[] = [];
let CHART_FIXTURES: Record<string, any>[] = [];
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/cypress-base/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare namespace Cypress {
cleanDashboards(): cy;
loadChartFixtures(): cy;
loadDashboardFixtures(): cy;
allowConsoleErrors(consoleMessages: (string | RegExp)[]): cy;

visitChartByParams(params: string | Record<string, unknown>): cy;
visitChartByName(name: string): cy;
Expand Down
Loading

0 comments on commit 63f24ea

Please sign in to comment.