Jest not picking up configs in multi project mode











up vote
8
down vote

favorite
2












We recently migrated two different repos into a monorepo. Each uses jest with its own custom configurations, defined in their own package.json files.



I'd like to use the --projects flag to run Jest across both projects from the root of the monorepo. I've added a jest.config.js file to the root of the monorepo:



module.exports = {
projects: ['<rootDir>/projectA', '<rootDir>/projectB']
};


The runner successfully picks up the tests for both projects, but it doesn't appear to be using each project's custom configuration. For example, in "projectA", I'm using babel-plugin-module-resolver. When I run jest in that project alone, babel-jest successfully picks up that plugin and it works fine, but when I run it from the root in multi-project mode, I get "Cannot find module..." errors that indicate the plugin isn't being used.



Similarly, in "projectB" I'm using a custom setupTestFrameworkScriptFile. Running jest in this project runs that file just fine, but it's ignored when running from the root.



My understanding of the multi-project mode was that each individual project should keep its own settings/configs intact. Did I miss something? Do I need to configure these in the root as well?










share|improve this question
























  • Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
    – Kenrick
    Nov 21 '17 at 4:05










  • React is not using projects anymore
    – Sibelius Seraphini
    Nov 15 at 1:10















up vote
8
down vote

favorite
2












We recently migrated two different repos into a monorepo. Each uses jest with its own custom configurations, defined in their own package.json files.



I'd like to use the --projects flag to run Jest across both projects from the root of the monorepo. I've added a jest.config.js file to the root of the monorepo:



module.exports = {
projects: ['<rootDir>/projectA', '<rootDir>/projectB']
};


The runner successfully picks up the tests for both projects, but it doesn't appear to be using each project's custom configuration. For example, in "projectA", I'm using babel-plugin-module-resolver. When I run jest in that project alone, babel-jest successfully picks up that plugin and it works fine, but when I run it from the root in multi-project mode, I get "Cannot find module..." errors that indicate the plugin isn't being used.



Similarly, in "projectB" I'm using a custom setupTestFrameworkScriptFile. Running jest in this project runs that file just fine, but it's ignored when running from the root.



My understanding of the multi-project mode was that each individual project should keep its own settings/configs intact. Did I miss something? Do I need to configure these in the root as well?










share|improve this question
























  • Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
    – Kenrick
    Nov 21 '17 at 4:05










  • React is not using projects anymore
    – Sibelius Seraphini
    Nov 15 at 1:10













up vote
8
down vote

favorite
2









up vote
8
down vote

favorite
2






2





We recently migrated two different repos into a monorepo. Each uses jest with its own custom configurations, defined in their own package.json files.



I'd like to use the --projects flag to run Jest across both projects from the root of the monorepo. I've added a jest.config.js file to the root of the monorepo:



module.exports = {
projects: ['<rootDir>/projectA', '<rootDir>/projectB']
};


The runner successfully picks up the tests for both projects, but it doesn't appear to be using each project's custom configuration. For example, in "projectA", I'm using babel-plugin-module-resolver. When I run jest in that project alone, babel-jest successfully picks up that plugin and it works fine, but when I run it from the root in multi-project mode, I get "Cannot find module..." errors that indicate the plugin isn't being used.



Similarly, in "projectB" I'm using a custom setupTestFrameworkScriptFile. Running jest in this project runs that file just fine, but it's ignored when running from the root.



My understanding of the multi-project mode was that each individual project should keep its own settings/configs intact. Did I miss something? Do I need to configure these in the root as well?










share|improve this question















We recently migrated two different repos into a monorepo. Each uses jest with its own custom configurations, defined in their own package.json files.



I'd like to use the --projects flag to run Jest across both projects from the root of the monorepo. I've added a jest.config.js file to the root of the monorepo:



module.exports = {
projects: ['<rootDir>/projectA', '<rootDir>/projectB']
};


The runner successfully picks up the tests for both projects, but it doesn't appear to be using each project's custom configuration. For example, in "projectA", I'm using babel-plugin-module-resolver. When I run jest in that project alone, babel-jest successfully picks up that plugin and it works fine, but when I run it from the root in multi-project mode, I get "Cannot find module..." errors that indicate the plugin isn't being used.



Similarly, in "projectB" I'm using a custom setupTestFrameworkScriptFile. Running jest in this project runs that file just fine, but it's ignored when running from the root.



My understanding of the multi-project mode was that each individual project should keep its own settings/configs intact. Did I miss something? Do I need to configure these in the root as well?







jestjs babel-jest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 '17 at 5:22









Kenrick

312213




312213










asked Oct 9 '17 at 18:32









kgoggin

649




649












  • Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
    – Kenrick
    Nov 21 '17 at 4:05










  • React is not using projects anymore
    – Sibelius Seraphini
    Nov 15 at 1:10


















  • Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
    – Kenrick
    Nov 21 '17 at 4:05










  • React is not using projects anymore
    – Sibelius Seraphini
    Nov 15 at 1:10
















Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
– Kenrick
Nov 21 '17 at 4:05




Looking at how React does it, looks like they pointed the "projects" straight to the project's config file: github.com/facebook/react/pull/10214/…
– Kenrick
Nov 21 '17 at 4:05












React is not using projects anymore
– Sibelius Seraphini
Nov 15 at 1:10




React is not using projects anymore
– Sibelius Seraphini
Nov 15 at 1:10












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I think there are some bugs with jest multi project runner, we need to provide some failing examples so jest can fix it. There are almost no docs about it



I made this work providing custom babel-transformer instead of using babel-jest directly.



Check this link https://twitter.com/sseraphini/status/1061779382669316098



Use this for your transformer inside packages



const config = require('../shared/babel.config.js');

const { createTransformer } = require('babel-jest');
module.exports = createTransformer({
...config,
});


and use this for your root transfomer



const { join, resolve } = require('path');
const { createTransformer } = require('babel-jest');
const packagePath = resolve('../');

const packageGlob = join(packagePath, '*');
module.exports = createTransformer({
babelrcRoots: packageGlob,
});


use like this on jest.config.js



transform: {
'^.+\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
},





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46652873%2fjest-not-picking-up-configs-in-multi-project-mode%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I think there are some bugs with jest multi project runner, we need to provide some failing examples so jest can fix it. There are almost no docs about it



    I made this work providing custom babel-transformer instead of using babel-jest directly.



    Check this link https://twitter.com/sseraphini/status/1061779382669316098



    Use this for your transformer inside packages



    const config = require('../shared/babel.config.js');

    const { createTransformer } = require('babel-jest');
    module.exports = createTransformer({
    ...config,
    });


    and use this for your root transfomer



    const { join, resolve } = require('path');
    const { createTransformer } = require('babel-jest');
    const packagePath = resolve('../');

    const packageGlob = join(packagePath, '*');
    module.exports = createTransformer({
    babelrcRoots: packageGlob,
    });


    use like this on jest.config.js



    transform: {
    '^.+\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
    },





    share|improve this answer

























      up vote
      0
      down vote













      I think there are some bugs with jest multi project runner, we need to provide some failing examples so jest can fix it. There are almost no docs about it



      I made this work providing custom babel-transformer instead of using babel-jest directly.



      Check this link https://twitter.com/sseraphini/status/1061779382669316098



      Use this for your transformer inside packages



      const config = require('../shared/babel.config.js');

      const { createTransformer } = require('babel-jest');
      module.exports = createTransformer({
      ...config,
      });


      and use this for your root transfomer



      const { join, resolve } = require('path');
      const { createTransformer } = require('babel-jest');
      const packagePath = resolve('../');

      const packageGlob = join(packagePath, '*');
      module.exports = createTransformer({
      babelrcRoots: packageGlob,
      });


      use like this on jest.config.js



      transform: {
      '^.+\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
      },





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I think there are some bugs with jest multi project runner, we need to provide some failing examples so jest can fix it. There are almost no docs about it



        I made this work providing custom babel-transformer instead of using babel-jest directly.



        Check this link https://twitter.com/sseraphini/status/1061779382669316098



        Use this for your transformer inside packages



        const config = require('../shared/babel.config.js');

        const { createTransformer } = require('babel-jest');
        module.exports = createTransformer({
        ...config,
        });


        and use this for your root transfomer



        const { join, resolve } = require('path');
        const { createTransformer } = require('babel-jest');
        const packagePath = resolve('../');

        const packageGlob = join(packagePath, '*');
        module.exports = createTransformer({
        babelrcRoots: packageGlob,
        });


        use like this on jest.config.js



        transform: {
        '^.+\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
        },





        share|improve this answer












        I think there are some bugs with jest multi project runner, we need to provide some failing examples so jest can fix it. There are almost no docs about it



        I made this work providing custom babel-transformer instead of using babel-jest directly.



        Check this link https://twitter.com/sseraphini/status/1061779382669316098



        Use this for your transformer inside packages



        const config = require('../shared/babel.config.js');

        const { createTransformer } = require('babel-jest');
        module.exports = createTransformer({
        ...config,
        });


        and use this for your root transfomer



        const { join, resolve } = require('path');
        const { createTransformer } = require('babel-jest');
        const packagePath = resolve('../');

        const packageGlob = join(packagePath, '*');
        module.exports = createTransformer({
        babelrcRoots: packageGlob,
        });


        use like this on jest.config.js



        transform: {
        '^.+\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
        },






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 13:52









        Sibelius Seraphini

        1,57421944




        1,57421944






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46652873%2fjest-not-picking-up-configs-in-multi-project-mode%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma