-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DB Seed to Cypress and setup Percy (#3155)
* Update Cypress element selectors * Add seed data function to Cypress * Change Cypress setup to be part of db-seed * Add DatabaseSource selector to Create Data Source spec * Add getElement command to Cypress * Fix eslint issues * Change Cypress getElement to getByTestId * Add Percy and test it with the CI * Change Percy dependency for CI to Cypress' Dockerfile * Change Percy's execution to the docker container - add --no-save to avoid errors on Dockerfile.cypress - pass PERCY_TOKEN from the CI to docker container * Fix missed char on CircleCI config file * Move Percy execution back to host on the CI * Test adding PERCY_TOKEN to frontend-e2e-tests on CI config * Undo add PERCY_TOKEN to config.yml * Add Percy token and .git folder to Cypress * Remove Percy install from config.yml * Ignore .git folder again and use Percy env vars instead * Update PERCY_PULL_REQUEST to be CIRCLE_PR_NUMBER * Update cypress-server.js to handle other cypress commands - cypress-server.js -> cypress.js - new commands added to cypress.js - CircleCI config updated accordingly - added a Homepage screenshot * Remove trailing spaces * Add Create Query spec * Disable Cypress videos * Update run browser to Chrome * Add missing --browser chrome
- Loading branch information
1 parent
38ed046
commit cfe12c5
Showing
20 changed files
with
186 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
FROM cypress/browsers:chrome67 | ||
|
||
WORKDIR /usr/src/app | ||
ENV APP /usr/src/app | ||
WORKDIR $APP | ||
|
||
RUN npm install cypress > /dev/null | ||
RUN npm install --no-save cypress @percy/cypress > /dev/null | ||
|
||
COPY cypress /usr/src/app/cypress | ||
COPY cypress.json /usr/src/app/cypress.json | ||
COPY cypress $APP/cypress | ||
COPY cypress.json $APP/cypress.json | ||
|
||
RUN ./node_modules/.bin/cypress verify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"baseUrl": "http://localhost:5000" | ||
"baseUrl": "http://localhost:5000", | ||
"video": false | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, no-console */ | ||
const atob = require('atob'); | ||
const { execSync } = require('child_process'); | ||
const { post } = require('request').defaults({ jar: true }); | ||
const { seedData } = require('./seed-data'); | ||
|
||
const baseUrl = process.env.CYPRESS_baseUrl || 'http://localhost:5000'; | ||
|
||
function seedDatabase(seedValues) { | ||
const request = seedValues.shift(); | ||
const data = request.type === 'form' ? { formData: request.data } : { json: request.data }; | ||
|
||
post(baseUrl + request.route, data, (err, response) => { | ||
const result = response ? response.statusCode : err; | ||
console.log('POST ' + request.route + ' - ' + result); | ||
if (seedValues.length) { | ||
seedDatabase(seedValues); | ||
} | ||
}); | ||
} | ||
|
||
function startServer() { | ||
console.log('Starting the server...'); | ||
|
||
execSync('docker-compose -p cypress build --build-arg skip_ds_deps=true', { stdio: 'inherit' }); | ||
execSync('docker-compose -p cypress up -d', { stdio: 'inherit' }); | ||
execSync('docker-compose -p cypress run server create_db', { stdio: 'inherit' }); | ||
} | ||
|
||
function stopServer() { | ||
console.log('Stopping the server...'); | ||
execSync('docker-compose -p cypress down', { stdio: 'inherit' }); | ||
} | ||
|
||
function runCypressCI() { | ||
if (process.env.PERCY_TOKEN_ENCODED) { | ||
process.env.PERCY_TOKEN = atob(`${process.env.PERCY_TOKEN_ENCODED}`); | ||
} | ||
execSync('docker-compose run cypress ./node_modules/.bin/percy exec -- ./node_modules/.bin/cypress run --browser chrome', { stdio: 'inherit' }); | ||
} | ||
|
||
const command = process.argv[2] || 'all'; | ||
|
||
switch (command) { | ||
case 'start': | ||
startServer(); | ||
break; | ||
case 'db-seed': | ||
seedDatabase(seedData); | ||
break; | ||
case 'run': | ||
execSync('cypress run --browser chrome', { stdio: 'inherit' }); | ||
break; | ||
case 'open': | ||
execSync('cypress open', { stdio: 'inherit' }); | ||
break; | ||
case 'run-ci': | ||
runCypressCI(); | ||
break; | ||
case 'stop': | ||
stopServer(); | ||
break; | ||
case 'all': | ||
startServer(); | ||
seedDatabase(seedData); | ||
execSync('cypress run --browser chrome', { stdio: 'inherit' }); | ||
stopServer(); | ||
break; | ||
default: | ||
console.log('Usage: npm run cypress [start|db-seed|open|run|stop]'); | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('Create Query', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
cy.visit('/queries/new'); | ||
}); | ||
|
||
it('executes the query', () => { | ||
cy.getByTestId('SelectDataSource') | ||
.click() | ||
.contains('Test PostgreSQL').click(); | ||
|
||
cy.getByTestId('QueryEditor') | ||
.get('.ace_text-input') | ||
.type('SELECT id, name FROM organizations{esc}', { force: true }); | ||
|
||
cy.getByTestId('ExecuteButton').click(); | ||
|
||
cy.getByTestId('DynamicTable').should('exist'); | ||
cy.percySnapshot('Edit Query page'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.