From 399ba0f6257ec96337dfedd68f3766acc424fd7f Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Wed, 8 Jan 2025 11:20:06 +0100 Subject: [PATCH 01/35] tests: add test skeleton --- .../targets/create-targets.unit-test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts new file mode 100644 index 00000000..fb7019ca --- /dev/null +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -0,0 +1,60 @@ +import { describe } from 'vitest'; + +describe('createProjectConfiguration', (): void => { + + // spies + // const { environments, packages } = normalizeCreateNodesOptions(options); + it('should call normalizeCreateNodesOptions ones with options', (): void => { + + }); + // const isE2eProject = isEnvProject(projectConfiguration, environments); + it('should call normalizeCreateNodesOptions ones with projectConfiguration and environments', (): void => { + + }); + // const isPublishableProject = isPkgProject(projectConfiguration, packages); + it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { + + }); + + // if (!isE2eProject && !isPublishableProject) { + // return {}; + // } + it('should return empty object if !isE2eProject and !isPublishableProject', (): void => { + + }) + + // if (isE2eProject && !projectConfiguration.implicitDependencies?.length) { + // logger.warn( + // `Project ${projectConfiguration.name} is an environment project but has no implicit dependencies.` + // ); + // } + // i need a spy or mock for warn? idk + it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { + + }) + + // i should check for ENVIRONMENT TARGETS structure and PACKAGE TARGETS + it('should generate project configuration with correct structure', (): void => { + + }); + + // spies + // ...verdaccioTargets(projectConfiguration, { + // environmentsDir: environments.environmentsDir, + // } + it('should call verdaccioTargets ones with correct arguments', (): void => { + + }); + + // ...getEnvTargets(projectConfiguration, environments) + it('should call verdaccioTargets ones with correct arguments', (): void => { + + }); + + // ...updateEnvTargetNames(projectConfiguration + it('should call updateEnvTargetNames ones with correct arguments', (): void => { + + }); + + //getPkgTargets() not sure if this should be a spy +}) From c0adb816553cf73ce7b2d1c3d9ad9f5585556a33 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Wed, 8 Jan 2025 16:51:55 +0100 Subject: [PATCH 02/35] tests: add normalizeCreateNodesOptions spy and test --- .../targets/create-targets.unit-test.ts | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index fb7019ca..fc8c9f76 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -1,12 +1,55 @@ -import { describe } from 'vitest'; +import { beforeEach, describe, MockInstance } from 'vitest'; +import { ProjectConfiguration } from '@nx/devkit'; + +import { createProjectConfiguration } from './create-targets'; + +import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; +import { NxVerdaccioCreateNodeOptions } from '../schema'; + +import * as normalizeCreateNodesModule from './../normalize-create-nodes-options'; describe('createProjectConfiguration', (): void => { + const config: ProjectConfiguration = { + root: 'mock-root', + name: 'unit-test-project', + targets: { build: { executor: 'nx:build', options: {} },}, + tags: ['env:production'], + }; + + const options: NormalizedCreateNodeOptions = { + environments: { + targetNames: ['build'], + environmentsDir: './environments', + }, + packages: { + targetNames: ['test', 'lint'], + environmentsDir: './packages', + filterByTags: ['env:production', 'utility'], + }, + }; + + let normalizeCreateNodesOptionsSpy: MockInstance< + [options: NxVerdaccioCreateNodeOptions], + NormalizedCreateNodeOptions + >; + + beforeEach((): void => { + normalizeCreateNodesOptionsSpy = vi + .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') + .mockReturnValue(options) + }) - // spies - // const { environments, packages } = normalizeCreateNodesOptions(options); - it('should call normalizeCreateNodesOptions ones with options', (): void => { + afterEach((): void => { + normalizeCreateNodesOptionsSpy.mockRestore(); + }) + it('should call normalizeCreateNodesOptions ones with config and options', (): void => { + createProjectConfiguration(config, options); + expect(normalizeCreateNodesModule.normalizeCreateNodesOptions).toHaveBeenCalledWith( + options + ); }); + // const isE2eProject = isEnvProject(projectConfiguration, environments); it('should call normalizeCreateNodesOptions ones with projectConfiguration and environments', (): void => { From 73d3a512fcadce3814220019e89503b90f3be6df Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 09:14:09 +0100 Subject: [PATCH 03/35] tests: add isEnvProject spy and test --- .../targets/create-targets.unit-test.ts | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index fc8c9f76..188ffcf2 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -4,19 +4,24 @@ import { ProjectConfiguration } from '@nx/devkit'; import { createProjectConfiguration } from './create-targets'; import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; -import { NxVerdaccioCreateNodeOptions } from '../schema'; +import { + NxVerdaccioCreateNodeOptions, + NxVerdaccioEnvironmentsOptions, +} from '../schema'; import * as normalizeCreateNodesModule from './../normalize-create-nodes-options'; +import * as isEnvProjectModule from './environment.targets'; +import { isEnvProject } from './environment.targets'; describe('createProjectConfiguration', (): void => { const config: ProjectConfiguration = { root: 'mock-root', name: 'unit-test-project', - targets: { build: { executor: 'nx:build', options: {} },}, + targets: { build: { executor: 'nx:build', options: {} } }, tags: ['env:production'], }; - const options: NormalizedCreateNodeOptions = { + const normalizedOptions: NormalizedCreateNodeOptions = { environments: { targetNames: ['build'], environmentsDir: './environments', @@ -28,43 +33,62 @@ describe('createProjectConfiguration', (): void => { }, }; + const options: NxVerdaccioCreateNodeOptions = { + environments: { + targetNames: ['build'], // Minimal required to pass validation + }, + }; + let normalizeCreateNodesOptionsSpy: MockInstance< [options: NxVerdaccioCreateNodeOptions], NormalizedCreateNodeOptions >; + let isEnvProjectSpy: MockInstance< + [projectConfig: ProjectConfiguration, options: NormalizedCreateNodeOptions['environments']], + boolean + >; + beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') - .mockReturnValue(options) - }) + .mockReturnValue(normalizedOptions); + isEnvProjectSpy = vi + .spyOn(isEnvProjectModule, 'isEnvProject') + .mockReturnValue(true); + }); afterEach((): void => { normalizeCreateNodesOptionsSpy.mockRestore(); - }) + }); it('should call normalizeCreateNodesOptions ones with config and options', (): void => { createProjectConfiguration(config, options); - expect(normalizeCreateNodesModule.normalizeCreateNodesOptions).toHaveBeenCalledWith( - options - ); + expect( + normalizeCreateNodesModule.normalizeCreateNodesOptions + ).toHaveBeenCalledOnce(); + expect( + normalizeCreateNodesModule.normalizeCreateNodesOptions + ).toHaveBeenCalledWith(options); }); // const isE2eProject = isEnvProject(projectConfiguration, environments); - it('should call normalizeCreateNodesOptions ones with projectConfiguration and environments', (): void => { - + it('should call isEnvProject ones with projectConfiguration and environments', (): void => { + createProjectConfiguration(config, options); + expect(isEnvProjectModule.isEnvProject).toHaveBeenCalledOnce(); + expect(isEnvProjectModule.isEnvProject).toHaveBeenCalledWith( + config, + normalizedOptions['environments'] + ); }); - // const isPublishableProject = isPkgProject(projectConfiguration, packages); - it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { - }); + // const isPublishableProject = isPkgProject(projectConfiguration, packages); + it('should call isPublishableProject ones with projectConfiguration and packages', (): void => {}); // if (!isE2eProject && !isPublishableProject) { // return {}; // } - it('should return empty object if !isE2eProject and !isPublishableProject', (): void => { - - }) + it('should return empty object if !isE2eProject and !isPublishableProject', (): void => {}); // if (isE2eProject && !projectConfiguration.implicitDependencies?.length) { // logger.warn( @@ -72,32 +96,22 @@ describe('createProjectConfiguration', (): void => { // ); // } // i need a spy or mock for warn? idk - it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { - - }) + it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => {}); // i should check for ENVIRONMENT TARGETS structure and PACKAGE TARGETS - it('should generate project configuration with correct structure', (): void => { - - }); + it('should generate project configuration with correct structure', (): void => {}); // spies // ...verdaccioTargets(projectConfiguration, { // environmentsDir: environments.environmentsDir, // } - it('should call verdaccioTargets ones with correct arguments', (): void => { - - }); + it('should call verdaccioTargets ones with correct arguments', (): void => {}); // ...getEnvTargets(projectConfiguration, environments) - it('should call verdaccioTargets ones with correct arguments', (): void => { - - }); + it('should call verdaccioTargets ones with correct arguments', (): void => {}); // ...updateEnvTargetNames(projectConfiguration - it('should call updateEnvTargetNames ones with correct arguments', (): void => { - - }); + it('should call updateEnvTargetNames ones with correct arguments', (): void => {}); //getPkgTargets() not sure if this should be a spy -}) +}); From eb0390d5cff4fa3b2c4ad5cf174b106dc697d2ed Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 10:47:05 +0100 Subject: [PATCH 04/35] tests: add isPkgProject spy and test --- .../targets/create-targets.unit-test.ts | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 188ffcf2..e34c7ac5 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -7,11 +7,12 @@ import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; import { NxVerdaccioCreateNodeOptions, NxVerdaccioEnvironmentsOptions, + NxVerdaccioPackagesOptions, } from '../schema'; import * as normalizeCreateNodesModule from './../normalize-create-nodes-options'; -import * as isEnvProjectModule from './environment.targets'; -import { isEnvProject } from './environment.targets'; +import * as environmentTargetsModule from './environment.targets'; +import * as packageTargetsModule from './package.targets'; describe('createProjectConfiguration', (): void => { const config: ProjectConfiguration = { @@ -45,7 +46,15 @@ describe('createProjectConfiguration', (): void => { >; let isEnvProjectSpy: MockInstance< - [projectConfig: ProjectConfiguration, options: NormalizedCreateNodeOptions['environments']], + [ + projectConfig: ProjectConfiguration, + options: NormalizedCreateNodeOptions['environments'] + ], + boolean + >; + + let isPkgSpy: MockInstance< + [projectConfig: ProjectConfiguration, options: NxVerdaccioPackagesOptions], boolean >; @@ -54,7 +63,10 @@ describe('createProjectConfiguration', (): void => { .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') .mockReturnValue(normalizedOptions); isEnvProjectSpy = vi - .spyOn(isEnvProjectModule, 'isEnvProject') + .spyOn(environmentTargetsModule, 'isEnvProject') + .mockReturnValue(true); + isPkgSpy = vi + .spyOn(packageTargetsModule, 'isPkgProject') .mockReturnValue(true); }); @@ -72,18 +84,23 @@ describe('createProjectConfiguration', (): void => { ).toHaveBeenCalledWith(options); }); - // const isE2eProject = isEnvProject(projectConfiguration, environments); it('should call isEnvProject ones with projectConfiguration and environments', (): void => { createProjectConfiguration(config, options); - expect(isEnvProjectModule.isEnvProject).toHaveBeenCalledOnce(); - expect(isEnvProjectModule.isEnvProject).toHaveBeenCalledWith( + expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledOnce(); + expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledWith( config, normalizedOptions['environments'] ); }); - // const isPublishableProject = isPkgProject(projectConfiguration, packages); - it('should call isPublishableProject ones with projectConfiguration and packages', (): void => {}); + it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { + createProjectConfiguration(config, options); + expect(packageTargetsModule.isPkgProject).toHaveBeenCalledOnce(); + expect(packageTargetsModule.isPkgProject).toHaveBeenCalledWith( + config, + normalizedOptions['packages'] + ); + }); // if (!isE2eProject && !isPublishableProject) { // return {}; From 3a88a54de0fc1c75bbe3d52b1815e289d5bb16ab Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 11:14:49 +0100 Subject: [PATCH 05/35] tests: should return empty object if !isE2eProject and !isPublishableProject --- .../src/plugin/targets/create-targets.unit-test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index e34c7ac5..e89f9eaf 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, MockInstance } from 'vitest'; +import { beforeEach, describe, expect, MockInstance } from 'vitest'; import { ProjectConfiguration } from '@nx/devkit'; import { createProjectConfiguration } from './create-targets'; @@ -72,6 +72,8 @@ describe('createProjectConfiguration', (): void => { afterEach((): void => { normalizeCreateNodesOptionsSpy.mockRestore(); + isEnvProjectSpy.mockRestore(); + isPkgSpy.mockRestore(); }); it('should call normalizeCreateNodesOptions ones with config and options', (): void => { @@ -102,10 +104,12 @@ describe('createProjectConfiguration', (): void => { ); }); - // if (!isE2eProject && !isPublishableProject) { - // return {}; - // } - it('should return empty object if !isE2eProject and !isPublishableProject', (): void => {}); + it('should return empty object if !isE2eProject and !isPublishableProject', (): void => { + isEnvProjectSpy.mockReturnValue(false); + isPkgSpy.mockReturnValue(false); + const projectConfiguration = createProjectConfiguration(config, options); + expect(projectConfiguration).toStrictEqual({}) + }); // if (isE2eProject && !projectConfiguration.implicitDependencies?.length) { // logger.warn( From 8a8fcf5015ac04d8e5e249555205d151457a2d8d Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 11:31:26 +0100 Subject: [PATCH 06/35] tests: add logger warn tests --- .../targets/create-targets.unit-test.ts | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index e89f9eaf..369721ef 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -6,7 +6,6 @@ import { createProjectConfiguration } from './create-targets'; import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; import { NxVerdaccioCreateNodeOptions, - NxVerdaccioEnvironmentsOptions, NxVerdaccioPackagesOptions, } from '../schema'; @@ -14,6 +13,8 @@ import * as normalizeCreateNodesModule from './../normalize-create-nodes-options import * as environmentTargetsModule from './environment.targets'; import * as packageTargetsModule from './package.targets'; +import * as nxDevkitModule from '@nx/devkit'; + describe('createProjectConfiguration', (): void => { const config: ProjectConfiguration = { root: 'mock-root', @@ -40,6 +41,14 @@ describe('createProjectConfiguration', (): void => { }, }; + vi.mock('@nx/devkit', () => { + return { + logger: { + warn: vi.fn() + } + } + }) + let normalizeCreateNodesOptionsSpy: MockInstance< [options: NxVerdaccioCreateNodeOptions], NormalizedCreateNodeOptions @@ -111,13 +120,32 @@ describe('createProjectConfiguration', (): void => { expect(projectConfiguration).toStrictEqual({}) }); - // if (isE2eProject && !projectConfiguration.implicitDependencies?.length) { - // logger.warn( - // `Project ${projectConfiguration.name} is an environment project but has no implicit dependencies.` - // ); - // } - // i need a spy or mock for warn? idk - it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => {}); + + it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { + createProjectConfiguration(config, options); + expect(nxDevkitModule.logger.warn).toHaveBeenCalledOnce(); + }); + + it('should not log warn if isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { + const configWithImplicitDependencies = {...config, implicitDependencies: ['mock-implicit-dep']} + createProjectConfiguration(configWithImplicitDependencies, options); + expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + }); + + it('should not log warn if !isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { + isEnvProjectSpy.mockReturnValue(false); + const configWithImplicitDependencies = {...config, implicitDependencies: ['mock-implicit-dep']} + createProjectConfiguration(configWithImplicitDependencies, options); + expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + }); + + it('should not log warn if !isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { + isEnvProjectSpy.mockReturnValue(false); + createProjectConfiguration(config, options); + expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + }); + + // i should check for ENVIRONMENT TARGETS structure and PACKAGE TARGETS it('should generate project configuration with correct structure', (): void => {}); From 37b765469a69a2a5c66154178c4e00ab35a7f0c5 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 12:26:54 +0100 Subject: [PATCH 07/35] tests: add project configuration top level structure --- .../targets/create-targets.unit-test.ts | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 369721ef..a70ca34c 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -14,6 +14,15 @@ import * as environmentTargetsModule from './environment.targets'; import * as packageTargetsModule from './package.targets'; import * as nxDevkitModule from '@nx/devkit'; +import { + TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_E2E, + TARGET_ENVIRONMENT_INSTALL, + TARGET_ENVIRONMENT_PUBLISH_ONLY, + TARGET_ENVIRONMENT_SETUP, + TARGET_ENVIRONMENT_TEARDOWN, + TARGET_ENVIRONMENT_VERDACCIO_START, + TARGET_ENVIRONMENT_VERDACCIO_STOP +} from './environment.targets'; describe('createProjectConfiguration', (): void => { const config: ProjectConfiguration = { @@ -145,10 +154,41 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); }); + it('should generate project configuration with namedInputs and targets if isE2eProject and isPublishableProject', (): void => { + const result = createProjectConfiguration(config, options); + expect(result).toMatchObject({ + namedInputs: expect.any(Object), + targets: expect.any(Object), + }); + }); + it('should generate project configuration with namedInputs if isE2eProject and !isPublishableProject', (): void => { + const result = createProjectConfiguration(config, options); + expect(result).toMatchObject({ + namedInputs: expect.any(Object), + }); + }); + + it('should generate project configuration with targets if !isE2eProject and isPublishableProject', (): void => { + const result = createProjectConfiguration(config, options); + expect(result).toMatchObject({ + targets: expect.any(Object), + }); + }); - // i should check for ENVIRONMENT TARGETS structure and PACKAGE TARGETS - it('should generate project configuration with correct structure', (): void => {}); + // it('should generate nameInputs with correct structure and data', (): void => { + // const result = createProjectConfiguration(config, options); + // expect(result['namedInputs']).toMatchObject({ + // [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), + // [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), + // [TARGET_ENVIRONMENT_BOOTSTRAP]: expect.any(Object), + // [TARGET_ENVIRONMENT_INSTALL]: expect.any(Object), + // [TARGET_ENVIRONMENT_PUBLISH_ONLY]: expect.any(Object), + // [TARGET_ENVIRONMENT_SETUP]: expect.any(Object), + // [TARGET_ENVIRONMENT_TEARDOWN]: expect.any(Object), + // [TARGET_ENVIRONMENT_E2E]: expect.any(Object), + // }); + // }); // spies // ...verdaccioTargets(projectConfiguration, { From b559c855ff6edac8d61c6fe878ea3d879964dac9 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 13:06:23 +0100 Subject: [PATCH 08/35] tests: add verdaccioTargets spy and test --- .../targets/create-targets.unit-test.ts | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index a70ca34c..aaff7bd2 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -21,10 +21,15 @@ import { TARGET_ENVIRONMENT_SETUP, TARGET_ENVIRONMENT_TEARDOWN, TARGET_ENVIRONMENT_VERDACCIO_START, - TARGET_ENVIRONMENT_VERDACCIO_STOP + TARGET_ENVIRONMENT_VERDACCIO_STOP, verdaccioTargets } from './environment.targets'; describe('createProjectConfiguration', (): void => { + const verdaccioTargetsMock = { + [TARGET_ENVIRONMENT_VERDACCIO_START]: {}, + [TARGET_ENVIRONMENT_VERDACCIO_STOP]: {} + } + const config: ProjectConfiguration = { root: 'mock-root', name: 'unit-test-project', @@ -76,6 +81,8 @@ describe('createProjectConfiguration', (): void => { boolean >; + let verdaccioTargetsSpy; + beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') @@ -86,12 +93,16 @@ describe('createProjectConfiguration', (): void => { isPkgSpy = vi .spyOn(packageTargetsModule, 'isPkgProject') .mockReturnValue(true); + verdaccioTargetsSpy = vi + .spyOn(environmentTargetsModule, 'verdaccioTargets') + .mockReturnValue(verdaccioTargetsMock) }); afterEach((): void => { normalizeCreateNodesOptionsSpy.mockRestore(); isEnvProjectSpy.mockRestore(); isPkgSpy.mockRestore(); + verdaccioTargetsSpy.mockRestore(); }); it('should call normalizeCreateNodesOptions ones with config and options', (): void => { @@ -190,11 +201,15 @@ describe('createProjectConfiguration', (): void => { // }); // }); - // spies - // ...verdaccioTargets(projectConfiguration, { - // environmentsDir: environments.environmentsDir, - // } - it('should call verdaccioTargets ones with correct arguments', (): void => {}); + + it('should call verdaccioTargets ones with correct arguments', (): void => { + createProjectConfiguration(config, options); + expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledOnce(); + expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledWith( + config, + {environmentsDir: normalizedOptions.environments.environmentsDir} + ); + }); // ...getEnvTargets(projectConfiguration, environments) it('should call verdaccioTargets ones with correct arguments', (): void => {}); From 49f1f3ea877ab16225da17a9efee2c06a5b970c7 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 13:08:04 +0100 Subject: [PATCH 09/35] tests: add verdaccioTargets spy and test --- .../targets/create-targets.unit-test.ts | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index aaff7bd2..cfa3be35 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -1,11 +1,12 @@ import { beforeEach, describe, expect, MockInstance } from 'vitest'; -import { ProjectConfiguration } from '@nx/devkit'; +import { ProjectConfiguration, type TargetConfiguration } from '@nx/devkit'; import { createProjectConfiguration } from './create-targets'; import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; import { NxVerdaccioCreateNodeOptions, + NxVerdaccioEnvironmentsOptions, NxVerdaccioPackagesOptions, } from '../schema'; @@ -15,20 +16,23 @@ import * as packageTargetsModule from './package.targets'; import * as nxDevkitModule from '@nx/devkit'; import { - TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_E2E, + TARGET_ENVIRONMENT_BOOTSTRAP, + TARGET_ENVIRONMENT_E2E, TARGET_ENVIRONMENT_INSTALL, TARGET_ENVIRONMENT_PUBLISH_ONLY, TARGET_ENVIRONMENT_SETUP, TARGET_ENVIRONMENT_TEARDOWN, TARGET_ENVIRONMENT_VERDACCIO_START, - TARGET_ENVIRONMENT_VERDACCIO_STOP, verdaccioTargets + TARGET_ENVIRONMENT_VERDACCIO_STOP, + verdaccioTargets, } from './environment.targets'; +import { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; describe('createProjectConfiguration', (): void => { const verdaccioTargetsMock = { [TARGET_ENVIRONMENT_VERDACCIO_START]: {}, - [TARGET_ENVIRONMENT_VERDACCIO_STOP]: {} - } + [TARGET_ENVIRONMENT_VERDACCIO_STOP]: {}, + }; const config: ProjectConfiguration = { root: 'mock-root', @@ -55,13 +59,13 @@ describe('createProjectConfiguration', (): void => { }, }; - vi.mock('@nx/devkit', () => { + vi.mock('@nx/devkit', () => { return { logger: { - warn: vi.fn() - } - } - }) + warn: vi.fn(), + }, + }; + }); let normalizeCreateNodesOptionsSpy: MockInstance< [options: NxVerdaccioCreateNodeOptions], @@ -81,7 +85,17 @@ describe('createProjectConfiguration', (): void => { boolean >; - let verdaccioTargetsSpy; + let verdaccioTargetsSpy: MockInstance< + [ + projectConfig: ProjectConfiguration, + options: Pick< + NormalizedCreateNodeOptions['environments'], + 'environmentsDir' + > & + Omit + ], + Record + >; beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi @@ -95,7 +109,7 @@ describe('createProjectConfiguration', (): void => { .mockReturnValue(true); verdaccioTargetsSpy = vi .spyOn(environmentTargetsModule, 'verdaccioTargets') - .mockReturnValue(verdaccioTargetsMock) + .mockReturnValue(verdaccioTargetsMock); }); afterEach((): void => { @@ -137,24 +151,29 @@ describe('createProjectConfiguration', (): void => { isEnvProjectSpy.mockReturnValue(false); isPkgSpy.mockReturnValue(false); const projectConfiguration = createProjectConfiguration(config, options); - expect(projectConfiguration).toStrictEqual({}) + expect(projectConfiguration).toStrictEqual({}); }); - it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { createProjectConfiguration(config, options); expect(nxDevkitModule.logger.warn).toHaveBeenCalledOnce(); }); it('should not log warn if isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { - const configWithImplicitDependencies = {...config, implicitDependencies: ['mock-implicit-dep']} + const configWithImplicitDependencies = { + ...config, + implicitDependencies: ['mock-implicit-dep'], + }; createProjectConfiguration(configWithImplicitDependencies, options); expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should not log warn if !isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { isEnvProjectSpy.mockReturnValue(false); - const configWithImplicitDependencies = {...config, implicitDependencies: ['mock-implicit-dep']} + const configWithImplicitDependencies = { + ...config, + implicitDependencies: ['mock-implicit-dep'], + }; createProjectConfiguration(configWithImplicitDependencies, options); expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); }); @@ -201,13 +220,12 @@ describe('createProjectConfiguration', (): void => { // }); // }); - it('should call verdaccioTargets ones with correct arguments', (): void => { createProjectConfiguration(config, options); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledOnce(); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledWith( config, - {environmentsDir: normalizedOptions.environments.environmentsDir} + { environmentsDir: normalizedOptions.environments.environmentsDir } ); }); From ba2c40bcc79cacf9336176811476bc078c6628d1 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 13:15:03 +0100 Subject: [PATCH 10/35] tests: add getEnvTargets spy and test --- .../targets/create-targets.unit-test.ts | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index cfa3be35..7e4c7859 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -16,6 +16,7 @@ import * as packageTargetsModule from './package.targets'; import * as nxDevkitModule from '@nx/devkit'; import { + getEnvTargets, TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_E2E, TARGET_ENVIRONMENT_INSTALL, @@ -24,7 +25,7 @@ import { TARGET_ENVIRONMENT_TEARDOWN, TARGET_ENVIRONMENT_VERDACCIO_START, TARGET_ENVIRONMENT_VERDACCIO_STOP, - verdaccioTargets, + verdaccioTargets } from './environment.targets'; import { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; @@ -34,6 +35,15 @@ describe('createProjectConfiguration', (): void => { [TARGET_ENVIRONMENT_VERDACCIO_STOP]: {}, }; + const envTargetsMock = { + [TARGET_ENVIRONMENT_BOOTSTRAP]: {}, + [TARGET_ENVIRONMENT_INSTALL]: {}, + [TARGET_ENVIRONMENT_PUBLISH_ONLY]: {}, + [TARGET_ENVIRONMENT_SETUP]: {}, + [TARGET_ENVIRONMENT_TEARDOWN]: {}, + [TARGET_ENVIRONMENT_E2E]: {}, + }; + const config: ProjectConfiguration = { root: 'mock-root', name: 'unit-test-project', @@ -97,6 +107,8 @@ describe('createProjectConfiguration', (): void => { Record >; + let getEnvTargetsSpy; + beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') @@ -110,6 +122,8 @@ describe('createProjectConfiguration', (): void => { verdaccioTargetsSpy = vi .spyOn(environmentTargetsModule, 'verdaccioTargets') .mockReturnValue(verdaccioTargetsMock); + getEnvTargetsSpy = vi.spyOn(environmentTargetsModule, 'getEnvTargets') + .mockReturnValue(envTargetsMock) }); afterEach((): void => { @@ -229,8 +243,14 @@ describe('createProjectConfiguration', (): void => { ); }); - // ...getEnvTargets(projectConfiguration, environments) - it('should call verdaccioTargets ones with correct arguments', (): void => {}); + it('should call getEnvTargets ones with correct arguments', (): void => { + createProjectConfiguration(config, options); + expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledOnce(); + expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledWith( + config, + normalizedOptions.environments + ); + }); // ...updateEnvTargetNames(projectConfiguration it('should call updateEnvTargetNames ones with correct arguments', (): void => {}); From dcc37cd3f82cba5fdd493140b0d0c1a9ee85a6de Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 13:46:45 +0100 Subject: [PATCH 11/35] tests: add object structure --- .../targets/create-targets.unit-test.ts | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 7e4c7859..54dcfc7e 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -28,6 +28,7 @@ import { verdaccioTargets } from './environment.targets'; import { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; +import { TARGET_PACKAGE_INSTALL, TARGET_PACKAGE_PUBLISH } from './package.targets'; describe('createProjectConfiguration', (): void => { const verdaccioTargetsMock = { @@ -107,7 +108,22 @@ describe('createProjectConfiguration', (): void => { Record >; - let getEnvTargetsSpy; + let getEnvTargetsSpy: MockInstance< + [ + projectConfig: ProjectConfiguration, + options: Omit< + NxVerdaccioEnvironmentsOptions, + 'targetNames' | 'environmentsDir' + > & + Required< + Pick< + NxVerdaccioEnvironmentsOptions, + 'targetNames' | 'environmentsDir' + > + > + ], + Record> + >; beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi @@ -131,6 +147,7 @@ describe('createProjectConfiguration', (): void => { isEnvProjectSpy.mockRestore(); isPkgSpy.mockRestore(); verdaccioTargetsSpy.mockRestore(); + getEnvTargetsSpy.mockRestore(); }); it('should call normalizeCreateNodesOptions ones with config and options', (): void => { @@ -206,34 +223,42 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate project configuration with namedInputs if isE2eProject and !isPublishableProject', (): void => { + it('should generate project configuration with targets if !isE2eProject and isPublishableProject', (): void => { const result = createProjectConfiguration(config, options); expect(result).toMatchObject({ - namedInputs: expect.any(Object), + targets: expect.any(Object), }); }); - it('should generate project configuration with targets if !isE2eProject and isPublishableProject', (): void => { + it('should generate targets with correct structure if isE2eProject and !isPublishableProject', (): void => { + isPkgSpy.mockReturnValue(false); + const result = createProjectConfiguration(config, options); + expect(result['targets']).toMatchObject( + {build: expect.any(Object), + [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), + [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), + [TARGET_ENVIRONMENT_BOOTSTRAP]: expect.any(Object), + [TARGET_ENVIRONMENT_INSTALL]: expect.any(Object), + [TARGET_ENVIRONMENT_PUBLISH_ONLY]: expect.any(Object), + [TARGET_ENVIRONMENT_SETUP]: expect.any(Object), + [TARGET_ENVIRONMENT_TEARDOWN]: expect.any(Object), + [TARGET_ENVIRONMENT_E2E]: expect.any(Object), + } + ); + }); + + it('should generate nameInputs with correct structure and data', (): void => { const result = createProjectConfiguration(config, options); expect(result).toMatchObject({ - targets: expect.any(Object), + namedInputs: expect.any(Object), + targets: + { + [TARGET_PACKAGE_PUBLISH]: expect.any(Object), + [TARGET_PACKAGE_INSTALL]: expect.any(Object), + } }); }); - // it('should generate nameInputs with correct structure and data', (): void => { - // const result = createProjectConfiguration(config, options); - // expect(result['namedInputs']).toMatchObject({ - // [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), - // [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), - // [TARGET_ENVIRONMENT_BOOTSTRAP]: expect.any(Object), - // [TARGET_ENVIRONMENT_INSTALL]: expect.any(Object), - // [TARGET_ENVIRONMENT_PUBLISH_ONLY]: expect.any(Object), - // [TARGET_ENVIRONMENT_SETUP]: expect.any(Object), - // [TARGET_ENVIRONMENT_TEARDOWN]: expect.any(Object), - // [TARGET_ENVIRONMENT_E2E]: expect.any(Object), - // }); - // }); - it('should call verdaccioTargets ones with correct arguments', (): void => { createProjectConfiguration(config, options); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledOnce(); @@ -254,6 +279,4 @@ describe('createProjectConfiguration', (): void => { // ...updateEnvTargetNames(projectConfiguration it('should call updateEnvTargetNames ones with correct arguments', (): void => {}); - - //getPkgTargets() not sure if this should be a spy }); From 03697f531ba460e55f87a555fea3320ae9922abc Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 13:53:00 +0100 Subject: [PATCH 12/35] tests: add updateEnvTargetNames spy and test --- .../plugin/targets/create-targets.unit-test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 54dcfc7e..13b5e4ea 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -24,7 +24,7 @@ import { TARGET_ENVIRONMENT_SETUP, TARGET_ENVIRONMENT_TEARDOWN, TARGET_ENVIRONMENT_VERDACCIO_START, - TARGET_ENVIRONMENT_VERDACCIO_STOP, + TARGET_ENVIRONMENT_VERDACCIO_STOP, updateEnvTargetNames, verdaccioTargets } from './environment.targets'; import { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; @@ -125,6 +125,8 @@ describe('createProjectConfiguration', (): void => { Record> >; + let updateEnvTargetNamesSpy; + beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') @@ -137,9 +139,8 @@ describe('createProjectConfiguration', (): void => { .mockReturnValue(true); verdaccioTargetsSpy = vi .spyOn(environmentTargetsModule, 'verdaccioTargets') - .mockReturnValue(verdaccioTargetsMock); getEnvTargetsSpy = vi.spyOn(environmentTargetsModule, 'getEnvTargets') - .mockReturnValue(envTargetsMock) + updateEnvTargetNamesSpy = vi.spyOn(environmentTargetsModule, 'updateEnvTargetNames') }); afterEach((): void => { @@ -148,6 +149,7 @@ describe('createProjectConfiguration', (): void => { isPkgSpy.mockRestore(); verdaccioTargetsSpy.mockRestore(); getEnvTargetsSpy.mockRestore(); + updateEnvTargetNamesSpy.mockRestore(); }); it('should call normalizeCreateNodesOptions ones with config and options', (): void => { @@ -277,6 +279,12 @@ describe('createProjectConfiguration', (): void => { ); }); - // ...updateEnvTargetNames(projectConfiguration - it('should call updateEnvTargetNames ones with correct arguments', (): void => {}); + it('should call updateEnvTargetNames ones with correct arguments', (): void => { + createProjectConfiguration(config, options); + expect(environmentTargetsModule.updateEnvTargetNames).toHaveBeenCalledOnce(); + expect(environmentTargetsModule.updateEnvTargetNames).toHaveBeenCalledWith( + config, + normalizedOptions.environments + ); + }); }); From 16379ffc621b67a9906a01af33056690e412b232 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 14:54:59 +0100 Subject: [PATCH 13/35] tests: code cleanup --- .../targets/create-targets.unit-test.ts | 226 +++++++----------- 1 file changed, 84 insertions(+), 142 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 13b5e4ea..4274a626 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -1,57 +1,43 @@ -import { beforeEach, describe, expect, MockInstance } from 'vitest'; -import { ProjectConfiguration, type TargetConfiguration } from '@nx/devkit'; +import { beforeEach, describe, expect, type MockInstance } from 'vitest'; +import { type ProjectConfiguration } from '@nx/devkit'; -import { createProjectConfiguration } from './create-targets'; +import * as nxDevkitMockModule from '@nx/devkit'; -import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; +import { createProjectConfiguration } from './create-targets'; import { - NxVerdaccioCreateNodeOptions, - NxVerdaccioEnvironmentsOptions, - NxVerdaccioPackagesOptions, -} from '../schema'; - -import * as normalizeCreateNodesModule from './../normalize-create-nodes-options'; -import * as environmentTargetsModule from './environment.targets'; -import * as packageTargetsModule from './package.targets'; - -import * as nxDevkitModule from '@nx/devkit'; + TARGET_PACKAGE_INSTALL, + TARGET_PACKAGE_PUBLISH, +} from './package.targets'; import { - getEnvTargets, - TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_E2E, - TARGET_ENVIRONMENT_INSTALL, - TARGET_ENVIRONMENT_PUBLISH_ONLY, TARGET_ENVIRONMENT_SETUP, + TARGET_ENVIRONMENT_INSTALL, TARGET_ENVIRONMENT_TEARDOWN, + TARGET_ENVIRONMENT_BOOTSTRAP, + TARGET_ENVIRONMENT_PUBLISH_ONLY, + TARGET_ENVIRONMENT_VERDACCIO_STOP, TARGET_ENVIRONMENT_VERDACCIO_START, - TARGET_ENVIRONMENT_VERDACCIO_STOP, updateEnvTargetNames, - verdaccioTargets } from './environment.targets'; -import { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; -import { TARGET_PACKAGE_INSTALL, TARGET_PACKAGE_PUBLISH } from './package.targets'; -describe('createProjectConfiguration', (): void => { - const verdaccioTargetsMock = { - [TARGET_ENVIRONMENT_VERDACCIO_START]: {}, - [TARGET_ENVIRONMENT_VERDACCIO_STOP]: {}, - }; +import { type NxVerdaccioCreateNodeOptions } from '../schema'; +import { type NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; - const envTargetsMock = { - [TARGET_ENVIRONMENT_BOOTSTRAP]: {}, - [TARGET_ENVIRONMENT_INSTALL]: {}, - [TARGET_ENVIRONMENT_PUBLISH_ONLY]: {}, - [TARGET_ENVIRONMENT_SETUP]: {}, - [TARGET_ENVIRONMENT_TEARDOWN]: {}, - [TARGET_ENVIRONMENT_E2E]: {}, - }; +import * as packageTargetsSpyModule from './package.targets'; +import * as environmentTargetsModule from './environment.targets'; +import * as normalizeCreateNodesSpyModule from './../normalize-create-nodes-options'; - const config: ProjectConfiguration = { +describe('createProjectConfiguration', (): void => { + const implicitDependencies = ['mock-implicit-dep']; + const projectConfiguration: ProjectConfiguration = { root: 'mock-root', name: 'unit-test-project', - targets: { build: { executor: 'nx:build', options: {} } }, - tags: ['env:production'], + targets: { build: {} }, + }; + const options: NxVerdaccioCreateNodeOptions = { + environments: { + targetNames: ['build'], + }, }; - const normalizedOptions: NormalizedCreateNodeOptions = { environments: { targetNames: ['build'], @@ -60,13 +46,6 @@ describe('createProjectConfiguration', (): void => { packages: { targetNames: ['test', 'lint'], environmentsDir: './packages', - filterByTags: ['env:production', 'utility'], - }, - }; - - const options: NxVerdaccioCreateNodeOptions = { - environments: { - targetNames: ['build'], // Minimal required to pass validation }, }; @@ -78,69 +57,32 @@ describe('createProjectConfiguration', (): void => { }; }); - let normalizeCreateNodesOptionsSpy: MockInstance< - [options: NxVerdaccioCreateNodeOptions], - NormalizedCreateNodeOptions - >; - - let isEnvProjectSpy: MockInstance< - [ - projectConfig: ProjectConfiguration, - options: NormalizedCreateNodeOptions['environments'] - ], - boolean - >; - - let isPkgSpy: MockInstance< - [projectConfig: ProjectConfiguration, options: NxVerdaccioPackagesOptions], - boolean - >; - - let verdaccioTargetsSpy: MockInstance< - [ - projectConfig: ProjectConfiguration, - options: Pick< - NormalizedCreateNodeOptions['environments'], - 'environmentsDir' - > & - Omit - ], - Record - >; - - let getEnvTargetsSpy: MockInstance< - [ - projectConfig: ProjectConfiguration, - options: Omit< - NxVerdaccioEnvironmentsOptions, - 'targetNames' | 'environmentsDir' - > & - Required< - Pick< - NxVerdaccioEnvironmentsOptions, - 'targetNames' | 'environmentsDir' - > - > - ], - Record> - >; - - let updateEnvTargetNamesSpy; + let normalizeCreateNodesOptionsSpy: MockInstance; + let isEnvProjectSpy: MockInstance; + let isPkgSpy: MockInstance; + let verdaccioTargetsSpy: MockInstance; + let getEnvTargetsSpy: MockInstance; + let updateEnvTargetNamesSpy: MockInstance; beforeEach((): void => { normalizeCreateNodesOptionsSpy = vi - .spyOn(normalizeCreateNodesModule, 'normalizeCreateNodesOptions') + .spyOn(normalizeCreateNodesSpyModule, 'normalizeCreateNodesOptions') .mockReturnValue(normalizedOptions); isEnvProjectSpy = vi .spyOn(environmentTargetsModule, 'isEnvProject') .mockReturnValue(true); isPkgSpy = vi - .spyOn(packageTargetsModule, 'isPkgProject') + .spyOn(packageTargetsSpyModule, 'isPkgProject') .mockReturnValue(true); - verdaccioTargetsSpy = vi - .spyOn(environmentTargetsModule, 'verdaccioTargets') - getEnvTargetsSpy = vi.spyOn(environmentTargetsModule, 'getEnvTargets') - updateEnvTargetNamesSpy = vi.spyOn(environmentTargetsModule, 'updateEnvTargetNames') + verdaccioTargetsSpy = vi.spyOn( + environmentTargetsModule, + 'verdaccioTargets' + ); + getEnvTargetsSpy = vi.spyOn(environmentTargetsModule, 'getEnvTargets'); + updateEnvTargetNamesSpy = vi.spyOn( + environmentTargetsModule, + 'updateEnvTargetNames' + ); }); afterEach((): void => { @@ -152,30 +94,30 @@ describe('createProjectConfiguration', (): void => { updateEnvTargetNamesSpy.mockRestore(); }); - it('should call normalizeCreateNodesOptions ones with config and options', (): void => { - createProjectConfiguration(config, options); + it('should call normalizeCreateNodesOptions ones with projectConfiguration and options', (): void => { + createProjectConfiguration(projectConfiguration, options); expect( - normalizeCreateNodesModule.normalizeCreateNodesOptions + normalizeCreateNodesSpyModule.normalizeCreateNodesOptions ).toHaveBeenCalledOnce(); expect( - normalizeCreateNodesModule.normalizeCreateNodesOptions + normalizeCreateNodesSpyModule.normalizeCreateNodesOptions ).toHaveBeenCalledWith(options); }); it('should call isEnvProject ones with projectConfiguration and environments', (): void => { - createProjectConfiguration(config, options); + createProjectConfiguration(projectConfiguration, options); expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledOnce(); expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledWith( - config, + projectConfiguration, normalizedOptions['environments'] ); }); it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { - createProjectConfiguration(config, options); - expect(packageTargetsModule.isPkgProject).toHaveBeenCalledOnce(); - expect(packageTargetsModule.isPkgProject).toHaveBeenCalledWith( - config, + createProjectConfiguration(projectConfiguration, options); + expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledOnce(); + expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledWith( + projectConfiguration, normalizedOptions['packages'] ); }); @@ -183,42 +125,42 @@ describe('createProjectConfiguration', (): void => { it('should return empty object if !isE2eProject and !isPublishableProject', (): void => { isEnvProjectSpy.mockReturnValue(false); isPkgSpy.mockReturnValue(false); - const projectConfiguration = createProjectConfiguration(config, options); - expect(projectConfiguration).toStrictEqual({}); + const result = createProjectConfiguration(projectConfiguration, options); + expect(result).toStrictEqual({}); }); it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { - createProjectConfiguration(config, options); - expect(nxDevkitModule.logger.warn).toHaveBeenCalledOnce(); + createProjectConfiguration(projectConfiguration, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); }); it('should not log warn if isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { const configWithImplicitDependencies = { - ...config, - implicitDependencies: ['mock-implicit-dep'], + ...projectConfiguration, + implicitDependencies, }; createProjectConfiguration(configWithImplicitDependencies, options); - expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should not log warn if !isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { isEnvProjectSpy.mockReturnValue(false); const configWithImplicitDependencies = { - ...config, - implicitDependencies: ['mock-implicit-dep'], + ...projectConfiguration, + implicitDependencies, }; createProjectConfiguration(configWithImplicitDependencies, options); - expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should not log warn if !isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { isEnvProjectSpy.mockReturnValue(false); - createProjectConfiguration(config, options); - expect(nxDevkitModule.logger.warn).toHaveBeenCalledTimes(0); + createProjectConfiguration(projectConfiguration, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should generate project configuration with namedInputs and targets if isE2eProject and isPublishableProject', (): void => { - const result = createProjectConfiguration(config, options); + const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), targets: expect.any(Object), @@ -226,7 +168,7 @@ describe('createProjectConfiguration', (): void => { }); it('should generate project configuration with targets if !isE2eProject and isPublishableProject', (): void => { - const result = createProjectConfiguration(config, options); + const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ targets: expect.any(Object), }); @@ -234,9 +176,9 @@ describe('createProjectConfiguration', (): void => { it('should generate targets with correct structure if isE2eProject and !isPublishableProject', (): void => { isPkgSpy.mockReturnValue(false); - const result = createProjectConfiguration(config, options); - expect(result['targets']).toMatchObject( - {build: expect.any(Object), + const result = createProjectConfiguration(projectConfiguration, options); + expect(result['targets']).toMatchObject({ + build: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), [TARGET_ENVIRONMENT_BOOTSTRAP]: expect.any(Object), @@ -245,45 +187,45 @@ describe('createProjectConfiguration', (): void => { [TARGET_ENVIRONMENT_SETUP]: expect.any(Object), [TARGET_ENVIRONMENT_TEARDOWN]: expect.any(Object), [TARGET_ENVIRONMENT_E2E]: expect.any(Object), - } - ); + }); }); it('should generate nameInputs with correct structure and data', (): void => { - const result = createProjectConfiguration(config, options); + const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), - targets: - { - [TARGET_PACKAGE_PUBLISH]: expect.any(Object), - [TARGET_PACKAGE_INSTALL]: expect.any(Object), - } + targets: { + [TARGET_PACKAGE_PUBLISH]: expect.any(Object), + [TARGET_PACKAGE_INSTALL]: expect.any(Object), + }, }); }); it('should call verdaccioTargets ones with correct arguments', (): void => { - createProjectConfiguration(config, options); + createProjectConfiguration(projectConfiguration, options); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledOnce(); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledWith( - config, + projectConfiguration, { environmentsDir: normalizedOptions.environments.environmentsDir } ); }); it('should call getEnvTargets ones with correct arguments', (): void => { - createProjectConfiguration(config, options); + createProjectConfiguration(projectConfiguration, options); expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledOnce(); expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledWith( - config, + projectConfiguration, normalizedOptions.environments ); }); it('should call updateEnvTargetNames ones with correct arguments', (): void => { - createProjectConfiguration(config, options); - expect(environmentTargetsModule.updateEnvTargetNames).toHaveBeenCalledOnce(); + createProjectConfiguration(projectConfiguration, options); + expect( + environmentTargetsModule.updateEnvTargetNames + ).toHaveBeenCalledOnce(); expect(environmentTargetsModule.updateEnvTargetNames).toHaveBeenCalledWith( - config, + projectConfiguration, normalizedOptions.environments ); }); From d9a12d0935f589c29f9e4e32db2279ee9a17d2a8 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Thu, 9 Jan 2025 17:10:23 +0100 Subject: [PATCH 14/35] tests: getPkgTargets object structure --- .../targets/package.targets.unit-test.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index d9903da1..2741d428 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -1,5 +1,14 @@ import { describe, it, expect } from 'vitest'; -import { isPkgProject } from './package.targets'; + +import { + getPkgTargets, + isPkgProject, + TARGET_PACKAGE_INSTALL, + TARGET_PACKAGE_PUBLISH, +} from './package.targets'; + +import { EXECUTOR_PACKAGE_NPM_INSTALL } from '../../executors/pkg-install/constants'; +import { EXECUTOR_PACKAGE_NPM_PUBLISH } from '../../executors/pkg-publish/constants'; describe('isPkgProject', () => { it('should return true for projects with projectType is library', () => { @@ -58,3 +67,31 @@ describe('isPkgProject', () => { ).toBe(false); }); }); + +describe('getPkgTargets', (): void => { + it('should generate PkgTargets with correct structure', (): void => { + const result = getPkgTargets(); + expect(result).toMatchObject({ + [TARGET_PACKAGE_PUBLISH]: expect.any(Object), + [TARGET_PACKAGE_INSTALL]: expect.any(Object), + }); + }); + + it('should generate TARGET_PACKAGE_PUBLISH with correct structure', (): void => { + const result = getPkgTargets(); + expect(result[TARGET_PACKAGE_PUBLISH]).toMatchObject({ + dependsOn: expect.any(Array), + executor: expect.stringContaining(EXECUTOR_PACKAGE_NPM_PUBLISH), + options: expect.any(Object), + }); + }); + + it('should generate TARGET_PACKAGE_INSTALL with correct structure', (): void => { + const result = getPkgTargets(); + expect(result[TARGET_PACKAGE_INSTALL]).toMatchObject({ + dependsOn: expect.any(Array), + executor: expect.stringContaining(EXECUTOR_PACKAGE_NPM_INSTALL), + options: expect.any(Object), + }); + }); +}); From 8da9a7031005b6096a98fa3dcbf27af050228d26 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:24:04 +0100 Subject: [PATCH 15/35] docs: add createProjectConfiguration --- .../src/plugin/targets/create-targets.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts index d5ae71e8..3bf09873 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts @@ -9,6 +9,24 @@ import { } from './environment.targets'; import { getPkgTargets, isPkgProject } from './package.targets'; +/** + * Generates a project configuration with targets and namedInputs. + * + * If the project is an environment project - `isEnvProject`(), + * wraps the results of `verdaccioTargets()`, `getEnvTargets()`, + *`updateEnvTargetNames()`, and namedInputs + * + * If the project is a publishable project - `isPkgProject()`, + * wraps the results of `getPkgTargets()`, and namedInputs + * + * Otherwise, returns and empty object (early return) + * + * Logs warnings for missing implicit dependencies in environment projects. + * + * @param projectConfiguration + * @param options + * @returns A partial project configuration with targets and namedInputs. + */ export function createProjectConfiguration( projectConfiguration: ProjectConfiguration, options: NxVerdaccioCreateNodeOptions From b8a082dbedc9f31001767b52a09ad72babcccad2 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:24:53 +0100 Subject: [PATCH 16/35] docs: createProjectConfiguration docs formatting --- projects/nx-verdaccio/src/plugin/targets/create-targets.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts index 3bf09873..f81d55af 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts @@ -47,8 +47,10 @@ export function createProjectConfiguration( /** * Unfortunately namedInputs are not picked up by tasks graph: Error: Input 'build-artifacts' is not defined - * When you pass your own namedInputs (like you would in a project.json file) via the inferred tasks plugin, the tasks pipeline ignores them and throws this error. - * Some Nx plugins use the default namedInput, probably for that reason, but I'm concerned that if developers change those inputs, it might lead to undesired behavior. + * When you pass your own namedInputs (like you would in a project.json file) via the inferred tasks plugin, + * the tasks pipeline ignores them and throws this error. + * Some Nx plugins use the default namedInput, probably for that reason, + * but I'm concerned that if developers change those inputs, it might lead to undesired behavior. * @todo investigate if there is a way to pass namedInputs to the tasks graph */ const namedInputs: ProjectConfiguration['namedInputs'] = { From 25501d37a860a36ce6c1bc7c11c69694bd3f93f9 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:31:41 +0100 Subject: [PATCH 17/35] docs: add isPkgProject --- .../nx-verdaccio/src/plugin/targets/package.targets.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts index dc6047cd..6bdd1eb4 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts @@ -7,6 +7,16 @@ import { EXECUTOR_PACKAGE_NPM_INSTALL } from '../../executors/pkg-install/consta export const TARGET_PACKAGE_INSTALL = 'nxv-pkg-install'; export const TARGET_PACKAGE_PUBLISH = 'nxv-pkg-publish'; + +/** + * Determines if the given project is a publishable project. + * A project qualifies as a publishable if it's of type 'library' (early return if it's not) + * and, when options tag filters are provided, and they have match with any config tag. + * + * @param projectConfig + * @param options + * @returns `true` if the project is a publishable; otherwise, `false`. + */ export function isPkgProject( projectConfig: ProjectConfiguration, options: NormalizedCreateNodeOptions['packages'] From b00c0cd3f4170a0b81d53ae8c32b7d50f7b81055 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:35:36 +0100 Subject: [PATCH 18/35] docs: add getPkgTargets --- .../nx-verdaccio/src/plugin/targets/package.targets.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts index 6bdd1eb4..1f1f561d 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts @@ -39,6 +39,13 @@ export function isPkgProject( return true; } +/** + * Creates package-related targets for build pipelines. + * Includes `TARGET_PACKAGE_PUBLISH` and `TARGET_PACKAGE_INSTALL` targets, + * each with targets they depend on. + * + * @returns A record of package targets with their configurations. + */ export function getPkgTargets(): Record { return { [TARGET_PACKAGE_PUBLISH]: { From 1e3d7d3a89efc528aa14c9ab2381bf475989241f Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:48:00 +0100 Subject: [PATCH 19/35] self-review: test names polish, add missing structure test --- .../targets/create-targets.unit-test.ts | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 4274a626..9f68e1b8 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -129,12 +129,12 @@ describe('createProjectConfiguration', (): void => { expect(result).toStrictEqual({}); }); - it('should log warn if isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { + it('should log warn if isE2eProject and implicitDependencies are empty', (): void => { createProjectConfiguration(projectConfiguration, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); }); - it('should not log warn if isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { + it('should not log warn if isE2eProject and implicitDependencies are not empty', (): void => { const configWithImplicitDependencies = { ...projectConfiguration, implicitDependencies, @@ -143,7 +143,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if !isE2eProject and projectConfiguration.implicitDependencies?.length', (): void => { + it('should not log warn if !isE2eProject and implicitDependencies are not empty', (): void => { isEnvProjectSpy.mockReturnValue(false); const configWithImplicitDependencies = { ...projectConfiguration, @@ -153,7 +153,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if !isE2eProject and !projectConfiguration.implicitDependencies?.length', (): void => { + it('should not log warn if !isE2eProject and implicitDependencies are empty', (): void => { isEnvProjectSpy.mockReturnValue(false); createProjectConfiguration(projectConfiguration, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); @@ -174,6 +174,23 @@ describe('createProjectConfiguration', (): void => { }); }); + it('should generate configuration with correct structure if !isE2eProject and isPublishableProject', (): void => { + const result = createProjectConfiguration(projectConfiguration, options); + expect(result).toMatchObject({ + namedInputs: expect.any(Object), + targets: expect.any(Object), + }); + }); + + it('should generate configuration with correct structure if isE2eProject and !isPublishableProject', (): void => { + isPkgSpy.mockReturnValue(false); + const result = createProjectConfiguration(projectConfiguration, options); + expect(result).toMatchObject({ + namedInputs: expect.any(Object), + targets: expect.any(Object), + }); + }); + it('should generate targets with correct structure if isE2eProject and !isPublishableProject', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); @@ -190,14 +207,11 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate nameInputs with correct structure and data', (): void => { + it('should generate targets with correct structure if !isE2eProject and isPublishableProject', (): void => { const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toMatchObject({ - namedInputs: expect.any(Object), - targets: { - [TARGET_PACKAGE_PUBLISH]: expect.any(Object), - [TARGET_PACKAGE_INSTALL]: expect.any(Object), - }, + expect(result['targets']).toMatchObject({ + [TARGET_PACKAGE_PUBLISH]: expect.any(Object), + [TARGET_PACKAGE_INSTALL]: expect.any(Object), }); }); From 164cf8fa0b57a6febe5fe85f5c39d5ee37e37f96 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Fri, 10 Jan 2025 09:53:03 +0100 Subject: [PATCH 20/35] self-review: add regex for executor --- .../src/plugin/targets/package.targets.unit-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 2741d428..4571a266 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -81,7 +81,7 @@ describe('getPkgTargets', (): void => { const result = getPkgTargets(); expect(result[TARGET_PACKAGE_PUBLISH]).toMatchObject({ dependsOn: expect.any(Array), - executor: expect.stringContaining(EXECUTOR_PACKAGE_NPM_PUBLISH), + executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)), options: expect.any(Object), }); }); @@ -90,7 +90,7 @@ describe('getPkgTargets', (): void => { const result = getPkgTargets(); expect(result[TARGET_PACKAGE_INSTALL]).toMatchObject({ dependsOn: expect.any(Array), - executor: expect.stringContaining(EXECUTOR_PACKAGE_NPM_INSTALL), + executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)), options: expect.any(Object), }); }); From 5bcc40d88b6480e271d3799d8d696764b0fe2211 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 17:15:24 +0100 Subject: [PATCH 21/35] docs: rephrasing, formatting --- .../src/plugin/targets/create-targets.ts | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts index f81d55af..49bd8c57 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts @@ -10,22 +10,22 @@ import { import { getPkgTargets, isPkgProject } from './package.targets'; /** - * Generates a project configuration with targets and namedInputs. + * Generates a project configuration partial including `targets` and `namedInputs`. * - * If the project is an environment project - `isEnvProject`(), - * wraps the results of `verdaccioTargets()`, `getEnvTargets()`, - *`updateEnvTargetNames()`, and namedInputs + * If the project is an environment project, derived by `isEnvProject()`, + * It returns the results of `verdaccioTargets()`, `getEnvTargets()`, + *`updateEnvTargetNames()` under `targets`, and `namedInputs` * - * If the project is a publishable project - `isPkgProject()`, - * wraps the results of `getPkgTargets()`, and namedInputs + * If the project is a publishable project, derived by `isPkgProject()`, + * it returns the results of `getPkgTargets()`, and `namedInputs` * - * Otherwise, returns and empty object (early return) + * Otherwise, it returns an empty object (as early exit) * - * Logs warnings for missing implicit dependencies in environment projects. + * Additionally, it logs warnings for missing implicit dependencies in environment projects. * * @param projectConfiguration * @param options - * @returns A partial project configuration with targets and namedInputs. + * @returns A partial project configuration with `targets` and `namedInputs`. */ export function createProjectConfiguration( projectConfiguration: ProjectConfiguration, @@ -46,11 +46,10 @@ export function createProjectConfiguration( } /** - * Unfortunately namedInputs are not picked up by tasks graph: Error: Input 'build-artifacts' is not defined - * When you pass your own namedInputs (like you would in a project.json file) via the inferred tasks plugin, - * the tasks pipeline ignores them and throws this error. - * Some Nx plugins use the default namedInput, probably for that reason, - * but I'm concerned that if developers change those inputs, it might lead to undesired behavior. + * When you pass your own `namedInputs` (like you would in a `project.json` file) + * via the inferred tasks plugin, the tasks pipeline ignores them and throws this error. + * Some Nx plugins use the default `namedInput`, probably for that reason, + * but I'm concerned that if developers change those inputs, it might lead to undesired behaviour. * @todo investigate if there is a way to pass namedInputs to the tasks graph */ const namedInputs: ProjectConfiguration['namedInputs'] = { From ae25a1f814a5b5a3440a38a386a118e6f9a1ac97 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 17:24:08 +0100 Subject: [PATCH 22/35] tests: create-targets change negations to `is false` --- .../plugin/targets/create-targets.unit-test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 9f68e1b8..643c4735 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -122,7 +122,7 @@ describe('createProjectConfiguration', (): void => { ); }); - it('should return empty object if !isE2eProject and !isPublishableProject', (): void => { + it('should return empty object if isE2eProject and isPublishableProject are false', (): void => { isEnvProjectSpy.mockReturnValue(false); isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); @@ -143,7 +143,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if !isE2eProject and implicitDependencies are not empty', (): void => { + it('should not log warn if isE2eProject is false and implicitDependencies are not empty', (): void => { isEnvProjectSpy.mockReturnValue(false); const configWithImplicitDependencies = { ...projectConfiguration, @@ -153,7 +153,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if !isE2eProject and implicitDependencies are empty', (): void => { + it('should not log warn if isE2eProject is false and implicitDependencies are empty', (): void => { isEnvProjectSpy.mockReturnValue(false); createProjectConfiguration(projectConfiguration, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); @@ -167,14 +167,14 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate project configuration with targets if !isE2eProject and isPublishableProject', (): void => { + it('should generate project configuration with targets if isE2eProject is false and isPublishableProject', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ targets: expect.any(Object), }); }); - it('should generate configuration with correct structure if !isE2eProject and isPublishableProject', (): void => { + it('should generate configuration with correct structure if isE2eProject is false and isPublishableProject', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), @@ -182,7 +182,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate configuration with correct structure if isE2eProject and !isPublishableProject', (): void => { + it('should generate configuration with correct structure if isE2eProject and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ @@ -191,7 +191,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate targets with correct structure if isE2eProject and !isPublishableProject', (): void => { + it('should generate targets with correct structure if isE2eProject and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ @@ -207,7 +207,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate targets with correct structure if !isE2eProject and isPublishableProject', (): void => { + it('should generate targets with correct structure if isE2eProject is false and isPublishableProject', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), From 21ecc4bebe2f6a0068ee48ed0281aec100f29eef Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 17:29:41 +0100 Subject: [PATCH 23/35] tests: add is true to boolean variable to remain consistent with is false --- .../src/plugin/targets/create-targets.unit-test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 643c4735..1922621b 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -129,12 +129,12 @@ describe('createProjectConfiguration', (): void => { expect(result).toStrictEqual({}); }); - it('should log warn if isE2eProject and implicitDependencies are empty', (): void => { + it('should log warn if isE2eProject is true and implicitDependencies are empty', (): void => { createProjectConfiguration(projectConfiguration, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); }); - it('should not log warn if isE2eProject and implicitDependencies are not empty', (): void => { + it('should not log warn if isE2eProject is true and implicitDependencies are not empty', (): void => { const configWithImplicitDependencies = { ...projectConfiguration, implicitDependencies, @@ -159,7 +159,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should generate project configuration with namedInputs and targets if isE2eProject and isPublishableProject', (): void => { + it('should generate project configuration with namedInputs and targets if isE2eProject and isPublishableProject are true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), @@ -174,7 +174,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate configuration with correct structure if isE2eProject is false and isPublishableProject', (): void => { + it('should generate configuration with correct structure if isE2eProject is false and isPublishableProject is true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), @@ -182,7 +182,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate configuration with correct structure if isE2eProject and isPublishableProject is false', (): void => { + it('should generate configuration with correct structure if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ @@ -191,7 +191,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate targets with correct structure if isE2eProject and isPublishableProject is false', (): void => { + it('should generate targets with correct structure if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ @@ -207,7 +207,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate targets with correct structure if isE2eProject is false and isPublishableProject', (): void => { + it('should generate targets with correct structure if isE2eProject is false and isPublishableProject is true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), From 1ab50d635a92bd80698264778cce461cda3e4457 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 17:34:17 +0100 Subject: [PATCH 24/35] tests: change empty/not empty to given/not given --- .../src/plugin/targets/create-targets.unit-test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 1922621b..dbcaf48d 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -134,7 +134,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); }); - it('should not log warn if isE2eProject is true and implicitDependencies are not empty', (): void => { + it('should not log warn if isE2eProject is true and implicitDependencies are given', (): void => { const configWithImplicitDependencies = { ...projectConfiguration, implicitDependencies, @@ -143,7 +143,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if isE2eProject is false and implicitDependencies are not empty', (): void => { + it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { isEnvProjectSpy.mockReturnValue(false); const configWithImplicitDependencies = { ...projectConfiguration, @@ -153,7 +153,7 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should not log warn if isE2eProject is false and implicitDependencies are empty', (): void => { + it('should not log warn if isE2eProject is false and implicitDependencies are not given', (): void => { isEnvProjectSpy.mockReturnValue(false); createProjectConfiguration(projectConfiguration, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); From 7920a8599742c2b821ce7ee4e76a9185a932f722 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 17:48:28 +0100 Subject: [PATCH 25/35] tests: change `configuration with correct structure` to `a config`, remove `correct structure` for consistency, add missing mockReturnFalse to false positive test --- .../targets/create-targets.unit-test.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index dbcaf48d..8a503389 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -159,22 +159,16 @@ describe('createProjectConfiguration', (): void => { expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); - it('should generate project configuration with namedInputs and targets if isE2eProject and isPublishableProject are true', (): void => { - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toMatchObject({ - namedInputs: expect.any(Object), - targets: expect.any(Object), - }); - }); - - it('should generate project configuration with targets if isE2eProject is false and isPublishableProject', (): void => { + it('should generate a config if isE2eProject and isPublishableProject are true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ targets: expect.any(Object), + namedInputs: expect.any(Object), }); }); - it('should generate configuration with correct structure if isE2eProject is false and isPublishableProject is true', (): void => { + it('should generate a config if isE2eProject is true and isPublishableProject is false', (): void => { + isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ namedInputs: expect.any(Object), @@ -182,16 +176,15 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate configuration with correct structure if isE2eProject is true and isPublishableProject is false', (): void => { - isPkgSpy.mockReturnValue(false); + it('should generate a config if isE2eProject is false and isPublishableProject is true', (): void => { + isEnvProjectSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ - namedInputs: expect.any(Object), targets: expect.any(Object), }); }); - it('should generate targets with correct structure if isE2eProject is true and isPublishableProject is false', (): void => { + it('should generate targets if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ @@ -207,7 +200,7 @@ describe('createProjectConfiguration', (): void => { }); }); - it('should generate targets with correct structure if isE2eProject is false and isPublishableProject is true', (): void => { + it('should generate targets if isE2eProject is false and isPublishableProject is true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result['targets']).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), From c801c4c36357cc40d61a73666d3a4353178b9d37 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:00:49 +0100 Subject: [PATCH 26/35] docs: remove implementation details --- .../nx-verdaccio/src/plugin/targets/package.targets.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts index 1f1f561d..072af040 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts @@ -9,9 +9,9 @@ export const TARGET_PACKAGE_PUBLISH = 'nxv-pkg-publish'; /** - * Determines if the given project is a publishable project. - * A project qualifies as a publishable if it's of type 'library' (early return if it's not) - * and, when options tag filters are provided, and they have match with any config tag. + * Determines if the given project is a `publishable` package. + * A project qualifies as a `publishable` if it's of type 'library'. + * If tag filters are provided only projects passing the filter will return true. * * @param projectConfig * @param options @@ -41,8 +41,7 @@ export function isPkgProject( /** * Creates package-related targets for build pipelines. - * Includes `TARGET_PACKAGE_PUBLISH` and `TARGET_PACKAGE_INSTALL` targets, - * each with targets they depend on. + * Includes `TARGET_PACKAGE_PUBLISH` and `TARGET_PACKAGE_INSTALL` target configurations. * * @returns A record of package targets with their configurations. */ From 601038ae828be54cdd02c2e717b0c3f8a59391b1 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:05:07 +0100 Subject: [PATCH 27/35] docs: change expect.any(Object) to {}, as options are always an empty object --- .../src/plugin/targets/package.targets.unit-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 4571a266..87fd02eb 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -82,7 +82,7 @@ describe('getPkgTargets', (): void => { expect(result[TARGET_PACKAGE_PUBLISH]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)), - options: expect.any(Object), + options: {}, }); }); @@ -91,7 +91,7 @@ describe('getPkgTargets', (): void => { expect(result[TARGET_PACKAGE_INSTALL]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)), - options: expect.any(Object), + options: {}, }); }); }); From 2c1dd13121e2e4387acf5746f3a394889258abd0 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:34:39 +0100 Subject: [PATCH 28/35] tests: getPkgTargets add dependsOn check for both targets --- .../targets/package.targets.unit-test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 87fd02eb..6acd4759 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -86,6 +86,18 @@ describe('getPkgTargets', (): void => { }); }); + it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { + const result = getPkgTargets(); + expect(result[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ + { target: 'build', params: 'forward' }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + ]); + }); + it('should generate TARGET_PACKAGE_INSTALL with correct structure', (): void => { const result = getPkgTargets(); expect(result[TARGET_PACKAGE_INSTALL]).toMatchObject({ @@ -94,4 +106,19 @@ describe('getPkgTargets', (): void => { options: {}, }); }); + + it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { + const result = getPkgTargets(); + expect(result[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ + { + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_INSTALL, + params: 'forward', + }, + ]); + }); }); From 0f87763c3f6ba26ba1e0cb08c8d6ce16fb1b1844 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:43:07 +0100 Subject: [PATCH 29/35] self-review: grouping of test by categories: generation, unhappy path, happy path, spies, mock --- .../targets/create-targets.unit-test.ts | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 8a503389..56b32566 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -94,71 +94,6 @@ describe('createProjectConfiguration', (): void => { updateEnvTargetNamesSpy.mockRestore(); }); - it('should call normalizeCreateNodesOptions ones with projectConfiguration and options', (): void => { - createProjectConfiguration(projectConfiguration, options); - expect( - normalizeCreateNodesSpyModule.normalizeCreateNodesOptions - ).toHaveBeenCalledOnce(); - expect( - normalizeCreateNodesSpyModule.normalizeCreateNodesOptions - ).toHaveBeenCalledWith(options); - }); - - it('should call isEnvProject ones with projectConfiguration and environments', (): void => { - createProjectConfiguration(projectConfiguration, options); - expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledOnce(); - expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledWith( - projectConfiguration, - normalizedOptions['environments'] - ); - }); - - it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { - createProjectConfiguration(projectConfiguration, options); - expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledOnce(); - expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledWith( - projectConfiguration, - normalizedOptions['packages'] - ); - }); - - it('should return empty object if isE2eProject and isPublishableProject are false', (): void => { - isEnvProjectSpy.mockReturnValue(false); - isPkgSpy.mockReturnValue(false); - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toStrictEqual({}); - }); - - it('should log warn if isE2eProject is true and implicitDependencies are empty', (): void => { - createProjectConfiguration(projectConfiguration, options); - expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); - }); - - it('should not log warn if isE2eProject is true and implicitDependencies are given', (): void => { - const configWithImplicitDependencies = { - ...projectConfiguration, - implicitDependencies, - }; - createProjectConfiguration(configWithImplicitDependencies, options); - expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); - }); - - it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { - isEnvProjectSpy.mockReturnValue(false); - const configWithImplicitDependencies = { - ...projectConfiguration, - implicitDependencies, - }; - createProjectConfiguration(configWithImplicitDependencies, options); - expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); - }); - - it('should not log warn if isE2eProject is false and implicitDependencies are not given', (): void => { - isEnvProjectSpy.mockReturnValue(false); - createProjectConfiguration(projectConfiguration, options); - expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); - }); - it('should generate a config if isE2eProject and isPublishableProject are true', (): void => { const result = createProjectConfiguration(projectConfiguration, options); expect(result).toMatchObject({ @@ -208,6 +143,41 @@ describe('createProjectConfiguration', (): void => { }); }); + it('should return an empty object if isE2eProject and isPublishableProject are false', (): void => { + isEnvProjectSpy.mockReturnValue(false); + isPkgSpy.mockReturnValue(false); + const result = createProjectConfiguration(projectConfiguration, options); + expect(result).toStrictEqual({}); + }); + + it('should call normalizeCreateNodesOptions ones with projectConfiguration and options', (): void => { + createProjectConfiguration(projectConfiguration, options); + expect( + normalizeCreateNodesSpyModule.normalizeCreateNodesOptions + ).toHaveBeenCalledOnce(); + expect( + normalizeCreateNodesSpyModule.normalizeCreateNodesOptions + ).toHaveBeenCalledWith(options); + }); + + it('should call isEnvProject ones with projectConfiguration and environments', (): void => { + createProjectConfiguration(projectConfiguration, options); + expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledOnce(); + expect(environmentTargetsModule.isEnvProject).toHaveBeenCalledWith( + projectConfiguration, + normalizedOptions['environments'] + ); + }); + + it('should call isPublishableProject ones with projectConfiguration and packages', (): void => { + createProjectConfiguration(projectConfiguration, options); + expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledOnce(); + expect(packageTargetsSpyModule.isPkgProject).toHaveBeenCalledWith( + projectConfiguration, + normalizedOptions['packages'] + ); + }); + it('should call verdaccioTargets ones with correct arguments', (): void => { createProjectConfiguration(projectConfiguration, options); expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledOnce(); @@ -236,4 +206,34 @@ describe('createProjectConfiguration', (): void => { normalizedOptions.environments ); }); + + it('should log warn if isE2eProject is true and implicitDependencies are empty', (): void => { + createProjectConfiguration(projectConfiguration, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledOnce(); + }); + + it('should not log warn if isE2eProject is true and implicitDependencies are given', (): void => { + const configWithImplicitDependencies = { + ...projectConfiguration, + implicitDependencies, + }; + createProjectConfiguration(configWithImplicitDependencies, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); + }); + + it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { + isEnvProjectSpy.mockReturnValue(false); + const configWithImplicitDependencies = { + ...projectConfiguration, + implicitDependencies, + }; + createProjectConfiguration(configWithImplicitDependencies, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); + }); + + it('should not log warn if isE2eProject is false and implicitDependencies are not given', (): void => { + isEnvProjectSpy.mockReturnValue(false); + createProjectConfiguration(projectConfiguration, options); + expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); + }); }); From 38878f744f0a5c9c93ac99013af45865ed13176d Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:46:37 +0100 Subject: [PATCH 30/35] self-review: memory optimization - remove consts that were used only once --- .../targets/create-targets.unit-test.ts | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 56b32566..9d091d0f 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -95,8 +95,7 @@ describe('createProjectConfiguration', (): void => { }); it('should generate a config if isE2eProject and isPublishableProject are true', (): void => { - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toMatchObject({ + expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ targets: expect.any(Object), namedInputs: expect.any(Object), }); @@ -104,8 +103,7 @@ describe('createProjectConfiguration', (): void => { it('should generate a config if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toMatchObject({ + expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ namedInputs: expect.any(Object), targets: expect.any(Object), }); @@ -113,16 +111,14 @@ describe('createProjectConfiguration', (): void => { it('should generate a config if isE2eProject is false and isPublishableProject is true', (): void => { isEnvProjectSpy.mockReturnValue(false); - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toMatchObject({ + expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ targets: expect.any(Object), }); }); it('should generate targets if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); - const result = createProjectConfiguration(projectConfiguration, options); - expect(result['targets']).toMatchObject({ + expect(createProjectConfiguration(projectConfiguration, options)['targets']).toMatchObject({ build: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), @@ -136,8 +132,7 @@ describe('createProjectConfiguration', (): void => { }); it('should generate targets if isE2eProject is false and isPublishableProject is true', (): void => { - const result = createProjectConfiguration(projectConfiguration, options); - expect(result['targets']).toMatchObject({ + expect(createProjectConfiguration(projectConfiguration, options)['targets']).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), [TARGET_PACKAGE_INSTALL]: expect.any(Object), }); @@ -146,8 +141,7 @@ describe('createProjectConfiguration', (): void => { it('should return an empty object if isE2eProject and isPublishableProject are false', (): void => { isEnvProjectSpy.mockReturnValue(false); isPkgSpy.mockReturnValue(false); - const result = createProjectConfiguration(projectConfiguration, options); - expect(result).toStrictEqual({}); + expect(createProjectConfiguration(projectConfiguration, options)).toStrictEqual({}); }); it('should call normalizeCreateNodesOptions ones with projectConfiguration and options', (): void => { @@ -213,21 +207,19 @@ describe('createProjectConfiguration', (): void => { }); it('should not log warn if isE2eProject is true and implicitDependencies are given', (): void => { - const configWithImplicitDependencies = { + createProjectConfiguration({ ...projectConfiguration, implicitDependencies, - }; - createProjectConfiguration(configWithImplicitDependencies, options); + }, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { isEnvProjectSpy.mockReturnValue(false); - const configWithImplicitDependencies = { + createProjectConfiguration({ ...projectConfiguration, implicitDependencies, - }; - createProjectConfiguration(configWithImplicitDependencies, options); + }, options); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); From 6724a1883eb49f6297ba339b714cba31e7bc0f60 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:48:06 +0100 Subject: [PATCH 31/35] self-review: getPkgTargets memory optimization - remove consts that were used only once --- .../plugin/targets/package.targets.unit-test.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 6acd4759..80612fc6 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -70,16 +70,14 @@ describe('isPkgProject', () => { describe('getPkgTargets', (): void => { it('should generate PkgTargets with correct structure', (): void => { - const result = getPkgTargets(); - expect(result).toMatchObject({ + expect(getPkgTargets()).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), [TARGET_PACKAGE_INSTALL]: expect.any(Object), }); }); it('should generate TARGET_PACKAGE_PUBLISH with correct structure', (): void => { - const result = getPkgTargets(); - expect(result[TARGET_PACKAGE_PUBLISH]).toMatchObject({ + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)), options: {}, @@ -87,8 +85,7 @@ describe('getPkgTargets', (): void => { }); it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { - const result = getPkgTargets(); - expect(result[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ { target: 'build', params: 'forward' }, { projects: 'dependencies', @@ -99,8 +96,7 @@ describe('getPkgTargets', (): void => { }); it('should generate TARGET_PACKAGE_INSTALL with correct structure', (): void => { - const result = getPkgTargets(); - expect(result[TARGET_PACKAGE_INSTALL]).toMatchObject({ + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)), options: {}, @@ -108,8 +104,7 @@ describe('getPkgTargets', (): void => { }); it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { - const result = getPkgTargets(); - expect(result[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ { target: TARGET_PACKAGE_PUBLISH, params: 'forward', From 7de15894cc5d43576c0fc74c181af100a3649dcf Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:49:09 +0100 Subject: [PATCH 32/35] self-review: delete `with correct structure` for consistency with create targets tests --- .../src/plugin/targets/package.targets.unit-test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 80612fc6..58e33036 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -69,14 +69,14 @@ describe('isPkgProject', () => { }); describe('getPkgTargets', (): void => { - it('should generate PkgTargets with correct structure', (): void => { + it('should generate PkgTargets', (): void => { expect(getPkgTargets()).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), [TARGET_PACKAGE_INSTALL]: expect.any(Object), }); }); - it('should generate TARGET_PACKAGE_PUBLISH with correct structure', (): void => { + it('should generate TARGET_PACKAGE_PUBLISH', (): void => { expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)), @@ -95,7 +95,7 @@ describe('getPkgTargets', (): void => { ]); }); - it('should generate TARGET_PACKAGE_INSTALL with correct structure', (): void => { + it('should generate TARGET_PACKAGE_INSTALL', (): void => { expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ dependsOn: expect.any(Array), executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)), From a39e93ec24fa03d93d3551071cf67367f3dba4de Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:54:52 +0100 Subject: [PATCH 33/35] self-review: make generation tests to check one field of object or whole object structure --- .../targets/package.targets.unit-test.ts | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 58e33036..3a3fd64d 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -79,41 +79,50 @@ describe('getPkgTargets', (): void => { it('should generate TARGET_PACKAGE_PUBLISH', (): void => { expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH]).toMatchObject({ dependsOn: expect.any(Array), - executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)), + executor: expect.any(String), options: {}, }); }); - it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ - { target: 'build', params: 'forward' }, - { - projects: 'dependencies', - target: TARGET_PACKAGE_PUBLISH, - params: 'forward', - }, - ]); + it('should generate TARGET_PACKAGE_PUBLISH executor', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)) }); - it('should generate TARGET_PACKAGE_INSTALL', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ - dependsOn: expect.any(Array), - executor: expect.stringMatching(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)), - options: {}, + it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ + { target: 'build', params: 'forward' }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + ]); }); + + it('should generate TARGET_PACKAGE_INSTALL', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ + dependsOn: expect.any(Array), + executor: expect.any(String), + options: {}, + }); + }); + + it('should generate TARGET_PACKAGE_INSTALL executor', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)) }); - it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ - { - target: TARGET_PACKAGE_PUBLISH, - params: 'forward', - }, - { - projects: 'dependencies', - target: TARGET_PACKAGE_INSTALL, - params: 'forward', - }, - ]); + it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ + { + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_INSTALL, + params: 'forward', + }, + ]); + }); }); -}); + From 555005f03530c98ffa28b51988f1c6eae3627242 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 18:56:06 +0100 Subject: [PATCH 34/35] self-review: nx format --- .../targets/create-targets.unit-test.ts | 46 ++++++++---- .../src/plugin/targets/package.targets.ts | 1 - .../targets/package.targets.unit-test.ts | 72 ++++++++++--------- 3 files changed, 70 insertions(+), 49 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts index 9d091d0f..a7ebe1ee 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts @@ -95,7 +95,9 @@ describe('createProjectConfiguration', (): void => { }); it('should generate a config if isE2eProject and isPublishableProject are true', (): void => { - expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ + expect( + createProjectConfiguration(projectConfiguration, options) + ).toMatchObject({ targets: expect.any(Object), namedInputs: expect.any(Object), }); @@ -103,7 +105,9 @@ describe('createProjectConfiguration', (): void => { it('should generate a config if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); - expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ + expect( + createProjectConfiguration(projectConfiguration, options) + ).toMatchObject({ namedInputs: expect.any(Object), targets: expect.any(Object), }); @@ -111,14 +115,18 @@ describe('createProjectConfiguration', (): void => { it('should generate a config if isE2eProject is false and isPublishableProject is true', (): void => { isEnvProjectSpy.mockReturnValue(false); - expect(createProjectConfiguration(projectConfiguration, options)).toMatchObject({ + expect( + createProjectConfiguration(projectConfiguration, options) + ).toMatchObject({ targets: expect.any(Object), }); }); it('should generate targets if isE2eProject is true and isPublishableProject is false', (): void => { isPkgSpy.mockReturnValue(false); - expect(createProjectConfiguration(projectConfiguration, options)['targets']).toMatchObject({ + expect( + createProjectConfiguration(projectConfiguration, options)['targets'] + ).toMatchObject({ build: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_START]: expect.any(Object), [TARGET_ENVIRONMENT_VERDACCIO_STOP]: expect.any(Object), @@ -132,7 +140,9 @@ describe('createProjectConfiguration', (): void => { }); it('should generate targets if isE2eProject is false and isPublishableProject is true', (): void => { - expect(createProjectConfiguration(projectConfiguration, options)['targets']).toMatchObject({ + expect( + createProjectConfiguration(projectConfiguration, options)['targets'] + ).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), [TARGET_PACKAGE_INSTALL]: expect.any(Object), }); @@ -141,7 +151,9 @@ describe('createProjectConfiguration', (): void => { it('should return an empty object if isE2eProject and isPublishableProject are false', (): void => { isEnvProjectSpy.mockReturnValue(false); isPkgSpy.mockReturnValue(false); - expect(createProjectConfiguration(projectConfiguration, options)).toStrictEqual({}); + expect( + createProjectConfiguration(projectConfiguration, options) + ).toStrictEqual({}); }); it('should call normalizeCreateNodesOptions ones with projectConfiguration and options', (): void => { @@ -207,19 +219,25 @@ describe('createProjectConfiguration', (): void => { }); it('should not log warn if isE2eProject is true and implicitDependencies are given', (): void => { - createProjectConfiguration({ - ...projectConfiguration, - implicitDependencies, - }, options); + createProjectConfiguration( + { + ...projectConfiguration, + implicitDependencies, + }, + options + ); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { isEnvProjectSpy.mockReturnValue(false); - createProjectConfiguration({ - ...projectConfiguration, - implicitDependencies, - }, options); + createProjectConfiguration( + { + ...projectConfiguration, + implicitDependencies, + }, + options + ); expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); }); diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts index 072af040..28d1b08d 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.ts @@ -7,7 +7,6 @@ import { EXECUTOR_PACKAGE_NPM_INSTALL } from '../../executors/pkg-install/consta export const TARGET_PACKAGE_INSTALL = 'nxv-pkg-install'; export const TARGET_PACKAGE_PUBLISH = 'nxv-pkg-publish'; - /** * Determines if the given project is a `publishable` package. * A project qualifies as a `publishable` if it's of type 'library'. diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index 3a3fd64d..efea027a 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -69,6 +69,7 @@ describe('isPkgProject', () => { }); describe('getPkgTargets', (): void => { + it('should generate PkgTargets', (): void => { expect(getPkgTargets()).toMatchObject({ [TARGET_PACKAGE_PUBLISH]: expect.any(Object), @@ -84,45 +85,48 @@ describe('getPkgTargets', (): void => { }); }); - it('should generate TARGET_PACKAGE_PUBLISH executor', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`)) + it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ + { target: 'build', params: 'forward' }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + ]); }); - it('should generate TARGET_PACKAGE_PUBLISH dependsOn', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].dependsOn).toEqual([ - { target: 'build', params: 'forward' }, - { - projects: 'dependencies', - target: TARGET_PACKAGE_PUBLISH, - params: 'forward', - }, - ]); - }); + it('should generate TARGET_PACKAGE_PUBLISH executor', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches( + new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_PUBLISH}`) + ); + }); - it('should generate TARGET_PACKAGE_INSTALL', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ - dependsOn: expect.any(Array), - executor: expect.any(String), - options: {}, - }); + it('should generate TARGET_PACKAGE_INSTALL', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL]).toMatchObject({ + dependsOn: expect.any(Array), + executor: expect.any(String), + options: {}, }); - - it('should generate TARGET_PACKAGE_INSTALL executor', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches(new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`)) }); - it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ - { - target: TARGET_PACKAGE_PUBLISH, - params: 'forward', - }, - { - projects: 'dependencies', - target: TARGET_PACKAGE_INSTALL, - params: 'forward', - }, - ]); - }); + it('should generate TARGET_PACKAGE_INSTALL dependsOn', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].dependsOn).toEqual([ + { + target: TARGET_PACKAGE_PUBLISH, + params: 'forward', + }, + { + projects: 'dependencies', + target: TARGET_PACKAGE_INSTALL, + params: 'forward', + }, + ]); }); + it('should generate TARGET_PACKAGE_INSTALL executor', (): void => { + expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches( + new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`) + ); + }); +}); From a966b80967880649ce1fde322a0c7607ffdd97b8 Mon Sep 17 00:00:00 2001 From: adrianromanski Date: Sat, 18 Jan 2025 19:05:09 +0100 Subject: [PATCH 35/35] self-review: change TARGET_PACKAGE_PUBLISH to TARGET_PACKAGE_INSTALL --- .../src/plugin/targets/package.targets.unit-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts index efea027a..dc53cd0d 100644 --- a/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/targets/package.targets.unit-test.ts @@ -125,7 +125,7 @@ describe('getPkgTargets', (): void => { }); it('should generate TARGET_PACKAGE_INSTALL executor', (): void => { - expect(getPkgTargets()[TARGET_PACKAGE_PUBLISH].executor).matches( + expect(getPkgTargets()[TARGET_PACKAGE_INSTALL].executor).matches( new RegExp(`.+:${EXECUTOR_PACKAGE_NPM_INSTALL}`) ); });