From a908ef586ae36ef1fbfcf279bf7a1aec943da645 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Fri, 21 Apr 2023 09:52:52 -0600 Subject: [PATCH] fix(nextjs): Add exclude to root projects e2e tsconfig so that tests will be picked up. (#16459) --- .../src/generators/application/application.ts | 2 ++ .../lib/update-cypress-tsconfig.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/next/src/generators/application/lib/update-cypress-tsconfig.ts diff --git a/packages/next/src/generators/application/application.ts b/packages/next/src/generators/application/application.ts index 99e8a7dca4402..b82bf4337199b 100644 --- a/packages/next/src/generators/application/application.ts +++ b/packages/next/src/generators/application/application.ts @@ -17,6 +17,7 @@ import { nextInitGenerator } from '../init/init'; import { addStyleDependencies } from '../../utils/styles'; import { addLinting } from './lib/add-linting'; import { customServerGenerator } from '../custom-server/custom-server'; +import { updateCypressTsConfig } from './lib/update-cypress-tsconfig'; export async function applicationGenerator(host: Tree, schema: Schema) { const options = normalizeOptions(host, schema); @@ -31,6 +32,7 @@ export async function applicationGenerator(host: Tree, schema: Schema) { const jestTask = await addJest(host, options); const lintTask = await addLinting(host, options); updateJestConfig(host, options); + updateCypressTsConfig(host, options); const styledTask = addStyleDependencies(host, options.style); setDefaults(host, options); diff --git a/packages/next/src/generators/application/lib/update-cypress-tsconfig.ts b/packages/next/src/generators/application/lib/update-cypress-tsconfig.ts new file mode 100644 index 0000000000000..84ff9b08650f1 --- /dev/null +++ b/packages/next/src/generators/application/lib/update-cypress-tsconfig.ts @@ -0,0 +1,19 @@ +import { Tree, updateJson } from '@nx/devkit'; +import { NormalizedSchema } from './normalize-options'; + +export function updateCypressTsConfig(host: Tree, options: NormalizedSchema) { + if (options.e2eTestRunner !== 'cypress' || !options.rootProject) { + return; + } + + updateJson( + host, + `${options.e2eProjectRoot}/${options.e2eProjectName}/tsconfig.json`, + (json) => { + return { + ...json, + exclude: [], + }; + } + ); +}