diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 981f75faacd071..395af4348533db 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -97,4 +97,16 @@ describe('Jest', () => { ); // text expect(result.stdout).toContain('Coverage summary'); // text-summary }, 90000); + + it('should be able to test node lib with babel-jest', async () => { + const libName = uniq('babel-test-lib'); + runCLI( + `generate @nrwl/node:lib ${libName} --buildable --importPath=@some-org/babel-test --publishable --babelJest` + ); + + const cliResults = await runCLIAsync(`test ${libName}`); + expect(cliResults.combinedOutput).toContain( + 'Test Suites: 1 passed, 1 total' + ); + }); }); diff --git a/packages/jest/src/generators/jest-project/jest-project.spec.ts b/packages/jest/src/generators/jest-project/jest-project.spec.ts index e0aec2052ec5c7..2ca08441815ab8 100644 --- a/packages/jest/src/generators/jest-project/jest-project.spec.ts +++ b/packages/jest/src/generators/jest-project/jest-project.spec.ts @@ -55,6 +55,15 @@ describe('jestProject', () => { expect(tree.exists('libs/lib1/tsconfig.spec.json')).toBeTruthy(); }); + it('should generate files w/babel-jest', async () => { + await jestProjectGenerator(tree, { + ...defaultOptions, + project: 'lib1', + babelJest: true, + } as JestProjectSchema); + expect(tree.exists('babel.config.json')).toBeTruthy(); + }); + it('should alter workspace.json', async () => { await jestProjectGenerator(tree, { ...defaultOptions, diff --git a/packages/jest/src/generators/jest-project/lib/create-files.ts b/packages/jest/src/generators/jest-project/lib/create-files.ts index b432153985ff9f..f0151fe4d46da9 100644 --- a/packages/jest/src/generators/jest-project/lib/create-files.ts +++ b/packages/jest/src/generators/jest-project/lib/create-files.ts @@ -4,6 +4,7 @@ import { offsetFromRoot, generateFiles, readProjectConfiguration, + stripIndents, } from '@nrwl/devkit'; import { join } from 'path'; @@ -24,4 +25,13 @@ export function createFiles(tree: Tree, options: JestProjectSchema) { if (options.setupFile === 'none') { tree.delete(join(projectConfig.root, './src/test-setup.ts')); } + + if (options.babelJest && !tree.exists('babel.config.json')) { + tree.write( + 'babel.config.json', + JSON.stringify({ + babelrcRoots: ['*'], + }) + ); + } }