Comments (6)
Jest mocks do not allow accessing vars from the outer scope, which exports is.
please expand on the problem. give an example
from babel-preset-firecloud.
I understand only partially what you're experiencing
-
and you presumably mock an entire module e.g. aws-sdk while referencing a shared top-level function, which babel rewrites as
exports.
-
which can be fixed by the documented
doMock
function jestjs/jest#2567 (comment)
Footnotes:
-
The problem is not in the transpilation of the
src
folder but thetest
folder, so adding a.babelrc
inside thetest
disabling export-all should work -
I don't even know how come you trigger the export-all plugin inside a jest test module (which should have no export statements)
from babel-preset-firecloud.
Okay, so it went a bit deeper than I thought...
Will reply to your quotes first.
and you presumably mock an entire module e.g. aws-sdk while referencing a shared top-level function, which babel rewrites as exports.
which can be fixed by the documented doMock function jestjs/jest#2567 (comment)
This can help sometimes when you don't need the hoisting mock behavior, but sometimes you need hoisting (you import tested module and it imports a mocked dependency). Cool thing is that jest allows to have vars prefixed with mock
to be referenced in mocks. This kind of implies that you know what you are doing. So on our side in export-all
we could add an option for this like ignorePrefix
.
The problem is not in the transpilation of the src folder but the test folder, so adding a .babelrc inside the test disabling export-all should work
This works, but only for files in the test folder. Files in src
folder will be transpiled with root .babelrc
. With suggested workaround above, we could even keep one plugin config (root) across src
and test
. (Spoiler: further, you will see why it's not enough...)
I don't even know how come you trigger the export-all plugin inside a jest test module (which should have no export statements)
This exception we have only for linter rules, remember? For babel plugin, I don't think we should do this, because you never know if the state of AST tree and ExportDeclaration
nodes in it are coming from the source code or were generated by another plugin. Probably, it is possible to know by analyzing original source code as string (you have this info in plugin), but I think it's brittle.
BUT... I was wrong when stated the problem in the title. The original problem (95% of all errors) is with coverage plugin Istanbul and that it ruins the AST somehow. I checked the code and they don't appear to be doing anything wrong, but somehow when the execution comes to our plugin, the tree is not correct and this causes same error as here istanbuljs/babel-plugin-istanbul#116. Instead of fixing a bug here, people actually suggest disabling faulting plugin in test env. Sad.
I really-really don't want to spend any more time on this problem, even though it's so fun to dig in jest/babel/istanbul 😂 Let's sit in the office when we are both in good health after sickness and decide something.
from babel-preset-firecloud.
🖖 i definitely don't want anyone to spend time like this
We settle it tmrw, even if we have a remote session
from babel-preset-firecloud.
I have now read your comment in peace. Let's just say bye-bye to this coverage crap, I say, but we talk tmrw.
from babel-preset-firecloud.
closing as it's a istanbul coverage issue
from babel-preset-firecloud.
Related Issues (8)
- maybe enable babel-plugin-firecloud-src-arg by default
- support __filename in src-arg plugin HOT 1
- consider auto-await HOT 6
- investigate using @babel/[email protected] HOT 1
- babel-plugin-firecloud-export-all and sourcemaps don't play well in chrome HOT 1
- consistent exports/underscore-private HOT 1
- export-all should not mark `export` variables that have 'require' call in right-hand-value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-preset-firecloud.