-
Notifications
You must be signed in to change notification settings - Fork 438
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
js: Add Jest testing #801
js: Add Jest testing #801
Conversation
Also pinging @stefangehn, @blatinier and @Lucas-C here. Let me know if you find this useful and please share tips/improvements/general ideas. I'd love for someone more knowledgeable than me to write some proper tests and I hope this is a good starting-off point. A way to simply have some |
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 bootstrapping! Good job @ix5 :)
Can I commit stuff on this branch if I find the time to write some tests?
"build-dev": "webpack --config isso/js/webpack.config.js --config-name dev", | ||
"watch-dev": "webpack --config isso/js/webpack.config.js --config-name dev --watch", | ||
"build-prod": "webpack --config isso/js/webpack.config.js --merge --config-name dev --config-name prod" | ||
}, | ||
"devDependencies": { | ||
"jest": "^27.5.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.
"jest-puppeteer" is missing ;)
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.
Adding jest-puppeteer
to devDependencies
will automatically pull in a 400Mb+ download of headless chrome, as explained earlier. That's why I'm a bit hesitant to add it here.
Imo it should be up to the user whether they need to run the end-to-end tests.
Maybe there's an option to configure the package before installing to not pull in the chrome download automatically?
isso/js/jest-puppeteer.config.js
Outdated
@@ -0,0 +1,6 @@ | |||
module.exports = { |
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 file should be at the root of the repository.
It is currently ignored by Jest when running npm test
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 like to keep all javascript-related stuff inside isso/js/
, so I'll have to figure out a way for Jest to read this file.
See https://github.com/smooth-code/jest-puppeteer#configure-puppeteer
(remains TODO)
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.
Point of reference: argos-ci/jest-puppeteer#160 (comment)
process.env.JEST_PUPPETEER_CONFIG = require.resolve('./jest-puppeteer.config.js');
Hey @Lucas-C, thank you so much for reviewing and verifying! I probably should have split this PR into two PRs, one for Jest and one for the addition of Re: Instrumentation is hard, and I'm open to suggestions here as I have no experience and no idea what accepted standard practices are. |
fe23d2c
to
fbaac0b
Compare
Provide a base config and npm commands to run unit tests using the `Jest` tool. Recommendations have been lifted from https://mailchimp.com/developer/open-commerce/docs/testing-requirements/ `jsdom` "emulates" a browser environment in a light way so that access to `window`, `document` etc. is possible.
Just a simple test as a starting point for further ones.
Test expected languages when none are set in the browser. Could be expanded further.
As discussed in #754, add some basic Jest testing config and examples to facilitate finally writing some frontend code tests.
Note: End-to-end tests using
puppeteer
were split off and moved into #807Terminology
Running
Install the needed packages:
Then run:
npm run test-unit
for Jest unit testsHighly WIP at the moment, but could be useful to someone else working on the same issues. Please communicate and collaborate!
Depends on #800.
I have temporarily changed the base to that branch to make it easier to review this change.