Skip to content
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 transpile code correctly when it's not runed manually. #7212

Closed
EmilNordling opened this issue Oct 18, 2018 · 8 comments
Closed

Comments

@EmilNordling
Copy link

🐛 Bug Report

Hello!

My set up is Babel 7 with TypeScript and the jest.config's transform property is set to babel-jest. The reason why I'm not using ts-jest is because I want to transpile the code with Babel so I can use the preval plugin.

This works great when I when I manually runs yarn test, it'll transpile the code according to the .babelrc config and run the tests without any errors or failures. The problem arrived when yarn test isn't runed by me directly.

I have a git hook with Husky to have it run yarn test with the pre-commit hook. What happens is whenever a commit happends, it'll run yarn test and Jest will fail to transpile the code. The output logs will be filled with Jest encountered an unexpected token, and it seems like Jest ignores the Babel config entirely when the command isn't executed directly by me.

It also seems to be a connection to this and the errors I get when the VS Code Extention vscode-jest is being runed in the background.

They do not interfere with each other, tried without the plugin and the same issue is still present.

To Reproduce

I've provided a repo that have this set up and issues.

For the git hook:

  1. Make a change.
  2. Try to commit it.
  3. Will fail and in the Jest outputs there will be transpile errors.

For vscode-jest extention:

  1. Install the extention.
  2. Won't work correctly and the Jest outputs will have the same transpile errors as the git hook.

Expected behavior

Since it works with me manually running yarn test and it'll transpile and tests correctly, the other cases should do that aswell, i.e. anything else than me running the jest command.

Link to repl or repo (highly encouraged)

Link to the repo

Run npx envinfo --preset jest

Paste the results here:

 System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz
    Memory: 363.67 MB / 4.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.11.0 - /usr/local/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.19.0 - /usr/local/bin/git
  Servers:
    Apache: 2.4.33 - /usr/sbin/apachectl
  IDEs:
    Emacs: 22.1.1 - /usr/bin/emacs
    Nano: 2.0.6 - /usr/bin/nano
    Vim: 8.0 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Perl: 5.18.2 - /usr/bin/perl
    PHP: 7.1.16 - /usr/bin/php
    Python: 2.7.10 - /usr/bin/python
    Ruby: 2.3.7 - /usr/bin/ruby
  Databases:
    SQLite: 3.19.3 - /usr/bin/sqlite3
  Browsers:
    Chrome: 69.0.3497.100
    Firefox: 62.0.3
    Safari: 12.0
@SimenB
Copy link
Member

SimenB commented Oct 18, 2018

I cannot reproduce this. I'm also on mac...

image

(btw, when using jest in a commit hook a good idea might be to use something like lint-staged and findRelatedTests to only run the changed tests, see https://jestjs.io/docs/en/cli.html#findrelatedtests-spaceseparatedlistofsourcefiles)

@EmilNordling
Copy link
Author

This is my bad, the info I provided is wrong. Wrote this on my mac at home and didn't double check the output error - just figure it was the same. I does work perfectly on mac.

We're using Windows at work, here's an updated envinfo.

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
    Memory: 1.54 GB / 7.90 GB
  Binaries:
    Yarn: 1.10.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.28.1 - C:\Program Files\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 4.4.12 - C:\Program Files\Git\usr\bin\bash.EXE
    Perl: 5.24.1 - C:\Program Files\Git\usr\bin\perl.EXE
  Browsers:
    Edge: 42.17134.1.0
    Internet Explorer: 11.0.17134.1

  It didn't include all, here's node and git:
    node: v10.12.0
    git version 2.15.1.windows.2

I took some screenshots of what happens when I commit.
image

Output git logs.
image
image

When I run yarn test
image

Will also look into lint-staged and using the findRelatedTests flag, good tip 👍

@clenemt
Copy link

clenemt commented Nov 7, 2018

Just to add my two cents.

Have the same problem when running from msysgit. Run fine when using cmd which is a bummer but probably not related to jest or babel-jest at all.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@sasjafor
Copy link

sasjafor commented Mar 4, 2022

I have the same problem on VSCode with WSL 2. I have a pre-push git hook setup to run npm test which uses jest.
It runs totally fine in the integrated VSCode terminal with the "git push" command, but when I try to use the VSCode source control feature I also get transpile errors.

As a note, I'm using ES6 modules for my code and have the following config option to make jest support the import statements:
"babel": { "env": { "test": { "plugins": [ "@babel/plugin-transform-modules-commonjs" ] } } },

@github-actions github-actions bot removed the Stale label Mar 4, 2022
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 4, 2023
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
@github-actions
Copy link

github-actions bot commented May 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants