-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
aliasJest causes my test suite to break #99
Comments
Managed to fix this with the help of a colleague. Wrapping my (formerly working) config in To get around that issue, we (rather clumsily) extracted the aliased paths from
|
Yes, it's not easy. It's good that you found a workaround. In order to fix
it is necessary the same configuration to reproduce. It is best to take one
of the projects in the Example folder and modify it.
Perhaps the problem will be visible if you provide the difference in the
resulting configuration. It is necessary to analyze the configuration
structure in the case when it does not work, and in the case when it works,
to identify the difference, what exactly is the problem.
чт, 18 мая 2023 г., 12:22 John Peden ***@***.***>:
… Managed to fix this with the help of a colleague. Wrapping my (formerly
working) config in aliasJest() seemed not to work so instead but *not*
doing that meant that our aliased paths were not being provided to Jest
when the test suite ran.
To get around that issue, we (rather clumsily) extracted the aliased paths
from aliasJest() and then spread them into the Jest config alonside the
existing config. Open to input if there is a better way fo doing this and
would love to know why aliasJest was killing my existing config.
jest: (config) => {
const aliasedConfig = aliasJest()(config);
const { moduleNameMapper } = aliasedConfig;
const overriddenConfig = override(
// Ignore all node modules, apart from @benefex scoped modules and non-transpiled deps
replaceJestIgnore('<some regex to include certain packages from node_modules>'),
replaceJestBabelTransform(appJestDir('<custom_babel_transform_file>')),
addJestSetupFile(appJestDir('<add_require_context>')),
)(config);
return {
...overriddenConfig,
moduleNameMapper,
};
},
—
Reply to this email directly, view it on GitHub
<#99 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB57HXCTTCZD5OHROECVGH3XGXL5FANCNFSM6AAAAAAYDWQ7SM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I'm switching an existing package that works without issue to use
react-app-alias
. My colleague and I were able to get the app running after setting a bunch of aliased paths correctly, however our unit test suite now fails to run.We've not changed the tests or any of the code that they run against and have narrowed the problem down to
aliasJest()
or at least something in that area.Prior to upgrading
Test suite runs without issue but the app doesn't run as our
config-overrides.js
is outside the project directory (it's shared across multiple apps).Existing Jest config
This works prior to the intorduction of
react-app-alias
.After switching to use
react-app-alias
If we don't touch config-overrides.js, our Jest overrides are not aware of the aliased paths so we get a bunch of errors like this:
Cannot find module 'components/ContentItem' from 'src/tests/components/ContentItem.spec.js
components is aliased in jsconfig.paths.json:
"components/*": ["src/components/*"],
New Jest config
This config gets me passed the 'cannot find module' errors but the tests fail as any Babel no longer transpiles any ES6 modules.
After switching to use
react-app-alias
andaliasJest()
If I wrap my Jest overrides with
aliasJest()
, then the aliases work but Jest fails to transpile any ES6 modules e.g:The text was updated successfully, but these errors were encountered: