UNPKG

@nx/next

Version:

The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides: - Scaffolding for creating, building, serving, linting, and testing Next.js applications. - Integration wit

39 lines (38 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addJest = addJest; const devkit_1 = require("@nx/devkit"); const versions_1 = require("../../../utils/versions"); async function addJest(host, options) { if (options.unitTestRunner !== 'jest') { return () => { }; } const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion); const jestTask = await configurationGenerator(host, { ...options, project: options.projectName, supportTsx: true, skipSerializers: true, setupFile: 'none', compiler: 'babel', skipFormat: true, runtimeTsconfigFileName: 'tsconfig.json', }); const tsConfigSpecJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.spec.json')); (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json'), (json) => { json.compilerOptions ??= {}; json.compilerOptions.types ??= []; json.compilerOptions.types.push(...(tsConfigSpecJson?.compilerOptions?.types ?? [])); return json; }); (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.spec.json'), (json) => { json.compilerOptions.jsx = 'react'; // have to override exclude otherwise lint will fail with setParserOptionsProject and jest.config.ts/jest.config.cts if (options.setParserOptionsProject) { const tsConfig = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json')); json.exclude = tsConfig.exclude.filter((e) => e !== 'jest.config.ts' && e !== 'jest.config.cts'); } return json; }); return jestTask; }