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 doesn't transpile test file in monorepo. #6835

Closed
ulivz opened this issue Aug 13, 2018 · 5 comments
Closed

Jest doesn't transpile test file in monorepo. #6835

ulivz opened this issue Aug 13, 2018 · 5 comments

Comments

@ulivz
Copy link

ulivz commented Aug 13, 2018

🐛 Bug Report

Recently I'm working on migrating my project to monorepo. but after I set up the monorepo, all the tests failed.

The first issue it that the test files in packages will not be transpiled by babel-jest. so I will get this error:

Click here to see the output log.
yarn run v1.7.0
$ NODE_ENV=test jest --config jest.config.js packages/a/a.spec.js
 FAIL  packages/a/a.spec.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/ulivz/Documents/ULIVZ/__forked__/jest-issue/packages/a/a.spec.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { APP } from './module';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)


After some investigation, and checked out the related issues: #2081, #3202, etc, I found my issue should be caused by monorepo.

To Reproduce

I create a minimal reproduction repo for that: https://github.com/ulivz/jest-6835

git clone https://github.com/ulivz/jest-issue.git
cd jest-issue
yarn
yarn test-1 # test in root dir passed
yarn test-2 # test tests in `packages` failed

All the detailed output has been included in the repo's readme.

Expected behavior

The test files in packages should be transpiled

Link to repl or repo (highly encouraged)

https://github.com/ulivz/jest-6835

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 8.11.3 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.0.0 => 23.5.0
@ulivz ulivz changed the title Jest doesn't transpile import in monorepo. Jest doesn't transpile test file in monorepo. Aug 13, 2018
@SimenB
Copy link
Member

SimenB commented Aug 15, 2018

I haven't tested, but this seems like #6053 (comment)

Could you confirm if that fixes it or not?

@ranyitz
Copy link
Contributor

ranyitz commented Aug 15, 2018

As @SimenB suggested, replacing .babelrc with a babel.config.js fixes it.

@SimenB
Copy link
Member

SimenB commented Aug 15, 2018

Awesome! Closing then 🙂

@SimenB SimenB closed this as completed Aug 15, 2018
ulivz added a commit to vuejs/vuepress that referenced this issue Aug 26, 2018
@ulivz
Copy link
Author

ulivz commented Aug 26, 2018

Thanks, it works for me.

shaun554 added a commit to shaun554/vuepress that referenced this issue Mar 21, 2019
devs-cloud pushed a commit to devs-cloud/vue-dev that referenced this issue Dec 27, 2019
@github-actions
Copy link

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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants