-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Unit tests in jest + minor cart store and hooks refactor #2414
Unit tests in jest + minor cart store and hooks refactor #2414
Conversation
@filrak All files in core/modules/cart except actions have full coverage, but I don't see much of a reason in testing actions. There are some areas to fix here and there in whole module including:
But I did the tests nonetheless. These issues are not super critical in opposite to what is happening to actions.ts alone:
Because of that, I suggest refactoring this area first because the code will change significantly after refactoring and will have to be rewritten anyway. @pkarw @patzick what do you think of it? Also please CR |
AWESOME job, thanks ;) Thanks again, huge step forward in quality |
package.json
Outdated
@@ -37,7 +37,7 @@ | |||
"build:client": "cross-env NODE_ENV=production TS_NODE_PROJECT=\"tsconfig-build.json\" webpack --config ./core/build/webpack.prod.client.config.ts --mode production --progress --hide-modules", | |||
"build:server": "cross-env NODE_ENV=production TS_NODE_PROJECT=\"tsconfig-build.json\" webpack --config ./core/build/webpack.prod.server.config.ts --mode production --progress --hide-modules", | |||
"build": "rimraf dist && yarn build:client && yarn build:server && yarn build:sw", | |||
"test:unit": "karma start ./tests/unit/karma.conf.js --single-run", | |||
"test:unit": "yarn jest -c test/unit/jest.conf.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.
i think this should be without yarn
, we're already calling yarn test:utils
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.
any response to this?
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 was certain that I fixed it last time. Will update in a minute
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.
Great job.
@lukeromanowicz is it still in WIP status? |
@patzick Yes, it is. I've been told to continue actions tests and clearing up dependencies is still todo. |
9e3a86d
to
5536a16
Compare
c4fbce7
to
83b18a4
Compare
83b18a4
to
5f6a881
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.
Mostly looks good to me. It's nice that you updated travis workflow!
Just some minor improvements and conflict to resolve.
And yes - i think this should go to 1.9.0-rc.1 after review. @filrak WDYT?
core/modules/cart/store/actions.ts
Outdated
if ((Date.now() - context.state.cartServerTotalsAt) >= CART_TOTALS_INTERVAL_MS) { | ||
context.state.cartServerPullAt = Date.now() | ||
context.state.cartServerTotalsAt = Date.now() |
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 should be mutation
core/modules/cart/store/actions.ts
Outdated
@@ -91,9 +92,9 @@ const actions: ActionTree<CartState, RootState> = { | |||
} | |||
}, | |||
serverTotals (context, { forceClientState = false }) { // pull current cart FROM the server | |||
if (rootStore.state.config.cart.synchronize_totals && !Vue.prototype.$isServer) { | |||
if (rootStore.state.config.cart.synchronize_totals && !isServer) { |
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.
in future we'd like to get rid of config inside state because it is ~16kB of data which is barely needed on initial load. Please import config
and apply suggestion
if (rootStore.state.config.cart.synchronize_totals && !isServer) { | |
if (config.cart.synchronize_totals && !isServer) { |
core/modules/cart/store/actions.ts
Outdated
@@ -110,7 +111,7 @@ const actions: ActionTree<CartState, RootState> = { | |||
} | |||
}, | |||
serverCreate (context, { guestCart = false }) { | |||
if (rootStore.state.config.cart.synchronize && !Vue.prototype.$isServer) { | |||
if (rootStore.state.config.cart.synchronize && !isServer) { |
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 (rootStore.state.config.cart.synchronize && !isServer) { | |
if (config.cart.synchronize && !isServer) { |
package.json
Outdated
@@ -37,7 +37,7 @@ | |||
"build:client": "cross-env NODE_ENV=production TS_NODE_PROJECT=\"tsconfig-build.json\" webpack --config ./core/build/webpack.prod.client.config.ts --mode production --progress --hide-modules", | |||
"build:server": "cross-env NODE_ENV=production TS_NODE_PROJECT=\"tsconfig-build.json\" webpack --config ./core/build/webpack.prod.server.config.ts --mode production --progress --hide-modules", | |||
"build": "rimraf dist && yarn build:client && yarn build:server && yarn build:sw", | |||
"test:unit": "karma start ./tests/unit/karma.conf.js --single-run", | |||
"test:unit": "yarn jest -c test/unit/jest.conf.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.
any response to this?
test/unit/package.json
Outdated
{ | ||
"name": "@vue-storefront/unit-tests", | ||
"private": true, | ||
"version": "0.1.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.
this shouldn't be current storefront version?
@lukeromanowicz could you make this improvements today, so we could add this to upcoming RC version? |
@patzick thank you for your input. I didn't really plan to do any refactoring except necessary changes to make the code possible to test but in the end, I did the changes in accordance with your suggestions. Please re-review. |
Related issues
#2305
Short description and why it's useful
Currently, existing tests (16 of them to be precise) written with mocha & karma are integration tests that might seem like a little bit chaotic. As VSF is growing fast, it's high time to use a more modern, comprehensive tool and start writing actual unit tests.
Upgrade Notes and Changelog
Contribution and currently important rules acceptance
Changes made in this PR:
tests/
totest/
directory