fix(testing): check if target exists before adding target for jest (#18327)
This commit is contained in:
parent
e5fd0d5581
commit
697754dfaa
@ -3,6 +3,7 @@ import {
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
updateProjectConfiguration,
|
||||
writeJson,
|
||||
} from '@nx/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
@ -60,6 +61,19 @@ describe('jestProject', () => {
|
||||
expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should add target if there are no targets', async () => {
|
||||
const pc = readProjectConfiguration(tree, 'lib1');
|
||||
delete pc.targets;
|
||||
updateProjectConfiguration(tree, 'lib1', pc);
|
||||
expect(async () => {
|
||||
await configurationGenerator(tree, {
|
||||
...defaultOptions,
|
||||
project: 'lib1',
|
||||
setupFile: 'angular',
|
||||
});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should alter project configuration', async () => {
|
||||
await configurationGenerator(tree, {
|
||||
...defaultOptions,
|
||||
|
||||
@ -12,6 +12,10 @@ export function updateWorkspace(
|
||||
options: NormalizedJestProjectSchema
|
||||
) {
|
||||
const projectConfig = readProjectConfiguration(tree, options.project);
|
||||
if (!projectConfig.targets) {
|
||||
projectConfig.targets = {};
|
||||
}
|
||||
|
||||
projectConfig.targets.test = {
|
||||
executor: '@nx/jest:jest',
|
||||
outputs: [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user