@nx/next
Version:
40 lines (39 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addJest = addJest;
const devkit_1 = require("@nx/devkit");
const internal_1 = require("@nx/eslint/internal");
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';
// Override exclude so typed linting doesn't fail on jest.config.ts and jest.config.cts.
if ((0, internal_1.isTypedLintingEnabled)(options)) {
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;
}