-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cypress tests: preset the admin API key to a static value #3358
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
917dfa7
Preset the admin API key to a static value
arikfr 126bd1d
Use correct Prettier/eslint settings
arikfr 48b0dfa
Update execSync command
arikfr 6f0da97
Remove double installation of requirements_all_ds
arikfr ec9117c
:facepalm: I'm a moron
arikfr 31349b2
Move the psql command to Circle config
arikfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual change. The rest is Prettier doing its thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! That was one of the solutions I thought about (the other one would require me to use Cypress Stubs).
My idea is to create a few Cypress tests in #3354, probably one for regenerating the API Key. If needed in there, I'll revisit this.
BTW, I thought the pattern was to use singlequoted 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 you're correct. Something went wrong there. I'll fix.