Skip to content

Commit

Permalink
fix(testing): check if target exists before adding target for jest (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed Aug 2, 2023
1 parent e5fd0d5 commit 697754d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/jest/src/generators/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
readJson,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
writeJson,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

1 comment on commit 697754d

@vercel
Copy link

@vercel vercel bot commented on 697754d Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.