-
Notifications
You must be signed in to change notification settings - Fork 178
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
ci(travis): run cypress e2e tests on build #5431
Conversation
Codecov Report
@@ Coverage Diff @@
## edge #5431 +/- ##
=======================================
Coverage 65.64% 65.64%
=======================================
Files 1084 1084
Lines 30905 30905
=======================================
Hits 20287 20287
Misses 10618 10618
Continue to review full report at Codecov.
|
@@ -43,7 +43,7 @@ const saveFile = (downloadData: $PropertyType<Props, 'downloadData'>) => { | |||
const blob = new Blob([JSON.stringify(downloadData.fileData)], { | |||
type: 'application/json', | |||
}) | |||
if (global.Cypress) { | |||
if (process.env.CYPRESS === '1') { |
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 will also have to be changed to an env var in your other PR #5424, right?
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.
If possible, I would love these e2e tests to be parallel rather than balloon out the existing JS test job
.travis.yml
Outdated
@@ -84,13 +84,14 @@ jobs: | |||
|
|||
# test, build, and upload for JavaScript projects | |||
- stage: test | |||
name: 'JS unit tests; build Protocol Designer, Labware Library, Components Library' | |||
name: 'JS unit & E2E tests; build Protocol Designer, Labware Library, Components Library' |
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 think it's a better idea to put E2E tests in their own parallel job in the test stage rather than blowing this job out even further.
If the reason it was placed in this stage was to prevent deploy of PD if the e2e tests don't pass, then I have two thoughts while we're still on Travis:
- We could move PD deploy to a job in the "deploy" stage
- This gates PD deploy on API tests passing
- We could continue to put PD artifacts in S3 regardless of what the e2e tests say
- PD "deploy" uploads artifacts in S3; it does not actually deploy anything
- I don't think preventing artifact uploads on e2e failures is necessarily worth the effort (not that it's a bad idea or anything)
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.
don't think preventing artifact uploads on e2e failures is necessarily worth the effort (not that it's a bad idea or anything)
👍
"$(MAKE) dev" \ | ||
"cypress run --browser chrome" | ||
concurrently --no-color --kill-others --success first --names "labware-library-server,labware-library-tests" \ | ||
"$(MAKE) dev CYPRESS=1 GTM_ID=''" \ |
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.
Why are we defining a new environment variable? We already have NODE_ENV=test, I feel like it might be a little more straightforward to do NODE_ENV=cypress or e2e or something similar
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.
It looks like we only ever set NODE_ENV to 'production' or 'development', I don't see test
?
I was worried that since we're just using 2 states of NODE_ENV, we'd find places in our code with an assumption "if NODE_ENV isn't production then it must be development". But now going through uses of NODE_ENV the only time I see something like that is const DEV_MODE = process.env.NODE_ENV !== 'production'
in app-shell which isn't going to cause an issue.
However, it's easy to do if (NODE_ENV === 'development ) {/* dev stuff */} else {/* prod stuff, but oops this also happens when NODE_ENV is cypress */}
and IMO this is more complicated to think about than using a new env var.
Also any use of process.env.CYPRESS
env var in the app code is an easy-to-search-for indicator that we had to do something gross to get Cypress to do something that it's not able to do, like looking at saved files
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.
agree re:
easy-to-search-for indicator
But I think we should be in the habit of explicitly checking strings rather than relying on an else
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.
It looks like we only ever set NODE_ENV to 'production' or 'development', I don't see test?
I don't much care, but since Jest sets NODE_ENV to test
during testing, (see https://jestjs.io/docs/en/getting-started#using-babel; expand the "Making your Babel config jest-aware" section) I suggested NODE_ENV="cypress"
to match that behavior. You can see our usage of this in our babel config:
env: {
// Note(isk: 3/2/20): Must have babel-plugin-styled-components in each env,
// see here for further details: s https://styled-components.com/docs/tooling#babel-plugin
production: {
plugins: ['babel-plugin-styled-components', 'babel-plugin-unassert'],
},
development: {
plugins: ['babel-plugin-styled-components', 'react-hot-loader/babel'],
},
test: {
plugins: [
'babel-plugin-styled-components',
'@babel/plugin-transform-modules-commonjs',
'babel-plugin-dynamic-import-node',
],
},
},
However, it's easy to do if (NODE_ENV === 'development' ) {/* dev stuff /} else {/ prod stuff, but oops this also happens when NODE_ENV is cypress */} and IMO this is more complicated to think about than using a new env var.
In my experience, checking for production environment should always be checking that the env was explicitly set to production to avoid this exact issue.
@@ -43,7 +43,7 @@ const saveFile = (downloadData: $PropertyType<Props, 'downloadData'>) => { | |||
const blob = new Blob([JSON.stringify(downloadData.fileData)], { | |||
type: 'application/json', | |||
}) | |||
if (global.Cypress) { | |||
if (process.env.CYPRESS === '1') { | |||
// HACK(IL, 2020-04-02): can't figure out a better way to do this yet |
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.
Rather than polluting the application code here, could you replace fileSaver
using webpack
or babel
if the environment doesn't support it? See eligrey/FileSaver.js#501
Also, the app attached the Redux store to the window if the NODE_ENV isn't production, but that doesn't feel like the problem here
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.
It will save fine under Cypress, but Cypress has no way to locate the file. Sometimes the test will timeout if a file is saved because depending on browser settings it might make a native "Save File..." modal that never closes, but that doesn't have to do with fileSaver
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.
Yeah to be clear, I'm not suggesting we change this global.__lastSavedFile__ = downloadData.fileData
behavior during Cypress runs. I'm saying that this override should happen using a mock for FileSaver
that webpack (using the resolve) config or babel (using babel-plugin-module-resolver) shims in when the environment is Cypress rather than putting the override logic in application code
Regardless, certainly not a request for this PR, sorry for not making clear in the original post
71897c5
to
0ab1098
Compare
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.
🌲
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.
🌵
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.
Good stuff @IanLondon!
"$(MAKE) dev" \ | ||
"cypress run --browser chrome" | ||
concurrently --no-color --kill-others --success first --names "labware-library-server,labware-library-tests" \ | ||
"$(MAKE) dev CYPRESS=1 GTM_ID=''" \ |
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.
agree re:
easy-to-search-for indicator
But I think we should be in the habit of explicitly checking strings rather than relying on an else
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.
Posted some clarifications but this LGTM. Looking over the Travis run is making me more convinced we should switch to GH actions and get even more parallelization going on
.travis.yml
Outdated
@@ -84,7 +84,7 @@ jobs: | |||
|
|||
# test, build, and upload for JavaScript projects | |||
- stage: test | |||
name: 'JS unit tests; build Protocol Designer, Labware Library, Components Library' | |||
name: 'JS unit; build Protocol Designer, Labware Library, Components Library' |
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.
Unintentional removal of "tests"?
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.
d'oh
@@ -43,7 +43,7 @@ const saveFile = (downloadData: $PropertyType<Props, 'downloadData'>) => { | |||
const blob = new Blob([JSON.stringify(downloadData.fileData)], { | |||
type: 'application/json', | |||
}) | |||
if (global.Cypress) { | |||
if (process.env.CYPRESS === '1') { | |||
// HACK(IL, 2020-04-02): can't figure out a better way to do this yet |
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.
Yeah to be clear, I'm not suggesting we change this global.__lastSavedFile__ = downloadData.fileData
behavior during Cypress runs. I'm saying that this override should happen using a mock for FileSaver
that webpack (using the resolve) config or babel (using babel-plugin-module-resolver) shims in when the environment is Cypress rather than putting the override logic in application code
Regardless, certainly not a request for this PR, sorry for not making clear in the original post
0ab1098
to
42a5716
Compare
* run cypress tests in new Travis job * labware-library: do not add GTM script when E2E testing
overview
Run cypress tests in Travis! Build will fail if any e2e tests fail. Closes #5318
This is dependent on #5424 - after it is merged, I'll rebase this PR and change
if (global.Cypress)
in that PR toif (process.env.CYPRESS === '1')
.changelog
review requests
Sanity check!
GTM_ID=''
and also just to be safe I cut out the GTM tag from the Handlebars HTML template if GTM_ID is falsey.wait-until
to make sure that the dev server is running before trying to start Cypresscd protocol-designer; yarn cypress open (whatever args)
rather than going thru Make.risk assessment
Significant risk to our workflow, but easy to roll back. If this causes builds to fail intermittently, or go too slowly, we'll have to change it back. Worst case scenario is removing
make test-e2e
from Travis yml to stop running the tests until we fix whatever problem we might have.