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,
|
readJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
Tree,
|
Tree,
|
||||||
|
updateProjectConfiguration,
|
||||||
writeJson,
|
writeJson,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
@ -60,6 +61,19 @@ describe('jestProject', () => {
|
|||||||
expect(tree.read('libs/lib1/jest.config.ts', 'utf-8')).toMatchSnapshot();
|
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 () => {
|
it('should alter project configuration', async () => {
|
||||||
await configurationGenerator(tree, {
|
await configurationGenerator(tree, {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
|
|||||||
@ -12,6 +12,10 @@ export function updateWorkspace(
|
|||||||
options: NormalizedJestProjectSchema
|
options: NormalizedJestProjectSchema
|
||||||
) {
|
) {
|
||||||
const projectConfig = readProjectConfiguration(tree, options.project);
|
const projectConfig = readProjectConfiguration(tree, options.project);
|
||||||
|
if (!projectConfig.targets) {
|
||||||
|
projectConfig.targets = {};
|
||||||
|
}
|
||||||
|
|
||||||
projectConfig.targets.test = {
|
projectConfig.targets.test = {
|
||||||
executor: '@nx/jest:jest',
|
executor: '@nx/jest:jest',
|
||||||
outputs: [
|
outputs: [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user