Closed joeluong-sfcc closed 1 month ago
@joeluong-sfcc I think we need to think about the bigger picture here, does it make sense for us to allow end-users the ability to run tests for projects that we are extending from? Have we thought about ignoring running any tests that are in the extended project as a solution here?
@joeluong-sfcc I think we need to think about the bigger picture here, does it make sense for us to allow end-users the ability to run tests for projects that we are extending from? Have we thought about ignoring running any tests that are in the extended project as a solution here?
@bendvc You bring up a good point. I think that certain tests wouldn't really make sense in an extended project, like tests that retest the implementation of a component from the underlying project. However, I still think we should allow end users to write unit tests in their extended project using exported components/functions from the underlying project. For example, I can imagine a scenario where a user would want to test the behavior of their overriding component and compare it to the underlying component that they're overriding.
I'd like to get your thoughts as well, do you think it makes sense to allow users to write tests in this manner (or other tests in general) in their extended projects?
@joeluong-sfcc I think we need to think about the bigger picture here, does it make sense for us to allow end-users the ability to run tests for projects that we are extending from? Have we thought about ignoring running any tests that are in the extended project as a solution here?
@bendvc You bring up a good point. I think that certain tests wouldn't really make sense in an extended project, like tests that retest the implementation of a component from the underlying project. However, I still think we should allow end users to write unit tests in their extended project using exported components/functions from the underlying project. For example, I can imagine a scenario where a user would want to test the behavior of their overriding component and compare it to the underlying component that they're overriding.
I'd like to get your thoughts as well, do you think it makes sense to allow users to write tests in this manner (or other tests in general) in their extended projects?
Yes. I agree that if we have a "test" script it implies that we have some kind of testing framework setup and executing that script will run it. So if a developer that is working on an extended project wants to add tests for a new component, whether that component is a new page or an override, it should be executed when they use npm run test
. But what shouldn't happen is the entire set of tests being run for the underlaying template that is being extended.
I'm open to discussing reasons why we might want to do that, but I can't think of any off the top of my head. The template being extended is, kind of a "grey" box, we know the api and how to use it, but we shouldn't be running the tests we created during an extended projects build cycle.
Description
There is currently an issue (https://github.com/SalesforceCommerceCloud/pwa-kit/issues/1763) in generated projects with extensibility where if you try to run unit tests, you can end up with the following error:
Note that the
SyntaxError: Cannot use import statement outside a module
error comes from within thenode_modules
, specifically atnode_modules/@salesforce/retail-react-app/app/components/_app-config/index.jsx
This issue occurs because transformations are not applied to
node_modules
by default. The files within thenode_modules/@salesforce/retail-react-app
directory are not formatted in the way that Jest expects. The fix is to ensure transformations are applied tonode_modules/@salesforce/retail-react-app
by configuring it in thejest.config.js
file.Steps to reproduce:
npx @salesforce/pwa-kit-create-app@latest --preset=retail-react-app-demo
cd retail-react-app-demo
index.test.js
) toretail-react-app-demo/overrides/app/components/_app-config/
npm run test
Types of Changes
Changes
jest.config.js
file to generated projects with extensibility enabledHow to Test-Drive This PR
git checkout ju/fix-import-extensible-tests
node ./packages/pwa-kit-create-app/scripts/create-mobify-app.js --preset=retail-react-app-demo
cd retail-react-app-demo
index.test.js
) toretail-react-app-demo/overrides/app/components/_app-config/
npm run test
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization