-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Move cypress test project to own folder #134
Conversation
I was just working on this. I thought we can still use the test project but clean data via graphql queries rather than relying on the reset route... would it not cause a lot more work now that we have two test projects? Relaying on one implementation and taking charge of it's store of data would be a better outcome IMO? |
The main problem I'm trying to solve is completely different Keystone setups, not just data. For example, I'll need a project where access control on everything is set to The changes in this PR are the first step to having project(s) separate to the The biggest down side here is that the In terms of resetting data via GraphQL: That's a great idea, and would work really well with each of the individual projects we setup with this PR 👍 |
d3f2193
to
e5a30af
Compare
Huzzah! It works:
|
3cc76b7
to
c2bb8a4
Compare
@@ -6,8 +6,6 @@ describe('Adding data', () => { | |||
'ks-input-name': 'John Doe', | |||
'ks-input-email': 'john@gmail.com', | |||
'ks-input-password': 'password1', | |||
'ks-input-twitterId': '@johndoe', | |||
'ks-input-twitterUsername': 'John Doe', |
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.
I simplified the tests a bit by removing the twitter stuff since it wasn't actually under test beyond "is shown in admin UI", which is passing tests elsewhere.
package.json
Outdated
"cypress:run:cmd:ci": "cypress run --env PORT=3000 --reporter junit --reporter-options \"mochaFile=reports/junit/cypress-results.xml\"", | ||
"cypress:open": "start-server-and-test cypress:start:server http-get://localhost:3000/admin cypress:open:cmd", | ||
"cypress:run": "start-server-and-test cypress:start:server http-get://localhost:3000/admin cypress:run:cmd", | ||
"cypress:run:ci": "start-server-and-test cypress:start:server http-get://localhost:3000/admin cypress:run:cmd:ci", |
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.
start-server-and-test
waits for the server to be up and running before trying to run the tests, removing any timing issues with webpack compilation 👍
package.json
Outdated
@@ -98,7 +103,8 @@ | |||
}, | |||
"bolt": { | |||
"workspaces": [ | |||
"packages/*" | |||
"packages/*", | |||
"cypress/projects/*" |
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.
@jesstelford I was thinking we would (when ready) do effectively this, but split into multiple test-project packages at some higher level and have cypress test them.
roughly:
"workspaces": [
"packages/*",
"projects/*",
]
This way we can have multiple test projects set up demonstrating different features / configurations / etc
Do you think it's a good idea to also split on projects used explicitly for cypress, vs. those not under test? I'm not sure about not having the other test projects not automatically tested. I worry that'll lead to them diverging, or work being done against a "main" test project that's not caught by tests, etc.
What if we did came at this the other way around? Created multiple test projects at the top level, actually included the test scripts with them (and imported from the cypress
directory) so we are colocating the code currently under cypress/integration
with the test project?
Not sure which of these approaches is more scalable or likely to keep us on the right track long term.
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.
"workspaces": [ "packages/*", "projects/*", ]
This way we can have multiple test projects set up demonstrating different features / configurations / etc
Great idea. Done.
Do you think it's a good idea to also split on projects used explicitly for cypress, vs. those not under test? I'm not sure about not having the other test projects not automatically tested. I worry that'll lead to them diverging, or work being done against a "main" test project that's not caught by tests, etc.
It's a great point. We should definitely have tests covering each of the projects, so they never get out of sync. I'll make sure there are at least basic tests for each.
Created multiple test projects at the top level, actually included the test scripts with them (and imported from the cypress directory)
I don't think Cypress allows this - they're oddly strict in the folder structure of where tests are located, etc. But if it's possible, it'd be great!
7bec564
to
1904631
Compare
Yes that's totally right. After a brief discussion with @jesstelford I think it's best to prefix each env var so that it clearly corresponds to each project. In CI as well as in the
Explicit over implicit and if it ever gets too verbose we can still add some magic. |
61a1de6
to
e659c66
Compare
e659c66
to
50a62ef
Compare
So we've gone with number 5 from above: Running cypress tests in parallel and from their project directories. There are 2 caveats:
|
@@ -4,88 +4,116 @@ | |||
# | |||
version: 2 | |||
|
|||
x-job-setup: &job-setup |
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 like a "default" config that is imported lower down in the .yml
file, so we don't have to repeat ourselves.
x-job-setup: &job-setup | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:carbon-browsers |
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.
The -browsers
version removes the need for apt-get install
later, reducing build time by about 22seconds per test run.
name: Login E2E tests | ||
command: CYPRESS_CACHE_FOLDER=$CIRCLE_WORKING_DIRECTORY/node_modules/cypress/.cache/ bolt ws run cypress:run:ci --only-fs projects/login | ||
environment: | ||
PORT: 4000 |
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.
NOTE: Thanks to running these in seperate processes, the env vars no longer clash, so prefixing is not necessary.
@@ -5,8 +5,8 @@ | |||
"license": "MIT", | |||
"scripts": { | |||
"coverage": "jest --coverage --collectCoverageFrom=packages/**/*.{js}", | |||
"cypress:open": "cypress open", | |||
"cypress:run": "cypress run", | |||
"cypress:run": "bolt ws run cypress:run", |
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.
Used only for local testing.
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.
Should it then rather use bolt ws run cypress:open
or will this break?
@@ -1,24 +1,22 @@ | |||
describe('Adding data', () => { | |||
[ | |||
{ | |||
url: 'http://localhost:3000/admin/users', | |||
url: '/admin/users', |
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.
By setting the baseUrl
in cypress/plugins/index.js
, we don't need to specify the entire URL for cy.X
commands, avoiding having to read from env vars too.
Cypress.Commands.add('graphql_query', query => | ||
apolloFetch({ query }) | ||
Cypress.Commands.add('graphql_query', (uri, query) => | ||
getApollo(uri)({ query }) |
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.
Changed to explicitly pass in the graphql endpoint, enabling future use of querying different endpoints as required.
|
||
const GRAPHQL_URI = 'http://localhost:3000/admin/api'; | ||
const apolloFetch = createApolloFetch({ uri: GRAPHQL_URI }); | ||
const getApollo = memoize(function createApollo(uri) { |
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.
Only want to create a single instance per URI, so we memoize based on that param.
"prepare-test-server": "node -r dotenv-safe/config -e 'require(`execa`)(`start-server-and-test`, [`start`, `http-get://localhost:${process.env.PORT}/admin`, process.argv[1]], { stdio: `inherit` }).catch(error => { console.error(error.toString()); process.exit(error.code) })'", | ||
"cypress:run:ci": "yarn prepare-test-server cypress:run:cmd:ci", | ||
"cypress:run": "if [ -f .env ]; then yarn prepare-test-server cypress:run:cmd; else echo \"\nError: Must create a projects/basic/.env file.\nSee projects/basic/.env.example for values\n\"; exit 1; fi", | ||
"cypress:open": "if [ -f .env ]; then yarn prepare-test-server cypress:open:cmd; else echo \"\nError: Must create a projects/basic/.env file.\nSee projects/basic/.env.example for values\n\"; exit 1; fi" |
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.
These commands are repeated in each project. They're of medium complexity, and favour repetition over more scripts given the feedback on the original PR.
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.
Note also there is a friendly error output for first time test run (when .env
hasn't been setup).
@@ -8,7 +8,8 @@ | |||
"node": ">=8.4.0" | |||
}, | |||
"scripts": { | |||
"start": "node -r dotenv-safe/config index.js" | |||
"start": "node -r dotenv-safe/config index.js", | |||
"cypress:run:ci": "exit 0" |
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.
No tests setup yet for this project, so exit with success.
This all looks good to me. I particularly like that the integration tests are explicitly colocated with the project they test. Hopefully this pattern will be valuable to developers building their own projects. There are two follow up tasks which we should look into after this task goes through:
|
🤔 ... insightful!
This mechanism already exists, just the output on the CLI is confusing (you'll still see failures though). I'll update the edit @timleslie see commit 4f7aad0 for updated docs. |
Looks great, LGTM |
I've left
packages/test-project
alone, but the Cypress tests now run againstcypress/projects/basic
.Ideally there will be other
cypress/projects/*
in the future for different setups.