-
Notifications
You must be signed in to change notification settings - Fork 336
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
Epic7 e2e tests #1413
Epic7 e2e tests #1413
Conversation
package.json
Outdated
@@ -14,35 +14,35 @@ | |||
}, | |||
"main": "index.js", | |||
"scripts": { | |||
"start": "NODE_ENV=production node --trace-warnings ./src/server/server.babel.js", | |||
"start": "NODE_ENV=${NODE_ENV:-production} node --trace-warnings ./src/server/server.babel.js", |
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.
what's this do?
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 there's a NODE_ENV
already bound in the environment, it uses that value, otherwise production
.
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.
can you give me an example where this is useful? it kinda scares me because this makes it seem a little less expressive because after calling this, i still don't know what env it's running in.
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 could revert this change if you like - it's a holdover from when I was associating the value of NODE_ENV
with the .env.<NODE_ENV>
files.
That said, here's an example of how it'd work:
$ # when NODE_ENV='' (unbound)
$ npm start # NODE_ENV is bound to 'production'
$ # when NODE_ENV='production'
$ npm start # NODE_ENV is bound to 'production'
$ # when NODE_ENV='development'
$ npm start # NODE_ENV is bound to 'development'
$ # ...etc
f4eccb0
to
cff772b
Compare
Codecov Report
@@ Coverage Diff @@
## epic7 #1413 +/- ##
=======================================
Coverage 44.01% 44.01%
=======================================
Files 359 359
Lines 4194 4194
Branches 572 572
=======================================
Hits 1846 1846
Misses 2019 2019
Partials 329 329 Continue to review full report at Codecov.
|
cff772b
to
2c244a8
Compare
package.json
Outdated
"start:tunnel": "export $(grep ^ULTRAHOOK_API_KEY .env | tr -d '\"') && ultrahook -k $ULTRAHOOK_API_KEY dev 3000", | ||
"dev": "if [ ! -f \"dll/vendors.json\" ] ; then npm run build:dll ; fi ; NODE_ENV=development node --trace-warnings ./src/server/server.babel.js", |
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.
[FYI] - most of these changes are just me re-ordering things in rough alphabetical order / trying to keep similar scripts close to each other.
Hey @mattkrick - if you have any early feedback, please feel free to leave it! I've got the auth tests working, and I'm planning to refactor that I'm also thinking of keeping this PR scoped to a proof-of-concept implementation, and adding more e2e tests incrementally. If you hav other feelings let me know! |
src/universal/utils/dotenv.js
Outdated
const config = {silent: true}; | ||
|
||
if (NODE_ENV) { | ||
config.path = `.env.${NODE_ENV}`; |
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 this change will have implications for others' dev environments, so I can revert it if need be. The main point is that this used to only use .env.test
when NODE_ENV === "test"
, and I changed it to use .env.${whateverTheNodeEnvIs}
. I'm finding it useful to keep a bunch of local .env
files for different builds.
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'm not a huge fan of the multiple .env
files. it may be a necessary evil for running a test on CI, but i'd be more inclined to get rid of the .env.test
and move that stuff to the CI internal environment instead of expanding the scope. see https://github.com/motdotla/dotenv#should-i-have-multiple-env-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.
I think this is fine, as long as .env*
is in .gitignore
. It's a fine thing to be able to be able to run your local instance and fire up the e2e tests for local integration (or even local continuous integration). I'd also suggest a fallback to .env
if it cannot find the local .env.$NODE_ENV
file...
e2e/runTests.js
Outdated
const execP = promisify(child_process.exec); | ||
const globP = promisify(glob); | ||
|
||
const SERVER_TIME_TO_START = 10000; |
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'd suggest that any of these "big knob" constants are kept in their own file.
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.
Yessir! I'd love to be able to fork the server process and receive a message back when the server is ready to accept connections. If you've got any ideas, let me know! I'll be looking into this in my current refactor.
e2e/runTests.js
Outdated
const mocha = new Mocha({ | ||
// Note that 20 seconds is a reasonably long timeout. I'm betting that | ||
// tests will generally fail due to errors rather than timeouts. | ||
timeout: 20000, |
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 also a "big knob" constant, and should be considered to be in its own file
34b9f69
to
2fe4ba1
Compare
d6fbf3f
to
ee0a6f4
Compare
@jordanh @mattkrick - if either of you'd like to take a final look, I've addressed feedback and got the initial tests running on circle! I'm thinking that further testing can be added on incrementally rather than monolithically in this 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.
absolutely amazing! i really tried to beat this up but all i could find were a couple nits. really, really great.
- type: shell | ||
name: E2E test build | ||
command: | | ||
cp $DEVOPS_WORKDIR/environments/e2e ./.env |
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!
|
||
export async function hasDrivers() { | ||
try { | ||
const realDriverFilenames = new Set(await promisify(fs.readdir)(DRIVERS_DIR)); |
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.
woooo this is a lot to take in for a single line, i'm cool with it if you are though
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.
Haha, yeah, I guess it is a bit much. I'll leave it for now; not expecting this file to cause a lot of tension.
export async function hasDrivers() { | ||
try { | ||
const realDriverFilenames = new Set(await promisify(fs.readdir)(DRIVERS_DIR)); | ||
return !DRIVERS.find((driver) => !realDriverFilenames.has(driver.driverFilename)); |
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.
my brain is a little fried, but couldn't you simplify away the double negative?
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'm always on the lookout to good solutions to brain fry!
I believe the double negative here is necessary, because if you think about it, it's not a real double negative:
The inner !realDriverFilenames.has(driver.driverFilename)
: We iterate over the DRIVERS
array, looking for one that is not downloaded. If we got rid of this, we might not make it through the whole array, and may miss a missing driver.
The outer !DRIVERS.find(...)
: if that inner find returns us a driver, then we need to download that webdriver; if it returns undefined
, then we've got all our drivers. The truthiness of those values is the opposite of the question "do we have all of our drivers?"
Hope that helps!
e2e/scripts/ensureDrivers.js
Outdated
} | ||
|
||
async function ensureDrivers() { | ||
const drivers = [ |
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.
could we replace this with the DRIVERS constant? to dry it up?
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.
Doh! Yes! Good catch.
e2e/scripts/ensureDrivers.js
Outdated
} | ||
} | ||
|
||
async function ensureDrivers() { |
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 could make this a sync function & just return Promise.all
if you wanted. Usually eslint picks up things that don't need to be async.
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 catch!
e2e/scripts/runTests.js
Outdated
|
||
commander | ||
.version('1.0.0') | ||
.description('Runs end-to-end tests against the Action app') |
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.
heh, let's call it Parabol. Calling it Action is deprecated, but hard to move away from 😄
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 got it!
e2e/tests/authentication.test.js
Outdated
.click(); | ||
await all( | ||
driver | ||
.wait(until.urlMatches(BASE_URL_REGEX), 2000, 'Logging out did not redirect to the base URL'), |
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.
can we make that 2000 a constant? i can see us reusing this a bunch
Maybe 2000 for things that relay on our server. 5000 for things that relay on a 3rd party like auth0, etc.
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, fair point. My only tension on this is that timing is finicky, and some things may take longer than others. That said, we can address that when we get there. What if I declared a wait
object that looks like { short: 2000, medium: 3000, long: 5000 }
?
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 like it! and maybe a comment to say when to use each. it'll be a heuristic, but at least it'll give the next guy an idea of where to start.
cache.credentials = credentials; | ||
}); | ||
|
||
it('can log in (and out) with valid credentials', async () => { |
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 makes me so happy i could barf. well done!
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.
Gee, thanks!
package.json
Outdated
@@ -14,35 +14,35 @@ | |||
}, | |||
"main": "index.js", | |||
"scripts": { | |||
"start": "NODE_ENV=production node --trace-warnings ./src/server/server.babel.js", | |||
"start": "NODE_ENV=${NODE_ENV:-production} node --trace-warnings ./src/server/server.babel.js", |
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.
can you give me an example where this is useful? it kinda scares me because this makes it seem a little less expressive because after calling this, i still don't know what env it's running in.
@dan-f great work! Only bug is that it borks the build on deployment. |
Hey @mattkrick thanks for the suggestions and kind words! Regarding your last comment ( Oops! I see two patterns here:
So we could fix this by either reverting the change such that Looking forward to your thoughts! |
IMO i like the first option, but i almost always opt for a bunch of smaller single-use scripts. |
Well, in any case, we're going to need some CLI interface by which we can specify the particular NODE_ENV. I can understand the arguments for option 1, so let's do that! |
@mattkrick - build passes w/ fixes addressing your final feedback. I'm not quite sure how to verify the prod build, so I'd appreciate your help with that! |
# Conflicts: # yarn.lock
This one fixes #1316.
I figured the benefits of driving multiple browsers concurrently (not yet introduced here) outweighs the nicer API cypress offers.