From 917dfa76bde4dfe25e28c4c6341d32790121f998 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 16:25:09 +0200 Subject: [PATCH 1/6] Preset the admin API key to a static value --- cypress/cypress.js | 67 ++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/cypress/cypress.js b/cypress/cypress.js index 3363b437e1..4d1ea471ad 100644 --- a/cypress/cypress.js +++ b/cypress/cypress.js @@ -1,72 +1,87 @@ /* 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 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'; +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 }; + 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); + console.log("POST " + request.route + " - " + result); if (seedValues.length) { seedDatabase(seedValues); } }); + + // Make sure the admin user has the same API key on every execution + execSync( + "docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\"" + ); } function startServer() { - console.log('Starting the server...'); + 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' }); + 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' }); + 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' }); + 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'; +const command = process.argv[2] || "all"; switch (command) { - case 'start': + case "start": startServer(); break; - case 'db-seed': + case "db-seed": seedDatabase(seedData); break; - case 'run': - execSync('cypress run --browser chrome', { stdio: 'inherit' }); + case "run": + execSync("cypress run --browser chrome", { stdio: "inherit" }); break; - case 'open': - execSync('cypress open', { stdio: 'inherit' }); + case "open": + execSync("cypress open", { stdio: "inherit" }); break; - case 'run-ci': + case "run-ci": runCypressCI(); break; - case 'stop': + case "stop": stopServer(); break; - case 'all': + case "all": startServer(); seedDatabase(seedData); - execSync('cypress run --browser chrome', { stdio: 'inherit' }); + execSync("cypress run --browser chrome", { stdio: "inherit" }); stopServer(); break; default: - console.log('Usage: npm run cypress [start|db-seed|open|run|stop]'); + console.log("Usage: npm run cypress [start|db-seed|open|run|stop]"); break; } From 126bd1d261d87d1acccea39f69d9390f0caace58 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 16:42:54 +0200 Subject: [PATCH 2/6] Use correct Prettier/eslint settings --- cypress/cypress.js | 65 +++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/cypress/cypress.js b/cypress/cypress.js index 4d1ea471ad..38d5bb642e 100644 --- a/cypress/cypress.js +++ b/cypress/cypress.js @@ -1,47 +1,42 @@ /* 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 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"; +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 }; + 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); + console.log('POST ' + request.route + ' - ' + result); if (seedValues.length) { seedDatabase(seedValues); } }); // Make sure the admin user has the same API key on every execution - execSync( - "docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\"" - ); + execSync("docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\""); } function startServer() { - console.log("Starting the server..."); + console.log('Starting the server...'); - execSync("docker-compose -p cypress build --build-arg skip_ds_deps=true", { - stdio: "inherit" + 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" + 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" }); + console.log('Stopping the server...'); + execSync('docker-compose -p cypress down', { stdio: 'inherit' }); } function runCypressCI() { @@ -49,39 +44,39 @@ function runCypressCI() { 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" } + 'docker-compose run cypress ./node_modules/.bin/percy exec -- ./node_modules/.bin/cypress run --browser chrome', + { stdio: 'inherit' }, ); } -const command = process.argv[2] || "all"; +const command = process.argv[2] || 'all'; switch (command) { - case "start": + case 'start': startServer(); break; - case "db-seed": + case 'db-seed': seedDatabase(seedData); break; - case "run": - execSync("cypress run --browser chrome", { stdio: "inherit" }); + case 'run': + execSync('cypress run --browser chrome', { stdio: 'inherit' }); break; - case "open": - execSync("cypress open", { stdio: "inherit" }); + case 'open': + execSync('cypress open', { stdio: 'inherit' }); break; - case "run-ci": + case 'run-ci': runCypressCI(); break; - case "stop": + case 'stop': stopServer(); break; - case "all": + case 'all': startServer(); seedDatabase(seedData); - execSync("cypress run --browser chrome", { stdio: "inherit" }); + execSync('cypress run --browser chrome', { stdio: 'inherit' }); stopServer(); break; default: - console.log("Usage: npm run cypress [start|db-seed|open|run|stop]"); + console.log('Usage: npm run cypress [start|db-seed|open|run|stop]'); break; } From 48b0dfa0165f4c5e92518e08875894c1b79b77ba Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 16:43:53 +0200 Subject: [PATCH 3/6] Update execSync command --- cypress/cypress.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cypress/cypress.js b/cypress/cypress.js index 38d5bb642e..3d2b0fcdda 100644 --- a/cypress/cypress.js +++ b/cypress/cypress.js @@ -19,7 +19,10 @@ function seedDatabase(seedValues) { }); // Make sure the admin user has the same API key on every execution - execSync("docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\""); + execSync( + "docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\"", + { stdio: 'inherit' }, + ); } function startServer() { From 6f0da97cd0d73a7ac5ff29c7889169d5a17ce67a Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 16:44:32 +0200 Subject: [PATCH 4/6] Remove double installation of requirements_all_ds --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2f719909a3..8dc2ebfbd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ARG skip_ds_deps # We first copy only the requirements file, to avoid rebuilding on every file # change. -COPY requirements.txt requirements_dev.txt requirements_all_ds.txt ./ +COPY requirements.txt requirements_dev.txt ./ RUN pip install -r requirements.txt -r requirements_dev.txt RUN if [ "x$skip_ds_deps" = "x" ] ; then pip install -r requirements_all_ds.txt ; else echo "Skipping pip install -r requirements_all_ds.txt" ; fi From ec9117c6e53b727e841da2d041badbac8b852065 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 16:45:15 +0200 Subject: [PATCH 5/6] :facepalm: I'm a moron --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8dc2ebfbd1..2f719909a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ARG skip_ds_deps # We first copy only the requirements file, to avoid rebuilding on every file # change. -COPY requirements.txt requirements_dev.txt ./ +COPY requirements.txt requirements_dev.txt requirements_all_ds.txt ./ RUN pip install -r requirements.txt -r requirements_dev.txt RUN if [ "x$skip_ds_deps" = "x" ] ; then pip install -r requirements_all_ds.txt ; else echo "Skipping pip install -r requirements_all_ds.txt" ; fi From 31349b2985fe2dcdb74026ace7e7bb1a68fb0e16 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 28 Jan 2019 17:32:58 +0200 Subject: [PATCH 6/6] Move the psql command to Circle config --- .circleci/config.yml | 2 ++ cypress/cypress.js | 14 ++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac7e5bb0d1..1242d7cf18 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -73,6 +73,8 @@ jobs: command: | npm run cypress start docker-compose run cypress node ./cypress/cypress.js db-seed + # Make sure the API key is the same so Percy snapshots are consistent + docker-compose -p cypress run postgres psql -U postgres -h postgres -c "update users set api_key = 'secret' where email ='admin@redash.io';" - run: name: Execute Cypress tests command: npm run cypress run-ci diff --git a/cypress/cypress.js b/cypress/cypress.js index 3d2b0fcdda..0dda6e4cff 100644 --- a/cypress/cypress.js +++ b/cypress/cypress.js @@ -17,24 +17,14 @@ function seedDatabase(seedValues) { seedDatabase(seedValues); } }); - - // Make sure the admin user has the same API key on every execution - execSync( - "docker-compose -p cypress run postgres psql -h postgres -c \"update users set api_key = 'secret' where email ='admin@redash.io';\"", - { stdio: 'inherit' }, - ); } 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 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', - }); + execSync('docker-compose -p cypress run server create_db', { stdio: 'inherit' }); } function stopServer() {