diff --git a/e2e/angular-core/src/config.test.ts b/e2e/angular-core/src/config.test.ts index fd0524d25ae6c..e329353095cf6 100644 --- a/e2e/angular-core/src/config.test.ts +++ b/e2e/angular-core/src/config.test.ts @@ -152,7 +152,7 @@ const angularV1Json = (appName: string) => `{ "builder": "@nrwl/jest:jest", "outputs": ["coverage/apps/${appName}"], "options": { - "jestConfig": "apps/${appName}/jest.config.js", + "jestConfig": "apps/${appName}/jest.config.ts", "passWithNoTests": true } } diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 34ac3520830ba..3ed5352601554 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -75,7 +75,7 @@ describe('Jest', () => { ); updateFile( - `libs/${mylib}/jest.config.js`, + `libs/${mylib}/jest.config.ts`, stripIndents` module.exports = { testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index 3a7b36c86b545..8d511e1230874 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -356,12 +356,12 @@ describe('nest libraries', function () { const nestlib = uniq('nestlib'); runCLI(`generate @nrwl/nest:lib ${nestlib}`); - const jestConfigContent = readFile(`libs/${nestlib}/jest.config.js`); + const jestConfigContent = readFile(`libs/${nestlib}/jest.config.ts`); expect(stripIndents`${jestConfigContent}`).toEqual( stripIndents`module.exports = { displayName: '${nestlib}', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 02f2c2158ea41..99fd2f3d1bb33 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -803,7 +803,7 @@ export function expectNoAngularDevkit() { export function expectNoTsJestInJestConfig(appName: string) { const jestConfig = readFile( - joinPathFragments('apps', appName, 'jest.config.js') + joinPathFragments('apps', appName, 'jest.config.ts') ); expect(jestConfig).not.toContain('ts-jest'); } diff --git a/e2e/workspace-core/src/aux-commands.test.ts b/e2e/workspace-core/src/aux-commands.test.ts index 3cfcb39eb8c27..e0aa375097e48 100644 --- a/e2e/workspace-core/src/aux-commands.test.ts +++ b/e2e/workspace-core/src/aux-commands.test.ts @@ -186,7 +186,7 @@ describe('workspace-lint', () => { expect(stdout).toContain( 'The following file(s) do not belong to any projects:' ); - expect(stdout).toContain(`- apps/${appAfter}/jest.config.js`); + expect(stdout).toContain(`- apps/${appAfter}/jest.config.ts`); expect(stdout).toContain(`- apps/${appAfter}/src/app/app.component.css`); expect(stdout).toContain(`- apps/${appAfter}/src/app/app.component.html`); expect(stdout).toContain( @@ -257,12 +257,12 @@ describe('move project', () => { expect(moveOutput).toContain(`CREATE ${readmePath}`); checkFilesExist(readmePath); - const jestConfigPath = `${newPath}/jest.config.js`; + const jestConfigPath = `${newPath}/jest.config.ts`; expect(moveOutput).toContain(`CREATE ${jestConfigPath}`); checkFilesExist(jestConfigPath); const jestConfig = readFile(jestConfigPath); expect(jestConfig).toContain(`displayName: 'shared-${lib1}-data-access'`); - expect(jestConfig).toContain(`preset: '../../../../jest.preset.js'`); + expect(jestConfig).toContain(`preset: '../../../../jest.preset.ts'`); expect(jestConfig).toContain(`'../../../../coverage/${newPath}'`); const tsConfigPath = `${newPath}/tsconfig.json`; @@ -395,12 +395,12 @@ describe('move project', () => { expect(moveOutput).toContain(`CREATE ${readmePath}`); checkFilesExist(readmePath); - const jestConfigPath = `${newPath}/jest.config.js`; + const jestConfigPath = `${newPath}/jest.config.ts`; expect(moveOutput).toContain(`CREATE ${jestConfigPath}`); checkFilesExist(jestConfigPath); const jestConfig = readFile(jestConfigPath); expect(jestConfig).toContain(`displayName: 'shared-${lib1}-data-access'`); - expect(jestConfig).toContain(`preset: '../../../../jest.preset.js'`); + expect(jestConfig).toContain(`preset: '../../../../jest.preset.ts'`); expect(jestConfig).toContain(`'../../../../coverage/${newPath}'`); const tsConfigPath = `${newPath}/tsconfig.json`; @@ -528,12 +528,12 @@ describe('move project', () => { expect(moveOutput).toContain(`CREATE ${readmePath}`); checkFilesExist(readmePath); - const jestConfigPath = `${newPath}/jest.config.js`; + const jestConfigPath = `${newPath}/jest.config.ts`; expect(moveOutput).toContain(`CREATE ${jestConfigPath}`); checkFilesExist(jestConfigPath); const jestConfig = readFile(jestConfigPath); expect(jestConfig).toContain(`displayName: 'shared-${lib1}-data-access'`); - expect(jestConfig).toContain(`preset: '../../../../jest.preset.js'`); + expect(jestConfig).toContain(`preset: '../../../../jest.preset.ts'`); expect(jestConfig).toContain(`'../../../../coverage/${newPath}'`); const tsConfigPath = `${newPath}/tsconfig.json`; diff --git a/e2e/workspace-integrations/src/workspace-aux-commands.test.ts b/e2e/workspace-integrations/src/workspace-aux-commands.test.ts index 98e1173de26c0..d887106aa97b9 100644 --- a/e2e/workspace-integrations/src/workspace-aux-commands.test.ts +++ b/e2e/workspace-integrations/src/workspace-aux-commands.test.ts @@ -445,7 +445,7 @@ describe('Move Angular Project', () => { // just check the output expect(moveOutput).toContain(`DELETE apps/${app1}`); expect(moveOutput).toContain(`CREATE apps/${newPath}/.browserslistrc`); - expect(moveOutput).toContain(`CREATE apps/${newPath}/jest.config.js`); + expect(moveOutput).toContain(`CREATE apps/${newPath}/jest.config.ts`); expect(moveOutput).toContain(`CREATE apps/${newPath}/tsconfig.app.json`); expect(moveOutput).toContain(`CREATE apps/${newPath}/tsconfig.json`); expect(moveOutput).toContain(`CREATE apps/${newPath}/tsconfig.spec.json`); diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index 7444ec5af6240..52b48853c7825 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -112,7 +112,7 @@ Object { "test": Object { "builder": "@nrwl/jest:jest", "options": Object { - "jestConfig": "apps/my-dir/my-app/jest.config.js", + "jestConfig": "apps/my-dir/my-app/jest.config.ts", "passWithNoTests": true, }, "outputs": Array [ @@ -281,7 +281,7 @@ Object { "test": Object { "builder": "@nrwl/jest:jest", "options": Object { - "jestConfig": "apps/my-app/jest.config.js", + "jestConfig": "apps/my-app/jest.config.ts", "passWithNoTests": true, }, "outputs": Array [ diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index 94cb4ebcbaf67..d533f462f4562 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -70,7 +70,7 @@ describe('app', () => { it('should generate files', async () => { await generateApp(appTree); - expect(appTree.exists(`apps/my-app/jest.config.js`)).toBeTruthy(); + expect(appTree.exists(`apps/my-app/jest.config.ts`)).toBeTruthy(); expect(appTree.exists('apps/my-app/src/main.ts')).toBeTruthy(); expect(appTree.exists('apps/my-app/src/app/app.module.ts')).toBeTruthy(); expect( @@ -113,13 +113,13 @@ describe('app', () => { it('should setup jest with serializers', async () => { await generateApp(appTree); - expect(appTree.read('apps/my-app/jest.config.js', 'utf-8')).toContain( + expect(appTree.read('apps/my-app/jest.config.ts', 'utf-8')).toContain( `'jest-preset-angular/build/serializers/no-ng-attributes'` ); - expect(appTree.read('apps/my-app/jest.config.js', 'utf-8')).toContain( + expect(appTree.read('apps/my-app/jest.config.ts', 'utf-8')).toContain( `'jest-preset-angular/build/serializers/ng-snapshot'` ); - expect(appTree.read('apps/my-app/jest.config.js', 'utf-8')).toContain( + expect(appTree.read('apps/my-app/jest.config.ts', 'utf-8')).toContain( `'jest-preset-angular/build/serializers/html-comment'` ); }); @@ -249,7 +249,7 @@ describe('app', () => { // Make sure these exist [ - `apps/my-dir/my-app/jest.config.js`, + `apps/my-dir/my-app/jest.config.ts`, 'apps/my-dir/my-app/src/main.ts', 'apps/my-dir/my-app/src/app/app.module.ts', 'apps/my-dir/my-app/src/app/app.component.ts', @@ -332,7 +332,7 @@ describe('app', () => { // Make sure these exist [ - 'my-dir/my-app/jest.config.js', + 'my-dir/my-app/jest.config.ts', 'my-dir/my-app/src/main.ts', 'my-dir/my-app/src/app/app.module.ts', 'my-dir/my-app/src/app/app.component.ts', @@ -631,10 +631,10 @@ describe('app', () => { describe('--unit-test-runner', () => { describe('default (jest)', () => { - it('should generate jest.config.js with serializers', async () => { + it('should generate jest.config.ts with serializers', async () => { await generateApp(appTree); - const jestConfig = appTree.read('apps/my-app/jest.config.js', 'utf-8'); + const jestConfig = appTree.read('apps/my-app/jest.config.ts', 'utf-8'); expect(jestConfig).toContain( `'jest-preset-angular/build/serializers/no-ng-attributes'` @@ -678,7 +678,7 @@ describe('app', () => { expect(appTree.exists('apps/my-app/src/test-setup.ts')).toBeFalsy(); expect(appTree.exists('apps/my-app/src/test.ts')).toBeFalsy(); expect(appTree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy(); - expect(appTree.exists('apps/my-app/jest.config.js')).toBeFalsy(); + expect(appTree.exists('apps/my-app/jest.config.ts')).toBeFalsy(); expect(appTree.exists('apps/my-app/karma.config.js')).toBeFalsy(); expect( appTree.exists('apps/my-app/src/app/app.component.spec.ts') diff --git a/packages/angular/src/generators/init/init.spec.ts b/packages/angular/src/generators/init/init.spec.ts index 2c48ba965851e..cdaefe34ee29d 100644 --- a/packages/angular/src/generators/init/init.spec.ts +++ b/packages/angular/src/generators/init/init.spec.ts @@ -140,7 +140,7 @@ describe('init', () => { skipFormat: false, }); - const hasJestConfigFile = host.exists('jest.config.js'); + const hasJestConfigFile = host.exists('jest.config.ts'); // ASSERT expect(hasJestConfigFile).toBeTruthy(); diff --git a/packages/angular/src/generators/library/library.spec.ts b/packages/angular/src/generators/library/library.spec.ts index 02fadb3c12029..881a588b734a4 100644 --- a/packages/angular/src/generators/library/library.spec.ts +++ b/packages/angular/src/generators/library/library.spec.ts @@ -429,7 +429,7 @@ describe('lib', () => { await runLibraryGeneratorWithOpts({ name: 'my-lib2' }); // ASSERT - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.module.ts')).toBeTruthy(); @@ -444,7 +444,7 @@ describe('lib', () => { tree.exists('libs/my-lib/src/lib/my-lib.service.spec.ts') ).toBeFalsy(); - expect(tree.exists(`libs/my-lib2/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-lib2/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-lib2/src/index.ts')).toBeTruthy(); expect( tree.exists('libs/my-lib2/src/lib/my-lib2.module.ts') @@ -544,7 +544,7 @@ describe('lib', () => { }); // ASSERT - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts') @@ -563,7 +563,7 @@ describe('lib', () => { tree.exists('libs/my-dir/my-lib/src/lib/my-lib.service.spec.ts') ).toBeFalsy(); - expect(tree.exists(`libs/my-dir/my-lib2/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib2/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib2/src/index.ts')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib2/src/lib/my-lib2.module.ts') @@ -740,7 +740,7 @@ describe('lib', () => { // Make sure these exist [ 'my-dir/my-lib/.browserslistrc', - 'my-dir/my-lib/jest.config.js', + 'my-dir/my-lib/jest.config.ts', 'my-dir/my-lib/ng-package.json', 'my-dir/my-lib/project.json', 'my-dir/my-lib/tsconfig.lib.prod.json', @@ -1192,7 +1192,7 @@ describe('lib', () => { expect(tree.exists('libs/my-lib/src/test.ts')).toBeFalsy(); expect(tree.exists('libs/my-lib/src/test.ts')).toBeFalsy(); expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('libs/my-lib/jest.config.js')).toBeFalsy(); + expect(tree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); expect(tree.exists('libs/my-lib/karma.conf.js')).toBeFalsy(); expect(workspaceJson.projects['my-lib'].architect.test).toBeUndefined(); }); diff --git a/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap b/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap index 882b4394d9a35..e17bfa9471c28 100644 --- a/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap +++ b/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap @@ -54,13 +54,13 @@ Array [ "apps/one/two/test-ui-lib-e2e/src/support/commands.ts", "apps/one/two/test-ui-lib-e2e/src/support/index.ts", "apps/one/two/test-ui-lib-e2e/tsconfig.json", - "jest.config.js", - "jest.preset.js", + "jest.config.ts", + "jest.preset.ts", "libs/test-ui-lib/.eslintrc.json", "libs/test-ui-lib/.storybook/main.js", "libs/test-ui-lib/.storybook/preview.js", "libs/test-ui-lib/.storybook/tsconfig.json", - "libs/test-ui-lib/jest.config.js", + "libs/test-ui-lib/jest.config.ts", "libs/test-ui-lib/README.md", "libs/test-ui-lib/src/index.ts", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.css", @@ -159,13 +159,13 @@ Array [ "apps/test-ui-lib-e2e/src/support/commands.ts", "apps/test-ui-lib-e2e/src/support/index.ts", "apps/test-ui-lib-e2e/tsconfig.json", - "jest.config.js", - "jest.preset.js", + "jest.config.ts", + "jest.preset.ts", "libs/test-ui-lib/.eslintrc.json", "libs/test-ui-lib/.storybook/main.js", "libs/test-ui-lib/.storybook/preview.js", "libs/test-ui-lib/.storybook/tsconfig.json", - "libs/test-ui-lib/jest.config.js", + "libs/test-ui-lib/jest.config.ts", "libs/test-ui-lib/README.md", "libs/test-ui-lib/src/index.ts", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.css", diff --git a/packages/express/src/generators/application/application.spec.ts b/packages/express/src/generators/application/application.spec.ts index 620a4e62051f0..253363078ec0a 100644 --- a/packages/express/src/generators/application/application.spec.ts +++ b/packages/express/src/generators/application/application.spec.ts @@ -90,6 +90,7 @@ Object { ], }, "exclude": Array [ + "jest.config.ts", "**/*.spec.ts", "**/*.test.ts", ], @@ -124,6 +125,7 @@ Object { ); expect(tsConfigApp.include).toEqual(['**/*.ts', '**/*.js']); expect(tsConfigApp.exclude).toEqual([ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.js', diff --git a/packages/jest/src/executors/jest/jest.impl.spec.ts b/packages/jest/src/executors/jest/jest.impl.spec.ts index 241903746fed0..7af56a71f2834 100644 --- a/packages/jest/src/executors/jest/jest.impl.spec.ts +++ b/packages/jest/src/executors/jest/jest.impl.spec.ts @@ -70,7 +70,7 @@ describe('Jest Executor', () => { describe('when the jest config file is untouched', () => { beforeEach(() => { jest.mock( - '/root/jest.config.js', + '/root/jest.config.ts', () => ({ transform: {}, }), @@ -82,7 +82,7 @@ describe('Jest Executor', () => { await jestExecutor( { ...defaultOptions, - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', watch: false, }, mockContext @@ -93,7 +93,7 @@ describe('Jest Executor', () => { testPathPattern: [], watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); @@ -123,7 +123,7 @@ describe('Jest Executor', () => { await jestExecutor( { testFile: 'lib.spec.ts', - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', codeCoverage: false, runInBand: true, testNamePattern: 'should load', @@ -152,7 +152,7 @@ describe('Jest Executor', () => { coverageDirectory: '/root/test/coverage', watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); @@ -161,7 +161,7 @@ describe('Jest Executor', () => { { ...defaultOptions, findRelatedTests: 'file1.ts,file2.ts', - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', codeCoverage: false, runInBand: true, testNamePattern: 'should load', @@ -180,14 +180,14 @@ describe('Jest Executor', () => { testPathPattern: [], watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); it('should send other options to jestCLI', async () => { await jestExecutor( { - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', codeCoverage: true, bail: 1, color: false, @@ -251,7 +251,7 @@ describe('Jest Executor', () => { watchAll: false, testLocationInResults: true, }, - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); @@ -259,7 +259,7 @@ describe('Jest Executor', () => { await jestExecutor( { ...defaultOptions, - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', maxWorkers: '50%', }, mockContext @@ -270,7 +270,7 @@ describe('Jest Executor', () => { maxWorkers: '50%', testPathPattern: [], }, - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); @@ -278,7 +278,7 @@ describe('Jest Executor', () => { await jestExecutor( { ...defaultOptions, - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', setupFile: './test-setup.ts', watch: false, }, @@ -291,14 +291,14 @@ describe('Jest Executor', () => { testPathPattern: [], watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); describe('when the jest config file has been modified', () => { beforeAll(() => { jest.doMock( - '/root/jest.config.js', + '/root/jest.config.ts', () => ({ transform: { '^.+\\.[tj]sx?$': 'ts-jest', @@ -313,7 +313,7 @@ describe('Jest Executor', () => { await jestExecutor( { ...defaultOptions, - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', setupFile: './test-setup.ts', watch: false, }, @@ -327,7 +327,7 @@ describe('Jest Executor', () => { testPathPattern: [], watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); }); @@ -335,7 +335,7 @@ describe('Jest Executor', () => { describe('when we use babel-jest', () => { beforeEach(() => { jest.doMock( - '/root/jest.config.js', + '/root/jest.config.ts', () => ({ transform: { '^.+\\.[tj]sx?$': 'babel-jest', @@ -348,7 +348,7 @@ describe('Jest Executor', () => { it('should send appropriate options to jestCLI', async () => { const options: JestExecutorOptions = { ...defaultOptions, - jestConfig: './jest.config.js', + jestConfig: './jest.config.ts', watch: false, }; @@ -359,7 +359,7 @@ describe('Jest Executor', () => { testPathPattern: [], watch: false, }), - ['/root/jest.config.js'] + ['/root/jest.config.ts'] ); }); }); diff --git a/packages/jest/src/generators/init/init.spec.ts b/packages/jest/src/generators/init/init.spec.ts index 93f43b0be174d..1a7c760301c76 100644 --- a/packages/jest/src/generators/init/init.spec.ts +++ b/packages/jest/src/generators/init/init.spec.ts @@ -12,8 +12,8 @@ describe('jest', () => { it('should generate files', async () => { jestInitGenerator(tree, {}); - expect(tree.exists('jest.config.js')).toBeTruthy(); - expect(tree.read('jest.config.js', 'utf-8')).toMatchInlineSnapshot(` + expect(tree.exists('jest.config.ts')).toBeTruthy(); + expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot(` "const { getJestProjects } = require('@nrwl/jest'); module.exports = { @@ -23,9 +23,9 @@ describe('jest', () => { }); it('should not override existing files', async () => { - tree.write('jest.config.js', `test`); + tree.write('jest.config.ts', `test`); jestInitGenerator(tree, {}); - expect(tree.read('jest.config.js', 'utf-8')).toEqual('test'); + expect(tree.read('jest.config.ts', 'utf-8')).toEqual('test'); }); it('should add dependencies', async () => { diff --git a/packages/jest/src/generators/jest-project/__snapshots__/jest-project.spec.ts.snap b/packages/jest/src/generators/jest-project/__snapshots__/jest-project.spec.ts.snap index f0c8ff522bbd4..f14c67e9be05b 100644 --- a/packages/jest/src/generators/jest-project/__snapshots__/jest-project.spec.ts.snap +++ b/packages/jest/src/generators/jest-project/__snapshots__/jest-project.spec.ts.snap @@ -3,7 +3,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when --compiler=swc and supportTsx is true 1`] = ` "module.exports = { displayName: 'lib1', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', transform: { '^.+\\\\\\\\.[tj]sx?$': ['@swc/jest', { jsc: { transform: { react: { runtime: 'automatic' } } } }] }, @@ -16,7 +16,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when --co exports[`jestProject --babelJest should generate proper jest.transform when babelJest and supportTsx is true 1`] = ` "module.exports = { displayName: 'lib1', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', transform: { '^.+\\\\\\\\.[tj]sx?$': 'babel-jest' }, @@ -29,7 +29,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe exports[`jestProject --babelJest should generate proper jest.transform when babelJest is true 1`] = ` "module.exports = { displayName: 'lib1', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', transform: { '^.+\\\\\\\\.[tj]s$': 'babel-jest' }, @@ -42,7 +42,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe exports[`jestProject --setup-file should have setupFilesAfterEnv and globals.ts-jest in the jest.config when generated for angular 1`] = ` "module.exports = { displayName: 'lib1', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', setupFilesAfterEnv: ['/src/test-setup.ts'], globals: { 'ts-jest': { @@ -67,7 +67,7 @@ exports[`jestProject --setup-file should have setupFilesAfterEnv and globals.ts- exports[`jestProject should create a jest.config.ts 1`] = ` "module.exports = { displayName: 'lib1', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', 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 84a96499dbb2b..bc79b33f98627 100644 --- a/packages/jest/src/generators/jest-project/jest-project.spec.ts +++ b/packages/jest/src/generators/jest-project/jest-project.spec.ts @@ -51,7 +51,7 @@ describe('jestProject', () => { setupFile: 'angular', } as JestProjectSchema); expect(tree.exists('libs/lib1/src/test-setup.ts')).toBeTruthy(); - expect(tree.exists('libs/lib1/jest.config.js')).toBeTruthy(); + expect(tree.exists('libs/lib1/jest.config.ts')).toBeTruthy(); expect(tree.exists('libs/lib1/tsconfig.spec.json')).toBeTruthy(); }); @@ -75,7 +75,7 @@ describe('jestProject', () => { executor: '@nrwl/jest:jest', outputs: ['coverage/libs/lib1'], options: { - jestConfig: 'libs/lib1/jest.config.js', + jestConfig: 'libs/lib1/jest.config.ts', passWithNoTests: true, }, }); @@ -84,12 +84,12 @@ describe('jestProject', () => { ); }); - it('should create a jest.config.js', async () => { + it('should create a jest.config.ts', async () => { await jestProjectGenerator(tree, { ...defaultOptions, project: 'lib1', } as JestProjectSchema); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toMatchSnapshot(); + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot(); }); it('should add a reference to solution tsconfig.json', async () => { @@ -129,7 +129,7 @@ describe('jestProject', () => { project: 'lib1', } as JestProjectSchema); expect(tree.exists('src/test-setup.ts')).toBeFalsy(); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).not.toContain( + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).not.toContain( `setupFilesAfterEnv: ['/src/test-setup.ts'],` ); }); @@ -140,7 +140,7 @@ describe('jestProject', () => { project: 'lib1', setupFile: 'web-components', } as JestProjectSchema); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toContain( + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toContain( `setupFilesAfterEnv: ['/src/test-setup.ts'],` ); }); @@ -152,7 +152,7 @@ describe('jestProject', () => { setupFile: 'angular', } as JestProjectSchema); - const jestConfig = tree.read('libs/lib1/jest.config.js', 'utf-8'); + const jestConfig = tree.read('libs/lib1/jest.config.ts', 'utf-8'); expect(jestConfig).toContain( `setupFilesAfterEnv: ['/src/test-setup.ts'],` ); @@ -212,13 +212,13 @@ describe('jestProject', () => { }); describe('--skip-serializers', () => { - it('should not list the serializers in jest.config.js', async () => { + it('should not list the serializers in jest.config.ts', async () => { await jestProjectGenerator(tree, { ...defaultOptions, project: 'lib1', skipSerializers: true, } as JestProjectSchema); - const jestConfig = tree.read('libs/lib1/jest.config.js', 'utf-8'); + const jestConfig = tree.read('libs/lib1/jest.config.ts', 'utf-8'); expect(jestConfig).not.toContain(` snapshotSerializers: [ 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js, @@ -236,7 +236,7 @@ describe('jestProject', () => { project: 'lib1', supportTsx: true, } as JestProjectSchema); - const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.js'); + const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.ts'); expect(jestConfig.transform).toEqual({ '^.+\\.[tj]sx?$': 'ts-jest', }); @@ -248,7 +248,7 @@ describe('jestProject', () => { project: 'lib1', supportTsx: true, } as JestProjectSchema); - const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.js'); + const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.ts'); expect(jestConfig.moduleFileExtensions).toEqual([ 'ts', 'tsx', @@ -265,7 +265,7 @@ describe('jestProject', () => { project: 'lib1', babelJest: false, } as JestProjectSchema); - const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.js'); + const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.ts'); expect(jestConfig.globals).toEqual({ 'ts-jest': { @@ -280,14 +280,14 @@ describe('jestProject', () => { project: 'lib1', babelJest: true, } as JestProjectSchema); - const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.js'); + const jestConfig = jestConfigObject(tree, 'libs/lib1/jest.config.ts'); expect(jestConfig.globals).not.toEqual({ 'ts-jest': { tsConfig: '/tsconfig.spec.json', }, }); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toMatchSnapshot(); + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot(); }); it('should generate proper jest.transform when babelJest and supportTsx is true', async () => { @@ -297,7 +297,7 @@ describe('jestProject', () => { babelJest: true, supportTsx: true, } as JestProjectSchema); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toMatchSnapshot(); + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot(); }); it('should generate proper jest.transform when --compiler=swc and supportTsx is true', async () => { @@ -307,7 +307,7 @@ describe('jestProject', () => { compiler: 'swc', supportTsx: true, } as JestProjectSchema); - expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toMatchSnapshot(); + expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot(); }); }); }); diff --git a/packages/js/src/generators/library/library.spec.ts b/packages/js/src/generators/library/library.spec.ts index 1c2d4337b31ea..34f8af52e7086 100644 --- a/packages/js/src/generators/library/library.spec.ts +++ b/packages/js/src/generators/library/library.spec.ts @@ -211,7 +211,7 @@ describe('lib', () => { name: 'myLib', directory: 'myDir', }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.ts') @@ -570,7 +570,7 @@ describe('lib', () => { name: 'myLib', js: true, }); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.js')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.js')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.js')).toBeTruthy(); @@ -617,7 +617,7 @@ describe('lib', () => { directory: 'myDir', js: true, }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.js') @@ -688,18 +688,18 @@ describe('lib', () => { }); expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeTruthy(); - expect(tree.exists('libs/my-lib/jest.config.js')).toBeTruthy(); + expect(tree.exists('libs/my-lib/jest.config.ts')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeTruthy(); const projectConfig = readProjectConfiguration(tree, 'my-lib'); expect(projectConfig.targets.test).toBeDefined(); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); - expect(tree.read(`libs/my-lib/jest.config.js`, 'utf-8')) + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); + expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', @@ -779,7 +779,7 @@ describe('lib', () => { compiler: 'swc', }); - const jestConfig = tree.read('libs/my-lib/jest.config.js').toString(); + const jestConfig = tree.read('libs/my-lib/jest.config.ts').toString(); expect(jestConfig).toContain('@swc/jest'); }); diff --git a/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap b/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap index c32b52734d3fc..dbd56e68bf316 100644 --- a/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap +++ b/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap @@ -24,6 +24,7 @@ exports[`Update .lib.swcrc exclude should update the exclude pattern 1`] = ` }, \\"sourceMaps\\": true, \\"exclude\\": [ + \\"jest.config.ts\\", \\".*.spec.tsx?$\\", \\".*.test.tsx?$\\", \\"./src/jest-setup.ts$\\", diff --git a/packages/linter/src/generators/workspace-rules-project/__snapshots__/workspace-rules-project.spec.ts.snap b/packages/linter/src/generators/workspace-rules-project/__snapshots__/workspace-rules-project.spec.ts.snap index 0c29a557489a6..ba1df99284bf7 100644 --- a/packages/linter/src/generators/workspace-rules-project/__snapshots__/workspace-rules-project.spec.ts.snap +++ b/packages/linter/src/generators/workspace-rules-project/__snapshots__/workspace-rules-project.spec.ts.snap @@ -84,7 +84,7 @@ exports[`@nrwl/linter:workspace-rules-project should generate the required files exports[`@nrwl/linter:workspace-rules-project should generate the required files 5`] = ` "module.exports = { displayName: 'eslint-rules', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', diff --git a/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.spec.ts b/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.spec.ts index 164206b967674..37cd84f6d371e 100644 --- a/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.spec.ts +++ b/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.spec.ts @@ -46,7 +46,7 @@ describe('@nrwl/linter:workspace-rules-project', () => { tree.read('tools/eslint-rules/tsconfig.spec.json', 'utf-8') ).toMatchSnapshot(); expect( - tree.read('tools/eslint-rules/jest.config.js', 'utf-8') + tree.read('tools/eslint-rules/jest.config.ts', 'utf-8') ).toMatchSnapshot(); }); @@ -78,7 +78,7 @@ describe('@nrwl/linter:workspace-rules-project', () => { "test": Object { "executor": "@nrwl/jest:jest", "options": Object { - "jestConfig": "tools/eslint-rules/jest.config.js", + "jestConfig": "tools/eslint-rules/jest.config.ts", "passWithNoTests": true, }, "outputs": Array [ diff --git a/packages/nest/src/generators/application/application.spec.ts b/packages/nest/src/generators/application/application.spec.ts index c31ef0181a643..434e27688af53 100644 --- a/packages/nest/src/generators/application/application.spec.ts +++ b/packages/nest/src/generators/application/application.spec.ts @@ -52,7 +52,11 @@ describe('application generator', () => { ); expect(tsConfig.compilerOptions.emitDecoratorMetadata).toBe(true); expect(tsConfig.compilerOptions.target).toBe('es2015'); - expect(tsConfig.exclude).toEqual(['**/*.spec.ts', '**/*.test.ts']); + expect(tsConfig.exclude).toEqual([ + 'jest.config.ts', + '**/*.spec.ts', + '**/*.test.ts', + ]); }); describe('--skipFormat', () => { diff --git a/packages/nest/src/generators/init/init.spec.ts b/packages/nest/src/generators/init/init.spec.ts index d14416cf141ef..3e77f80a0f580 100644 --- a/packages/nest/src/generators/init/init.spec.ts +++ b/packages/nest/src/generators/init/init.spec.ts @@ -61,13 +61,13 @@ describe('init generator', () => { it('should add jest config when unitTestRunner is jest', async () => { await initGenerator(tree, { unitTestRunner: 'jest' }); - expect(tree.exists('jest.config.js')).toBe(true); + expect(tree.exists('jest.config.ts')).toBe(true); }); it('should not add jest config when unitTestRunner is none', async () => { await initGenerator(tree, { unitTestRunner: 'none' }); - expect(tree.exists('jest.config.js')).toBe(false); + expect(tree.exists('jest.config.ts')).toBe(false); }); describe('--skipFormat', () => { diff --git a/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap index 4adc174f94238..130e8779108fb 100644 --- a/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap @@ -3,7 +3,7 @@ exports[`lib --testEnvironment should set target jest testEnvironment to jsdom 1`] = ` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', @@ -21,7 +21,7 @@ exports[`lib --testEnvironment should set target jest testEnvironment to jsdom 1 exports[`lib --testEnvironment should set target jest testEnvironment to node by default 1`] = ` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', diff --git a/packages/nest/src/generators/library/library.spec.ts b/packages/nest/src/generators/library/library.spec.ts index f18e2ec175833..79cc0abbac7a1 100644 --- a/packages/nest/src/generators/library/library.spec.ts +++ b/packages/nest/src/generators/library/library.spec.ts @@ -36,7 +36,7 @@ describe('lib', () => { builder: '@nrwl/jest:jest', outputs: [`coverage/libs/${libFileName}`], options: { - jestConfig: `libs/${libFileName}/jest.config.js`, + jestConfig: `libs/${libFileName}/jest.config.ts`, passWithNoTests: true, }, }); @@ -156,13 +156,17 @@ describe('lib', () => { `libs/${libFileName}/tsconfig.lib.json` ); expect(tsconfigJson.extends).toEqual('./tsconfig.json'); - expect(tsconfigJson.exclude).toEqual(['**/*.spec.ts', '**/*.test.ts']); + expect(tsconfigJson.exclude).toEqual([ + 'jest.config.ts', + '**/*.spec.ts', + '**/*.test.ts', + ]); }); it('should generate files', async () => { await libraryGenerator(tree, { name: libName }); - expect(tree.exists(`libs/${libFileName}/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/${libFileName}/jest.config.ts`)).toBeTruthy(); expect(tree.exists(`libs/${libFileName}/src/index.ts`)).toBeTruthy(); expect( tree.exists(`libs/${libFileName}/src/lib/${libFileName}.spec.ts`) @@ -195,7 +199,7 @@ describe('lib', () => { await libraryGenerator(tree, { name: libName, directory: dirName }); expect( - tree.exists(`libs/${dirFileName}/${libFileName}/jest.config.js`) + tree.exists(`libs/${dirFileName}/${libFileName}/jest.config.ts`) ).toBeTruthy(); expect( tree.exists(`libs/${dirFileName}/${libFileName}/src/index.ts`) @@ -285,7 +289,7 @@ describe('lib', () => { await libraryGenerator(tree, { name: libName, unitTestRunner: 'none' }); expect(tree.exists(`libs/${libFileName}/tsconfig.spec.json`)).toBeFalsy(); - expect(tree.exists(`libs/${libFileName}/jest.config.js`)).toBeFalsy(); + expect(tree.exists(`libs/${libFileName}/jest.config.ts`)).toBeFalsy(); expect( tree.exists(`libs/${libFileName}/lib/${libFileName}.spec.ts`) ).toBeFalsy(); @@ -358,7 +362,7 @@ describe('lib', () => { await libraryGenerator(tree, { name: libName }); expect( - tree.read(`libs/${libFileName}/jest.config.js`, 'utf-8') + tree.read(`libs/${libFileName}/jest.config.ts`, 'utf-8') ).toMatchSnapshot(); }); @@ -366,7 +370,7 @@ describe('lib', () => { await libraryGenerator(tree, { name: libName, testEnvironment: 'jsdom' }); expect( - tree.read(`libs/${libFileName}/jest.config.js`, 'utf-8') + tree.read(`libs/${libFileName}/jest.config.ts`, 'utf-8') ).toMatchSnapshot(); }); }); diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index 4fa74ffbf734d..30e5a94e52a73 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -223,7 +223,7 @@ describe('app', () => { standaloneConfig: false, }); - expect(tree.read('apps/my-app/jest.config.js', 'utf-8')).toContain( + expect(tree.read('apps/my-app/jest.config.ts', 'utf-8')).toContain( `moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],` ); }); @@ -235,7 +235,7 @@ describe('app', () => { standaloneConfig: false, }); - expect(tree.read('apps/my-app/jest.config.js', 'utf-8')).toContain( + expect(tree.read('apps/my-app/jest.config.ts', 'utf-8')).toContain( `'^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest'` ); }); @@ -302,7 +302,7 @@ describe('app', () => { unitTestRunner: 'none', standaloneConfig: false, }); - expect(tree.exists('jest.config.js')).toBeFalsy(); + expect(tree.exists('jest.config.ts')).toBeFalsy(); expect(tree.exists('apps/my-app/specs/index.spec.tsx')).toBeFalsy(); }); }); diff --git a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts b/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts index 99b0dae4055e6..a673b33dc08e1 100644 --- a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts +++ b/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts @@ -1,4 +1,8 @@ -import { Tree } from '@nrwl/devkit'; +import { + readProjectConfiguration, + Tree, + updateProjectConfiguration, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { applicationGenerator } from '../../generators/application/application'; @@ -18,6 +22,20 @@ describe('Migration: enable SWC', () => { skipFormat: false, swc: false, }); + // rename jest config to js as that was standard at this version of nx + tree.delete('apps/demo/jest.config.ts'); + updateProjectConfiguration(tree, 'demo', { + ...readProjectConfiguration(tree, 'demo'), + targets: { + test: { + executor: '@nrwl/jest:jest', + options: { + jestConfig: 'apps/demo/jest.config.js', + passWithNoTests: true, + }, + }, + }, + }); // Config that isn't configured properly tree.write( @@ -53,7 +71,20 @@ module.exports = { skipFormat: false, swc: true, }); - + // rename jest config to js as that was standard at this version of nx + tree.delete('apps/demo/jest.config.ts'); + updateProjectConfiguration(tree, 'demo', { + ...readProjectConfiguration(tree, 'demo'), + targets: { + test: { + executor: '@nrwl/jest:jest', + options: { + jestConfig: 'apps/demo/jest.config.js', + passWithNoTests: true, + }, + }, + }, + }); // Config that isn't configured properly tree.write( 'apps/demo/jest.config.js', @@ -85,7 +116,20 @@ module.exports = { skipFormat: false, swc: false, }); - + // rename jest config to js as that was standard at this version of nx + tree.rename('apps/demo/jest.config.ts', 'apps/demo/jest.config.js'); + updateProjectConfiguration(tree, 'demo', { + ...readProjectConfiguration(tree, 'demo'), + targets: { + test: { + executor: '@nrwl/jest:jest', + options: { + jestConfig: 'apps/demo/jest.config.js', + passWithNoTests: true, + }, + }, + }, + }); tree.write( 'apps/demo/.babelrc', `{ diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index f64cfdb486f70..a0b0fbead3575 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -104,7 +104,7 @@ describe('app', () => { name: 'myNodeApp', standaloneConfig: false, }); - expect(tree.exists(`apps/my-node-app/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`apps/my-node-app/jest.config.ts`)).toBeTruthy(); expect(tree.exists('apps/my-node-app/src/main.ts')).toBeTruthy(); const tsconfig = readJson(tree, 'apps/my-node-app/tsconfig.json'); @@ -127,7 +127,11 @@ describe('app', () => { const tsconfigApp = readJson(tree, 'apps/my-node-app/tsconfig.app.json'); expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc'); expect(tsconfigApp.extends).toEqual('./tsconfig.json'); - expect(tsconfigApp.exclude).toEqual(['**/*.spec.ts', '**/*.test.ts']); + expect(tsconfigApp.exclude).toEqual([ + 'jest.config.ts', + '**/*.spec.ts', + '**/*.test.ts', + ]); const eslintrc = readJson(tree, 'apps/my-node-app/.eslintrc.json'); expect(eslintrc).toMatchInlineSnapshot(` Object { @@ -236,7 +240,7 @@ describe('app', () => { // Make sure these exist [ - `apps/my-dir/my-node-app/jest.config.js`, + `apps/my-dir/my-node-app/jest.config.ts`, 'apps/my-dir/my-node-app/src/main.ts', ].forEach((path) => { expect(tree.exists(path)).toBeTruthy(); @@ -257,7 +261,7 @@ describe('app', () => { { path: 'apps/my-dir/my-node-app/tsconfig.app.json', lookupFn: (json) => json.exclude, - expectedValue: ['**/*.spec.ts', '**/*.test.ts'], + expectedValue: ['jest.config.ts', '**/*.spec.ts', '**/*.test.ts'], }, { path: 'apps/my-dir/my-node-app/.eslintrc.json', @@ -275,11 +279,11 @@ describe('app', () => { unitTestRunner: 'none', standaloneConfig: false, }); - expect(tree.exists('jest.config.js')).toBeFalsy(); + expect(tree.exists('jest.config.ts')).toBeFalsy(); expect(tree.exists('apps/my-node-app/src/test-setup.ts')).toBeFalsy(); expect(tree.exists('apps/my-node-app/src/test.ts')).toBeFalsy(); expect(tree.exists('apps/my-node-app/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('apps/my-node-app/jest.config.js')).toBeFalsy(); + expect(tree.exists('apps/my-node-app/jest.config.ts')).toBeFalsy(); const workspaceJson = readJson(tree, 'workspace.json'); expect( workspaceJson.projects['my-node-app'].architect.test @@ -368,11 +372,11 @@ describe('app', () => { babelJest: true, } as Schema); - expect(tree.read(`apps/my-node-app/jest.config.js`, 'utf-8')) + expect(tree.read(`apps/my-node-app/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-node-app', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', testEnvironment: 'node', transform: { '^.+\\\\\\\\.[tj]s$': 'babel-jest' @@ -391,7 +395,7 @@ describe('app', () => { js: true, } as Schema); - expect(tree.exists(`apps/my-node-app/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`apps/my-node-app/jest.config.ts`)).toBeTruthy(); expect(tree.exists('apps/my-node-app/src/main.js')).toBeTruthy(); const tsConfig = readJson(tree, 'apps/my-node-app/tsconfig.json'); @@ -402,6 +406,7 @@ describe('app', () => { const tsConfigApp = readJson(tree, 'apps/my-node-app/tsconfig.app.json'); expect(tsConfigApp.include).toEqual(['**/*.ts', '**/*.js']); expect(tsConfigApp.exclude).toEqual([ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.js', @@ -434,7 +439,7 @@ describe('app', () => { js: true, } as Schema); expect( - tree.exists(`apps/my-dir/my-node-app/jest.config.js`) + tree.exists(`apps/my-dir/my-node-app/jest.config.ts`) ).toBeTruthy(); expect(tree.exists('apps/my-dir/my-node-app/src/main.js')).toBeTruthy(); }); diff --git a/packages/node/src/generators/library/library.spec.ts b/packages/node/src/generators/library/library.spec.ts index 68d921400e830..b7091a8adbb9d 100644 --- a/packages/node/src/generators/library/library.spec.ts +++ b/packages/node/src/generators/library/library.spec.ts @@ -40,7 +40,7 @@ describe('lib', () => { builder: '@nrwl/jest:jest', outputs: ['coverage/libs/my-lib'], options: { - jestConfig: 'libs/my-lib/jest.config.js', + jestConfig: 'libs/my-lib/jest.config.ts', passWithNoTests: true, }, }); @@ -116,12 +116,16 @@ describe('lib', () => { it('should exclude test files from tsconfig.lib.json', async () => { await libraryGenerator(tree, baseLibraryConfig); const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.lib.json'); - expect(tsconfigJson.exclude).toEqual(['**/*.spec.ts', '**/*.test.ts']); + expect(tsconfigJson.exclude).toEqual([ + 'jest.config.ts', + '**/*.spec.ts', + '**/*.test.ts', + ]); }); it('should generate files', async () => { await libraryGenerator(tree, baseLibraryConfig); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); const eslintrc = readJson(tree, 'libs/my-lib/.eslintrc.json'); @@ -199,7 +203,7 @@ describe('lib', () => { ...baseLibraryConfig, directory: 'myDir', }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); }); @@ -276,7 +280,7 @@ describe('lib', () => { directory: 'myDir', simpleModuleName: true, }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/lib/my-lib.ts')).toBeTruthy(); expect( @@ -320,7 +324,7 @@ describe('lib', () => { unitTestRunner: 'none', }); expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('libs/my-lib/jest.config.js')).toBeFalsy(); + expect(tree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); expect(tree.exists('libs/my-lib/lib/my-lib.spec.ts')).toBeFalsy(); const workspaceJson = readJson(tree, 'workspace.json'); expect(workspaceJson.projects['my-lib'].architect.test).toBeUndefined(); @@ -456,11 +460,11 @@ describe('lib', () => { babelJest: true, } as Schema); - expect(tree.read(`libs/my-lib/jest.config.js`, 'utf-8')) + expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', testEnvironment: 'node', transform: { '^.+\\\\\\\\.[tj]sx?$': 'babel-jest' @@ -494,6 +498,7 @@ describe('lib', () => { '**/*.js', ]); expect(readJson(tree, 'libs/my-lib/tsconfig.lib.json').exclude).toEqual([ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.js', diff --git a/packages/nx-plugin/src/generators/e2e-project/e2e.spec.ts b/packages/nx-plugin/src/generators/e2e-project/e2e.spec.ts index ffd2484d273d6..a765284adc36c 100644 --- a/packages/nx-plugin/src/generators/e2e-project/e2e.spec.ts +++ b/packages/nx-plugin/src/generators/e2e-project/e2e.spec.ts @@ -140,11 +140,11 @@ describe('NxPlugin e2e-project Generator', () => { expect(project.targets.e2e).toMatchObject({ options: expect.objectContaining({ - jestConfig: 'apps/my-plugin-e2e/jest.config.js', + jestConfig: 'apps/my-plugin-e2e/jest.config.ts', }), }); expect(tree.exists('apps/my-plugin-e2e/tsconfig.spec.json')).toBeTruthy(); - expect(tree.exists('apps/my-plugin-e2e/jest.config.js')).toBeTruthy(); + expect(tree.exists('apps/my-plugin-e2e/jest.config.ts')).toBeTruthy(); }); }); diff --git a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts index 1deec71cbcf51..cbb6f21bec38b 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts @@ -75,7 +75,7 @@ describe('NxPlugin Plugin Generator', () => { executor: '@nrwl/jest:jest', outputs: ['coverage/libs/my-plugin'], options: { - jestConfig: 'libs/my-plugin/jest.config.js', + jestConfig: 'libs/my-plugin/jest.config.ts', passWithNoTests: true, }, }); diff --git a/packages/react-native/src/generators/library/library.spec.ts b/packages/react-native/src/generators/library/library.spec.ts index 985673fe9d681..01c5e6612efee 100644 --- a/packages/react-native/src/generators/library/library.spec.ts +++ b/packages/react-native/src/generators/library/library.spec.ts @@ -226,7 +226,7 @@ describe('lib', () => { }); expect(appTree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(appTree.exists('libs/my-lib/jest.config.js')).toBeFalsy(); + expect(appTree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); const workspaceJson = readJson(appTree, 'workspace.json'); expect(workspaceJson.projects['my-lib'].architect.test).toBeUndefined(); expect(workspaceJson.projects['my-lib'].architect.lint) diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index beab116c056a7..217eeec4f6460 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -64,7 +64,7 @@ describe('app', () => { expect(appTree.exists('apps/my-app/src/app/app.spec.tsx')).toBeTruthy(); expect(appTree.exists('apps/my-app/src/app/app.module.css')).toBeTruthy(); - const jestConfig = appTree.read('apps/my-app/jest.config.js').toString(); + const jestConfig = appTree.read('apps/my-app/jest.config.ts').toString(); expect(jestConfig).toContain('@nrwl/react/plugins/jest'); const tsconfig = readJson(appTree, 'apps/my-app/tsconfig.json'); @@ -91,6 +91,7 @@ describe('app', () => { expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc'); expect(tsconfigApp.extends).toEqual('./tsconfig.json'); expect(tsconfigApp.exclude).toEqual([ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.tsx', @@ -208,6 +209,7 @@ Object { path: 'apps/my-dir/my-app/tsconfig.app.json', lookupFn: (json) => json.exclude, expectedValue: [ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.tsx', @@ -274,7 +276,7 @@ Object { it('should setup jest with tsx support', async () => { await applicationGenerator(appTree, { ...schema, name: 'my-app' }); - expect(appTree.read('apps/my-app/jest.config.js').toString()).toContain( + expect(appTree.read('apps/my-app/jest.config.ts').toString()).toContain( `moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],` ); }); @@ -282,7 +284,7 @@ Object { it('should setup jest without serializers', async () => { await applicationGenerator(appTree, { ...schema, name: 'my-app' }); - expect(appTree.read('apps/my-app/jest.config.js').toString()).not.toContain( + expect(appTree.read('apps/my-app/jest.config.ts').toString()).not.toContain( `'jest-preset-angular/build/AngularSnapshotSerializer.js',` ); }); @@ -359,10 +361,10 @@ Object { unitTestRunner: 'none', }); - expect(appTree.exists('jest.config.js')).toBeFalsy(); + expect(appTree.exists('jest.config.ts')).toBeFalsy(); expect(appTree.exists('apps/my-app/src/app/app.spec.tsx')).toBeFalsy(); expect(appTree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy(); - expect(appTree.exists('apps/my-app/jest.config.js')).toBeFalsy(); + expect(appTree.exists('apps/my-app/jest.config.ts')).toBeFalsy(); const workspaceJson = getProjects(appTree); expect(workspaceJson.get('my-app').targets.test).toBeUndefined(); expect(workspaceJson.get('my-app').targets.lint).toMatchInlineSnapshot(` diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index 096f89c6ff0e3..a5b804887ad47 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -152,6 +152,7 @@ describe('lib', () => { await libraryGenerator(appTree, defaultSchema); const tsconfigJson = readJson(appTree, 'libs/my-lib/tsconfig.lib.json'); expect(tsconfigJson.exclude).toEqual([ + 'jest.config.ts', '**/*.spec.ts', '**/*.test.ts', '**/*.spec.tsx', @@ -166,7 +167,7 @@ describe('lib', () => { it('should generate files', async () => { await libraryGenerator(appTree, defaultSchema); expect(appTree.exists('libs/my-lib/package.json')).toBeFalsy(); - expect(appTree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); + expect(appTree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); expect(appTree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); expect(appTree.exists('libs/my-lib/src/lib/my-lib.tsx')).toBeTruthy(); expect( @@ -247,7 +248,7 @@ describe('lib', () => { it('should generate files', async () => { await libraryGenerator(appTree, { ...defaultSchema, directory: 'myDir' }); - expect(appTree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(appTree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(appTree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect( appTree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.tsx') @@ -395,7 +396,7 @@ describe('lib', () => { }); expect(appTree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(appTree.exists('libs/my-lib/jest.config.js')).toBeFalsy(); + expect(appTree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); const workspaceJson = readJson(appTree, 'workspace.json'); expect(workspaceJson.projects['my-lib'].architect.test).toBeUndefined(); expect(workspaceJson.projects['my-lib'].architect.lint) diff --git a/packages/web/src/generators/application/application.spec.ts b/packages/web/src/generators/application/application.spec.ts index 9834b4ee13810..1469652436cb5 100644 --- a/packages/web/src/generators/application/application.spec.ts +++ b/packages/web/src/generators/application/application.spec.ts @@ -279,7 +279,7 @@ describe('app', () => { standaloneConfig: false, }); - expect(tree.read('apps/my-app/jest.config.js', 'utf-8')).not.toContain( + expect(tree.read('apps/my-app/jest.config.ts', 'utf-8')).not.toContain( `'jest-preset-angular/build/AngularSnapshotSerializer.js',` ); }); @@ -374,12 +374,12 @@ describe('app', () => { unitTestRunner: 'none', standaloneConfig: false, }); - expect(tree.exists('jest.config.js')).toBeFalsy(); + expect(tree.exists('jest.config.ts')).toBeFalsy(); expect( tree.exists('apps/my-app/src/app/app.element.spec.ts') ).toBeFalsy(); expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('apps/my-app/jest.config.js')).toBeFalsy(); + expect(tree.exists('apps/my-app/jest.config.ts')).toBeFalsy(); const workspaceJson = readJson(tree, 'workspace.json'); expect(workspaceJson.projects['my-app'].architect.test).toBeUndefined(); expect(workspaceJson.projects['my-app'].architect.lint) @@ -419,11 +419,11 @@ describe('app', () => { compiler: 'babel', } as Schema); - expect(tree.read(`apps/my-app/jest.config.js`, 'utf-8')) + expect(tree.read(`apps/my-app/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-app', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', setupFilesAfterEnv: ['/src/test-setup.ts'], transform: { '^.+\\\\\\\\.[tj]s$': 'babel-jest' @@ -441,11 +441,11 @@ describe('app', () => { compiler: 'swc', } as Schema); - expect(tree.read(`apps/my-app/jest.config.js`, 'utf-8')) + expect(tree.read(`apps/my-app/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-app', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', setupFilesAfterEnv: ['/src/test-setup.ts'], transform: { '^.+\\\\\\\\.[tj]s$': '@swc/jest' diff --git a/packages/workspace/src/generators/library/library.spec.ts b/packages/workspace/src/generators/library/library.spec.ts index 5a57f09652469..cb802593217bd 100644 --- a/packages/workspace/src/generators/library/library.spec.ts +++ b/packages/workspace/src/generators/library/library.spec.ts @@ -192,12 +192,12 @@ describe('lib', () => { name: 'myLib', }); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); - expect(tree.read(`libs/my-lib/jest.config.js`, 'utf-8')) + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); + expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json', @@ -234,7 +234,7 @@ describe('lib', () => { };" `; - expect(tree.read('jest.config.js', 'utf-8')).toMatchInlineSnapshot( + expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot( expectedRootJestConfig ); await libraryGenerator(tree, { @@ -242,7 +242,7 @@ describe('lib', () => { name: 'myLib2', }); - expect(tree.read('jest.config.js', 'utf-8')).toMatchInlineSnapshot( + expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot( expectedRootJestConfig ); }); @@ -287,7 +287,7 @@ describe('lib', () => { name: 'myLib', directory: 'myDir', }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.ts') @@ -602,7 +602,7 @@ describe('lib', () => { }); expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('libs/my-lib/jest.config.js')).toBeFalsy(); + expect(tree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeFalsy(); const workspaceJson = readJson(tree, 'workspace.json'); @@ -704,7 +704,7 @@ describe('lib', () => { name: 'myLib', js: true, }); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-lib/src/index.js')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.js')).toBeTruthy(); expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.js')).toBeTruthy(); @@ -758,7 +758,7 @@ describe('lib', () => { directory: 'myDir', js: true, }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); + expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy(); expect( tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.js') @@ -827,11 +827,11 @@ describe('lib', () => { babelJest: true, } as Schema); - expect(tree.read(`libs/my-lib/jest.config.js`, 'utf-8')) + expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` "module.exports = { displayName: 'my-lib', - preset: '../../jest.preset.js', + preset: '../../jest.preset.ts', transform: { '^.+\\\\\\\\.[tj]sx?$': 'babel-jest' }, diff --git a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts index fe26d3da45bd9..f3964d1f3e4da 100644 --- a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts @@ -32,15 +32,15 @@ describe('updateJestConfig', () => { it('should update the name and coverage directory', async () => { const jestConfig = `module.exports = { name: 'my-source', - preset: '../../jest.config.js', + preset: '../../jest.config.ts', coverageDirectory: '../../coverage/libs/my-source', snapshotSerializers: [ 'jest-preset-angular/AngularSnapshotSerializer.js', 'jest-preset-angular/HTMLCommentSerializer.js' ] };`; - const jestConfigPath = '/libs/my-destination/jest.config.js'; - const rootJestConfigPath = '/jest.config.js'; + const jestConfigPath = '/libs/my-destination/jest.config.ts'; + const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { name: 'my-source', standaloneConfig: false, @@ -70,15 +70,15 @@ describe('updateJestConfig', () => { it('should update jest configs properly even if project is in many layers of subfolders', async () => { const jestConfig = `module.exports = { name: 'some-test-dir-my-source', - preset: '../../jest.config.js', + preset: '../../jest.config.ts', coverageDirectory: '../../coverage/libs/some/test/dir/my-source', snapshotSerializers: [ 'jest-preset-angular/AngularSnapshotSerializer.js', 'jest-preset-angular/HTMLCommentSerializer.js' ] };`; - const jestConfigPath = '/libs/other/test/dir/my-destination/jest.config.js'; - const rootJestConfigPath = '/jest.config.js'; + const jestConfigPath = '/libs/other/test/dir/my-destination/jest.config.ts'; + const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { name: 'some/test/dir/my-source', standaloneConfig: false, @@ -108,7 +108,7 @@ describe('updateJestConfig', () => { }); it('updates the root config if not using `getJestProjects()`', async () => { - const rootJestConfigPath = '/jest.config.js'; + const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { name: 'some/test/dir/my-source', standaloneConfig: false, @@ -145,7 +145,7 @@ describe('updateJestConfig', () => { }); it('updates the root config if `getJestProjects()` is used but old path exists', async () => { - const rootJestConfigPath = '/jest.config.js'; + const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { name: 'some/test/dir/my-source', standaloneConfig: false, @@ -185,7 +185,7 @@ module.exports = { }); it('updates the root config if `getJestProjects()` is used with other projects in the array', async () => { - const rootJestConfigPath = '/jest.config.js'; + const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { name: 'some/test/dir/my-source', standaloneConfig: false, diff --git a/packages/workspace/src/generators/move/lib/update-jest-config.ts b/packages/workspace/src/generators/move/lib/update-jest-config.ts index ae2360fcf4279..256134ac7e8b3 100644 --- a/packages/workspace/src/generators/move/lib/update-jest-config.ts +++ b/packages/workspace/src/generators/move/lib/update-jest-config.ts @@ -31,8 +31,8 @@ export function updateJestConfig( tree.write(jestConfigPath, newContent); } - // update root jest.config.js - const rootJestConfigPath = '/jest.config.js'; + // update root jest.config.ts + const rootJestConfigPath = '/jest.config.ts'; if (!tree.exists(rootJestConfigPath)) { return; diff --git a/packages/workspace/src/generators/move/lib/update-project-root-files.ts b/packages/workspace/src/generators/move/lib/update-project-root-files.ts index b345e488f4f59..fd83586a68c37 100644 --- a/packages/workspace/src/generators/move/lib/update-project-root-files.ts +++ b/packages/workspace/src/generators/move/lib/update-project-root-files.ts @@ -35,10 +35,8 @@ export function updateProjectRootFiles( const dots = /\./g; const regex = new RegExp(oldRelativeRoot.replace(dots, '\\.'), 'g'); - for (const file of tree.children(schema.relativeToRootDestination)) { const ext = extname(file); - console.log({file}) if (!allowedExt.includes(ext)) { continue; } diff --git a/packages/workspace/src/generators/move/move.spec.ts b/packages/workspace/src/generators/move/move.spec.ts new file mode 100644 index 0000000000000..d13b192dbb3eb --- /dev/null +++ b/packages/workspace/src/generators/move/move.spec.ts @@ -0,0 +1,47 @@ +import { Tree } from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { moveGenerator } from './move'; +import { libraryGenerator } from '../library/library'; + +describe('move', () => { + let tree: Tree; + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + }); + + it('should update jest config when moving down directories', async () => { + await libraryGenerator(tree, { name: 'my-lib' }); + + await moveGenerator(tree, { + projectName: 'my-lib', + importPath: '@proj/shared-mylib', + updateImportPath: true, + destination: 'shared/my-lib-new', + }); + const jestConfigPath = 'libs/shared/my-lib-new/jest.config.ts'; + const afterJestConfig = tree.read(jestConfigPath, 'utf-8'); + expect(tree.exists(jestConfigPath)).toBeTruthy(); + expect(afterJestConfig).toContain("preset: '../../../jest.preset.ts'"); + expect(afterJestConfig).toContain( + "coverageDirectory: '../../../coverage/libs/shared/my-lib-new'" + ); + }); + + it('should update jest config when moving up directories', async () => { + await libraryGenerator(tree, { name: 'shared/my-lib' }); + + await moveGenerator(tree, { + projectName: 'shared-my-lib', + importPath: '@proj/mylib', + updateImportPath: true, + destination: 'my-lib-new', + }); + const jestConfigPath = 'libs/my-lib-new/jest.config.ts'; + const afterJestConfig = tree.read(jestConfigPath, 'utf-8'); + expect(tree.exists(jestConfigPath)).toBeTruthy(); + expect(afterJestConfig).toContain("preset: '../../jest.preset.ts'"); + expect(afterJestConfig).toContain( + "coverageDirectory: '../../coverage/libs/my-lib-new'" + ); + }); +}); diff --git a/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap b/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap index a48a3b470d898..7b6bcd58c8776 100644 --- a/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap +++ b/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap @@ -9,7 +9,7 @@ Array [ "tsconfig.editor.json", "tsconfig.json", ".eslintrc.json", - "jest.config.js", + "jest.config.ts", ] `; diff --git a/packages/workspace/src/generators/remove/lib/test-files/jest.config.js b/packages/workspace/src/generators/remove/lib/test-files/jest.config.ts similarity index 100% rename from packages/workspace/src/generators/remove/lib/test-files/jest.config.js rename to packages/workspace/src/generators/remove/lib/test-files/jest.config.ts diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts index 18484127b03d0..6e7fb02964129 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts @@ -31,19 +31,19 @@ describe('updateRootJestConfig', () => { }); tree.write( - 'jest.config.js', - readFileSync(join(__dirname, './test-files/jest.config.js'), 'utf-8') + 'jest.config.ts', + readFileSync(join(__dirname, './test-files/jest.config.ts'), 'utf-8') ); }); it('should delete lib project ref from root jest config', async () => { - const jestConfig = tree.read('jest.config.js', 'utf-8'); + const jestConfig = tree.read('jest.config.ts', 'utf-8'); expect(jestConfig).toMatchSnapshot(); updateJestConfig(tree, schema, readProjectConfiguration(tree, 'my-lib')); - const updatedJestConfig = tree.read('jest.config.js', 'utf-8'); + const updatedJestConfig = tree.read('jest.config.ts', 'utf-8'); expect(updatedJestConfig).toMatchSnapshot(); @@ -53,23 +53,23 @@ describe('updateRootJestConfig', () => { readProjectConfiguration(tree, 'my-other-lib') ); - const updatedJestConfig2 = tree.read('jest.config.js', 'utf-8'); + const updatedJestConfig2 = tree.read('jest.config.ts', 'utf-8'); expect(updatedJestConfig2).toMatchSnapshot(); }); it('should not delete lib project ref from root jest config if there is no project jest config', () => { - tree.delete('libs/my-lib/jest.config.js'); + tree.delete('libs/my-lib/jest.config.ts'); - const originalRootJestConfig = tree.read('jest.config.js', 'utf-8'); + const originalRootJestConfig = tree.read('jest.config.ts', 'utf-8'); tree.write( - 'jest.config.js', + 'jest.config.ts', originalRootJestConfig.replace(`'/libs/my-lib',`, '') ); updateJestConfig(tree, schema, readProjectConfiguration(tree, 'my-lib')); - const rootJestConfig = tree.read('jest.config.js', 'utf-8'); + const rootJestConfig = tree.read('jest.config.ts', 'utf-8'); expect(rootJestConfig).toMatchSnapshot(); });