-
Notifications
You must be signed in to change notification settings - Fork 508
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
Jest does not work with macros -- build
babel config is not used for test
#383
Comments
@arvigeus possible solution: |
@ambroseus I was thinking the same, but I will need to untangle the config from that function. Haven't done something like that before, should be fun |
@arvigeus need to implement |
My first (failed) attempt: https://github.com/arvigeus/tsdx/commit/83d26bf66ddd4b560734fbbbe91e31ba3a92f332 Problem 1: Does not actually work at all. |
Another failed attempt here: https://github.com/arvigeus/tsdx/tree/bugfix-ts-jest-use-babel It seems like the correct way, but I am missing something. Or I am entirely wrong again... |
I also think about how to make our dev life easy and avoid configs hell :) |
@arvigeus have you tried just adding // jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: true
}
}
}; If you did, did that still not work? So long as your {
"plugins": [
"macros"
]
} I'm not sure that re-using all of TSDX's internal babel config is necessary for resolving this. I'm also not sure that it's necessarily ideal to re-use that for tests, because the test environment is different. But I do agree (as I've said in other issues) that it should be easier to re-use pieces of TSDX and a preset would be good to have (though TSDX changes it based on config options, so it's a bit complex). And this use case probably makes sense to support internally as well with a PR, in my opinion. I'm not totally sure why your attempts don't work for the Jest config -- I do see that you set |
Just experienced a similar problem in one of my packages, which works fine with I had some issues with using |
build
babel config is not used for test
So just to make it explicit for anyone looking for a workaround: |
Just jotting some implementation notes here: Started work, found merging problems...So I've started to work on creating a Babel preset similar to @arvigeus 's work (although looks like their fork/branch/commit is gone now, links are 404'ing), but the merging TSDX currently does in Furthermore, if TSDX just requests users to use a TSDX preset (a la #634), then duplicate plugins or presets actually won't be merged at all, they'll be re-run a second time per babel/babel#8799 ... 😕 i.e. If instead one had: module.exports = {
presets: [
'@tsdx/babel-preset',
['@babel/preset-env', /* .... */ ],
],
} There would actually be two instances of The fix, I suppose, is to allow configuring all of the plugins or presets within module.exports = {
presets: [
['@tsdx/babel-preset', {
'@babel/preset-env': /* .... */,
}],
],
} but that's very breaking and users would have to know that that's possible; it's somewhat low-level. TSDX could warn on detection of a duplicate preset/plugin though 🤔 But it'd be difficult to tell if the duplicate were intentional or not (I assume it'd be unintentional in most cases, but not all). I'm not really sure what the optimal option is here... issues with all those options. Partial Resolution likely possibleThat being said, this doesn't need to be entirely solved to resolve this issue. Only a partial resolution is needed for this, which I think can be done. A full resolution is necessary for #634 though. Misc NotesCurrent detection/merge logic has some missesAlso of worth to note is that the current detection logic misses things like Most overrides were removedPer #583 (comment) , I did remove most of the overrides TSDX did during merging in #795, but Per-output options could be problematicPer-output options, like the This is currently the only place it's used though, so perhaps it's avoidable -- have been looking into change this one option for #759 already |
Has anyone found a fix to this? I tried using #383 (comment) as a fix but this only gave me more errors. I am also using styled-components and attempting to get the macro working. |
@iDavidB I got it to work but it was quite a while ago.. I'm just looking at the setup in my project.. So try adding the
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
]
],
"plugins": [
["macros"]
]
}
module.exports = {
globals: {
'ts-jest': {
babelConfig: '.babelrc',
},
},
} Let me know if that does the trick! |
@zenflow Thank you very much! That did do the trick! |
* Improve styled components build related docs: - jaredpalmer/tsdx#543 - jaredpalmer/tsdx#383 - https://styled-components.com/docs/tooling#babel-macro * v0.1.26-0
Current Behavior
For example: Using
styled-components/macros
breaks the test. Usingstyled-components
does not.Suggested solution(s)
https://kulshekhar.github.io/ts-jest/user/config/babelConfig
Additional context
I can make a PR for this, but not sure how to tell it to find the babel config that tsdx uses
The text was updated successfully, but these errors were encountered: