diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 88b75796e1902..cf4a92839e98e 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -1,12 +1,12 @@ import { stripIndents } from '@angular-devkit/core/src/utils/literals'; import { + cleanupProject, + expectJestTestsToPass, newProject, runCLI, runCLIAsync, uniq, updateFile, - expectJestTestsToPass, - cleanupProject, } from '@nx/e2e/utils'; describe('Jest', () => { @@ -20,6 +20,21 @@ describe('Jest', () => { await expectJestTestsToPass('@nx/js:lib --unitTestRunner=jest'); }, 500000); + it('should be resilient against NODE_ENV values', async () => { + const name = uniq('lib'); + runCLI( + `generate @nx/js:lib ${name} --unitTestRunner=jest --no-interactive` + ); + + const results = await runCLIAsync(`test ${name}`, { + env: { + ...process.env, // need to set this for some reason, or else get "env: node: No such file or directory" + NODE_ENV: 'foobar', + }, + }); + expect(results.combinedOutput).toContain('Test Suites: 1 passed, 1 total'); + }); + it('should merge with jest config globals', async () => { const testGlobal = `'My Test Global'`; const mylib = uniq('mylib'); diff --git a/packages/js/babel.ts b/packages/js/babel.ts index 4841bd04e5273..043056005c168 100644 --- a/packages/js/babel.ts +++ b/packages/js/babel.ts @@ -52,7 +52,7 @@ module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) { // For Jest tests, NODE_ENV is set as 'test' and we only want to set target as Node. // All other options will fail in Jest since Node does not support some ES features // such as import syntax. - isTest || process.env.NODE_ENV === 'test' + isTest || process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID ? { targets: { node: 'current' }, loose: true } : { // Allow importing core-js in entrypoint and use browserslist to select polyfills.