Giter Club home page Giter Club logo

Comments (6)

andreineculau avatar andreineculau commented on August 22, 2024

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.

andreineculau avatar andreineculau commented on August 22, 2024

I understand only partially what you're experiencing

Footnotes:

  1. 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

  2. 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.

IanSavchenko avatar IanSavchenko commented on August 22, 2024

Okay, so it went a bit deeper than I thought...
Will reply to your quotes first.

trigger https://github.com/facebook/jest/tree/6ee2a14b83393c9e3e3408beb5c4848489f04cf6/packages/babel-plugin-jest-hoist

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.

andreineculau avatar andreineculau commented on August 22, 2024

🖖 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.

andreineculau avatar andreineculau commented on August 22, 2024

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.

andreineculau avatar andreineculau commented on August 22, 2024

closing as it's a istanbul coverage issue

from babel-preset-firecloud.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.