ci(cypress): adding the foundation for cypress integration tests & some starter coverage for login, search & updates (#3672)

This commit is contained in:
Gabe Lyons 2021-12-13 23:08:30 -08:00 committed by GitHub
parent a4ac79db48
commit e9c87bc0df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 2898 additions and 0 deletions

5
.gitignore vendored
View File

@ -46,5 +46,10 @@ MANIFEST
**/spark-lineage/**/out.csv/
.vscode
# cypress integration test generated files
**/cypress/videos
**/cypress/screenshots
**/cypress/node_modules
# Metadata Ingestion Generated
metadata-ingestion/generated/**

View File

@ -23,4 +23,6 @@ datahub docker quickstart \
--quickstart-compose-file ../docker/docker-compose.dev.yml \
--dump-logs-on-failure
(cd tests/cypress ; yarn install)
pytest -vv --continue-on-collection-errors --junit-xml=junit.smoke.xml

View File

View File

@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:9002"
}

View File

@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@ -0,0 +1,9 @@
describe('login', () => {
it('logs in', () => {
cy.visit('/');
cy.get('input[placeholder=Username]').type('datahub');
cy.get('input[placeholder=Password]').type('datahub');
cy.contains('Log in').click();
cy.contains('Welcome back, datahub');
});
})

View File

@ -0,0 +1,40 @@
describe('mutations', () => {
it('can create and add a tag to dataset and visit new tag page', () => {
cy.deleteUrn('urn:li:tag:CypressTestAddTag')
cy.login();
cy.visit('/dataset/urn:li:dataset:(urn:li:dataPlatform:hive,cypress_logging_events,PROD)');
cy.contains('cypress_logging_events');
cy.contains('Add Tag').click();
cy.focused().type('CypressTestAddTag');
cy.contains('Create CypressTestAddTag').click();
cy.get('textarea').type('CypressTestAddTag Test Description');
cy.contains(/Create$/).click();
// go to tag page
cy.get('a[href="/tag/urn:li:tag:CypressTestAddTag"]').click();
// title of tag page
cy.contains('CypressTestAddTag');
// description of tag page
cy.contains('CypressTestAddTag Test Description');
// used by panel - click to search
cy.contains('1 Datasets').click();
// verify dataset shows up in search now
cy.contains('of 1 result').click();
cy.contains('cypress_logging_events').click();
cy.get('a[href="/tag/urn:li:tag:CypressTestAddTag"]').within(() => cy.get('span[aria-label=close]').click());
cy.contains('Yes').click();
cy.get('a[href="/tag/urn:li:tag:CypressTestAddTag"]').should('not.exist');
cy.deleteUrn('urn:li:tag:CypressTestAddTag')
});
})

View File

@ -0,0 +1,44 @@
describe('search', () => {
it('can hit all entities search, see some results (testing this any more is tricky because it is cached for now)', () => {
cy.login();
cy.visit('/');
cy.get('input[data-testid=search-input]').type('*{enter}');
cy.contains('of 0 results').should('not.exist');
cy.contains(/of [0-9]+ results/);
});
it('can hit all entities search with an impossible query and find 0 results', () => {
cy.login();
cy.visit('/');
// random string that is unlikely to accidentally have a match
cy.get('input[data-testid=search-input]').type('zzzzzzzzzzzzzqqqqqqqqqqqqqzzzzzzqzqzqzqzq{enter}');
cy.contains('of 0 results');
});
it('can search, find a result, and visit the dataset page', () => {
cy.login();
cy.visit('http://localhost:9002/search?filter_entity=DATASET&filter_tags=urn%3Ali%3Atag%3ACypress&page=1&query=users_created')
cy.contains('of 1 result');
cy.contains('Cypress')
cy.contains('fct_cypress_users_created').click();
// platform
cy.contains('Hive');
// entity type
cy.contains('Dataset');
// entity name
cy.contains('fct_cypress_users_created');
// column name
cy.contains('user_id');
// column description
cy.contains('Id of the user');
// table description
cy.contains('table containing all the users created on a single day');
});
})

View File

@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// 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)
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

View File

@ -0,0 +1,39 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
Cypress.Commands.add('login', () => {
cy.request('POST', '/logIn', {
username: 'datahub',
password: 'datahub',
})
})
Cypress.Commands.add('deleteUrn', (urn) => {
cy.request({ method: 'POST', url: 'http://localhost:8080/entities?action=delete', body: {
urn
}, headers: {
"X-RestLi-Protocol-Version": "2.0.0",
"Content-Type": "application/json",
}})
})
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

View File

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
import pytest
import subprocess
from tests.utils import ingest_file_via_rest
from tests.utils import delete_urns_from_file
@pytest.fixture(scope="module", autouse=True)
def ingest_cleanup_data():
print("ingesting test data")
ingest_file_via_rest("tests/cypress/data.json")
yield
print("removing test data")
delete_urns_from_file("tests/cypress/data.json")
def test_run_cypress(frontend_session, wait_for_healthchecks):
command = f"npx cypress run"
print('starting?')
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd="tests/cypress")
stdout = proc.stdout.read()
stderr = proc.stderr.read()
return_code = proc.wait()
print(stdout.decode("utf-8"))
print('stderr output:')
print(stderr.decode("utf-8"))
print('return code', return_code)
assert(return_code == 0)

View File

@ -0,0 +1,9 @@
{
"name": "smoke-test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"cypress": "^9.1.0"
}
}

File diff suppressed because it is too large Load Diff