Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
build: enable typescript for cypress
Browse files Browse the repository at this point in the history
Follow up apache#10161 :

- Enable TypeScript for Cypress
- Convert support files to TS
- Convert an example test (dashboard/filter.test.js) to TS
- Upgrade TypeScript for both `cypress-base` and `superset-frontend`
- Reenable Prefer TS check for `cypress-base`
  • Loading branch information
ktmud committed Jun 29, 2020
1 parent 539e11b commit 5276b49
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 153 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/prefer_typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
js_files_added() {
jq -r '
map(
select(
(contains("cypress-base/") | not) and
(endswith(".js") or endswith(".jsx"))
)
select((endswith(".js") or endswith(".jsx"))
) | join("\n")
' ${HOME}/files_added.json
}
Expand Down
24 changes: 24 additions & 0 deletions superset-frontend/cypress-base/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["cypress", "@typescript-eslint"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:cypress/recommended"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/camelcase": 0
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"env": {
"cypress/globals": true
}
}
3 changes: 2 additions & 1 deletion superset-frontend/cypress-base/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"baseUrl": "http://localhost:8081",
"chromeWebSecurity": false,
"defaultCommandTimeout": 5000,
"experimentalFetchPolyfill": true,
"requestTimeout": 10000,
"ignoreTestFiles": [
"**/!(*.test.js)"
"**/!(*.test.js|*.test.ts)"
],
"video": false,
"videoUploadOnPasses": false,
Expand Down
8 changes: 0 additions & 8 deletions superset-frontend/cypress-base/cypress/.eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

interface Slice {
slice_id: number;
form_data: {
viz_type: string;
[key: string]: JSONValue;
};
}

interface DashboardData {
slices: Slice[];
}

describe('Dashboard filter', () => {
let filterId;
let aliases;
let filterId: number;
let aliases: string[];

const getAlias = id => {
const getAlias = (id: number) => {
return `@slice_${id}`;
};

Expand All @@ -32,13 +44,14 @@ describe('Dashboard filter', () => {

cy.visit(WORLD_HEALTH_DASHBOARD);

cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
cy.get('#app').then(app => {
const bootstrapData = app.data('bootstrap');
const dashboard = bootstrapData.dashboard_data as DashboardData;
const sliceIds = dashboard.slices.map(slice => slice.slice_id);
filterId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'filter_box',
).slice_id;
filterId =
dashboard.slices.find(
slice => slice.form_data.viz_type === 'filter_box',
)?.slice_id || 0;
aliases = sliceIds.map(id => {
const alias = getAlias(id);
const url = `/superset/explore_json/?*{"slice_id":${id}}*`;
Expand Down Expand Up @@ -72,7 +85,7 @@ describe('Dashboard filter', () => {

cy.get('.Select__control input[type=text]')
.first()
.focus({ force: true })
.focus()
.type('So', { force: true });

cy.get('.Select__menu').first().contains('Create "So"');
Expand All @@ -81,7 +94,7 @@ describe('Dashboard filter', () => {
// we refocus the input again here. The is not happening in real life.
cy.get('.Select__control input[type=text]')
.first()
.focus({ force: true })
.focus()
.type('uth Asia{enter}', { force: true });

// by default, need to click Apply button to apply filter
Expand All @@ -90,8 +103,10 @@ describe('Dashboard filter', () => {
// wait again after applied filters
cy.wait(aliases.filter(x => x !== getAlias(filterId))).then(requests => {
requests.forEach(xhr => {
const requestFormData = xhr.request.body;
const requestParams = JSON.parse(requestFormData.get('form_data'));
const requestFormData = xhr.request.body as FormData;
const requestParams = JSON.parse(
requestFormData.get('form_data') as string,
);
expect(requestParams.extra_filters[0]).deep.eq({
col: 'region',
op: 'in',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

describe('Dashboard save action', () => {
let dashboardId;
let boxplotChartId;

beforeEach(() => {
cy.server();
Expand All @@ -32,10 +31,6 @@ describe('Dashboard save action', () => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
dashboardId = dashboard.id;
boxplotChartId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'box_plot',
).slice_id;

cy.route('POST', `/superset/copy_dash/${dashboardId}/`).as('copyRequest');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ describe('Test explore links', () => {
// explicitly wait for the url response
cy.wait('@getShortUrl');

cy.wait(100);

cy.get('#shorturl-popover [data-test="short-url"]')
.invoke('text')
.then(text => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@ describe('SqlLab query tabs', () => {
});

it('allows you to create a tab', () => {
cy.get('#a11y-query-editor-tabs > ul > li').then(tabList => {
cy.get('.SqlEditorTabs > ul > li').then(tabList => {
const initialTabCount = tabList.length;

// add tab
cy.get('#a11y-query-editor-tabs > ul > li').last().click();

cy.get('#a11y-query-editor-tabs > ul > li').should(
'have.length',
initialTabCount + 1,
cy.get('.SqlEditorTabs > ul > li').last().click();
// wait until we find the new tab
cy.get(`.SqlEditorTabs > ul > li:eq(${initialTabCount - 1})`).contains(
'Untitled Query',
);
});
});

it('allows you to close a tab', () => {
cy.get('#a11y-query-editor-tabs > ul > li').then(tabListA => {
cy.get('.SqlEditorTabs > ul > li').then(tabListA => {
const initialTabCount = tabListA.length;

// open the tab dropdown to remove
cy.get('#a11y-query-editor-tabs > ul > li .dropdown-toggle').click();
cy.get('.SqlEditorTabs > ul > li .dropdown-toggle').click();

// first item is close
cy.get('#a11y-query-editor-tabs .close-btn a').click();
cy.get('.SqlEditorTabs .close-btn a').click();

cy.get('#a11y-query-editor-tabs > ul > li').should(
cy.get('.SqlEditorTabs > ul > li').should(
'have.length',
initialTabCount - 1,
);
Expand Down
10 changes: 0 additions & 10 deletions superset-frontend/cypress-base/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

Expand Down
61 changes: 61 additions & 0 deletions superset-frontend/cypress-base/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// eslint-disable-next-line spaced-comment
/// <reference types="cypress" />
type JSONPrimitive = string | number | boolean | null;
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
type JSONObject = { [member: string]: JSONValue };
type JSONArray = JSONValue[];

declare namespace Cypress {
interface Chainable {
/**
* Login test user.
*/
login(): void;

/**
* Verify a waitXHR response and parse response JSON.
*/
verifyResponseCodes(
xhr: WaitXHR,
callback?: (result: JSONValue) => void,
): cy;

/**
* Verify slice container renders.
*/
verifySliceContainer(chartSelector: JQuery.Selector): cy;

/**
* Verify slice successfully loaded.
*/
verifySliceSuccess({
waitAlias,
querySubString,
chartSelector,
}: {
waitAlias: string;
querySubString: string;
chartSelector: JQuery.Selector;
}): cy;
}
}

declare module '@cypress/code-coverage/task';
42 changes: 0 additions & 42 deletions superset-frontend/cypress-base/cypress/support/index.js

This file was deleted.

Loading

0 comments on commit 5276b49

Please sign in to comment.