-
Notifications
You must be signed in to change notification settings - Fork 4
Tests - Package & Create Targets #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdrianRomanski
wants to merge
35
commits into
push-based:main
Choose a base branch
from
AdrianRomanski:package-create-targets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
399ba0f
tests: add test skeleton
AdrianRomanski c0adb81
tests: add normalizeCreateNodesOptions spy and test
AdrianRomanski 73d3a51
tests: add isEnvProject spy and test
AdrianRomanski eb0390d
tests: add isPkgProject spy and test
AdrianRomanski 3a88a54
tests: should return empty object if !isE2eProject and !isPublishable…
AdrianRomanski 8a8fcf5
tests: add logger warn tests
AdrianRomanski 37b7654
tests: add project configuration top level structure
AdrianRomanski b559c85
tests: add verdaccioTargets spy and test
AdrianRomanski 49f1f3e
tests: add verdaccioTargets spy and test
AdrianRomanski ba2c40b
tests: add getEnvTargets spy and test
AdrianRomanski dcc37cd
tests: add object structure
AdrianRomanski 03697f5
tests: add updateEnvTargetNames spy and test
AdrianRomanski 16379ff
tests: code cleanup
AdrianRomanski d9a12d0
tests: getPkgTargets object structure
AdrianRomanski 8da9a70
docs: add createProjectConfiguration
AdrianRomanski b8a082d
docs: createProjectConfiguration docs formatting
AdrianRomanski 25501d3
docs: add isPkgProject
AdrianRomanski b00c0cd
docs: add getPkgTargets
AdrianRomanski 1e3d7d3
self-review: test names polish, add missing structure test
AdrianRomanski 164cf8f
self-review: add regex for executor
AdrianRomanski 5bcc40d
docs: rephrasing, formatting
AdrianRomanski ae25a1f
tests: create-targets change negations to `is false`
AdrianRomanski 21ecc4b
tests: add is true to boolean variable to remain consistent with is f…
AdrianRomanski 1ab50d6
tests: change empty/not empty to given/not given
AdrianRomanski 7920a85
tests: change `configuration with correct structure` to `a config`, r…
AdrianRomanski c801c4c
docs: remove implementation details
AdrianRomanski 601038a
docs: change expect.any(Object) to {}, as options are always an empty…
AdrianRomanski 2c1dd13
tests: getPkgTargets add dependsOn check for both targets
AdrianRomanski 0f87763
self-review: grouping of test by categories: generation, unhappy path…
AdrianRomanski 38878f7
self-review: memory optimization - remove consts that were used only …
AdrianRomanski 6724a18
self-review: getPkgTargets memory optimization - remove consts that w…
AdrianRomanski 7de1589
self-review: delete `with correct structure` for consistency with cre…
AdrianRomanski a39e93e
self-review: make generation tests to check one field of object or wh…
AdrianRomanski 555005f
self-review: nx format
AdrianRomanski a966b80
self-review: change TARGET_PACKAGE_PUBLISH to TARGET_PACKAGE_INSTALL
AdrianRomanski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
249 changes: 249 additions & 0 deletions
249
projects/nx-verdaccio/src/plugin/targets/create-targets.unit-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,249 @@ | ||||||||||||
| import { beforeEach, describe, expect, type MockInstance } from 'vitest'; | ||||||||||||
| import { type ProjectConfiguration } from '@nx/devkit'; | ||||||||||||
|
|
||||||||||||
| import * as nxDevkitMockModule from '@nx/devkit'; | ||||||||||||
|
|
||||||||||||
| import { createProjectConfiguration } from './create-targets'; | ||||||||||||
| import { | ||||||||||||
| TARGET_PACKAGE_INSTALL, | ||||||||||||
| TARGET_PACKAGE_PUBLISH, | ||||||||||||
| } from './package.targets'; | ||||||||||||
| import { | ||||||||||||
| TARGET_ENVIRONMENT_E2E, | ||||||||||||
| TARGET_ENVIRONMENT_SETUP, | ||||||||||||
| TARGET_ENVIRONMENT_INSTALL, | ||||||||||||
| TARGET_ENVIRONMENT_TEARDOWN, | ||||||||||||
| TARGET_ENVIRONMENT_BOOTSTRAP, | ||||||||||||
| TARGET_ENVIRONMENT_PUBLISH_ONLY, | ||||||||||||
| TARGET_ENVIRONMENT_VERDACCIO_STOP, | ||||||||||||
| TARGET_ENVIRONMENT_VERDACCIO_START, | ||||||||||||
| } from './environment.targets'; | ||||||||||||
|
|
||||||||||||
| import { type NxVerdaccioCreateNodeOptions } from '../schema'; | ||||||||||||
| import { type NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; | ||||||||||||
|
|
||||||||||||
| import * as packageTargetsSpyModule from './package.targets'; | ||||||||||||
| import * as environmentTargetsModule from './environment.targets'; | ||||||||||||
| import * as normalizeCreateNodesSpyModule from './../normalize-create-nodes-options'; | ||||||||||||
|
|
||||||||||||
| describe('createProjectConfiguration', (): void => { | ||||||||||||
| const implicitDependencies = ['mock-implicit-dep']; | ||||||||||||
| const projectConfiguration: ProjectConfiguration = { | ||||||||||||
| root: 'mock-root', | ||||||||||||
| name: 'unit-test-project', | ||||||||||||
| targets: { build: {} }, | ||||||||||||
| }; | ||||||||||||
| const options: NxVerdaccioCreateNodeOptions = { | ||||||||||||
| environments: { | ||||||||||||
| targetNames: ['build'], | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
| const normalizedOptions: NormalizedCreateNodeOptions = { | ||||||||||||
| environments: { | ||||||||||||
| targetNames: ['build'], | ||||||||||||
| environmentsDir: './environments', | ||||||||||||
| }, | ||||||||||||
| packages: { | ||||||||||||
| targetNames: ['test', 'lint'], | ||||||||||||
| environmentsDir: './packages', | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| vi.mock('@nx/devkit', () => { | ||||||||||||
| return { | ||||||||||||
| logger: { | ||||||||||||
| warn: vi.fn(), | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| let normalizeCreateNodesOptionsSpy: MockInstance; | ||||||||||||
| let isEnvProjectSpy: MockInstance; | ||||||||||||
| let isPkgSpy: MockInstance; | ||||||||||||
| let verdaccioTargetsSpy: MockInstance; | ||||||||||||
| let getEnvTargetsSpy: MockInstance; | ||||||||||||
| let updateEnvTargetNamesSpy: MockInstance; | ||||||||||||
|
|
||||||||||||
| beforeEach((): void => { | ||||||||||||
| normalizeCreateNodesOptionsSpy = vi | ||||||||||||
| .spyOn(normalizeCreateNodesSpyModule, 'normalizeCreateNodesOptions') | ||||||||||||
| .mockReturnValue(normalizedOptions); | ||||||||||||
| isEnvProjectSpy = vi | ||||||||||||
| .spyOn(environmentTargetsModule, 'isEnvProject') | ||||||||||||
| .mockReturnValue(true); | ||||||||||||
| isPkgSpy = vi | ||||||||||||
| .spyOn(packageTargetsSpyModule, 'isPkgProject') | ||||||||||||
| .mockReturnValue(true); | ||||||||||||
| verdaccioTargetsSpy = vi.spyOn( | ||||||||||||
| environmentTargetsModule, | ||||||||||||
| 'verdaccioTargets' | ||||||||||||
| ); | ||||||||||||
| getEnvTargetsSpy = vi.spyOn(environmentTargetsModule, 'getEnvTargets'); | ||||||||||||
| updateEnvTargetNamesSpy = vi.spyOn( | ||||||||||||
| environmentTargetsModule, | ||||||||||||
| 'updateEnvTargetNames' | ||||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| afterEach((): void => { | ||||||||||||
| normalizeCreateNodesOptionsSpy.mockRestore(); | ||||||||||||
| isEnvProjectSpy.mockRestore(); | ||||||||||||
| isPkgSpy.mockRestore(); | ||||||||||||
| verdaccioTargetsSpy.mockRestore(); | ||||||||||||
| getEnvTargetsSpy.mockRestore(); | ||||||||||||
| updateEnvTargetNamesSpy.mockRestore(); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should generate a config if isE2eProject and isPublishableProject are true', (): void => { | ||||||||||||
| expect( | ||||||||||||
| createProjectConfiguration(projectConfiguration, options) | ||||||||||||
| ).toMatchObject({ | ||||||||||||
| targets: expect.any(Object), | ||||||||||||
| namedInputs: expect.any(Object), | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should generate a config if isE2eProject is true and isPublishableProject is false', (): void => { | ||||||||||||
| isPkgSpy.mockReturnValue(false); | ||||||||||||
| expect( | ||||||||||||
| createProjectConfiguration(projectConfiguration, options) | ||||||||||||
| ).toMatchObject({ | ||||||||||||
| namedInputs: expect.any(Object), | ||||||||||||
| targets: expect.any(Object), | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should generate a config if isE2eProject is false and isPublishableProject is true', (): void => { | ||||||||||||
| isEnvProjectSpy.mockReturnValue(false); | ||||||||||||
| 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({ | ||||||||||||
| 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 targets if isE2eProject is false and isPublishableProject is true', (): void => { | ||||||||||||
| expect( | ||||||||||||
| createProjectConfiguration(projectConfiguration, options)['targets'] | ||||||||||||
| ).toMatchObject({ | ||||||||||||
| [TARGET_PACKAGE_PUBLISH]: expect.any(Object), | ||||||||||||
| [TARGET_PACKAGE_INSTALL]: expect.any(Object), | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should return an empty object if isE2eProject and isPublishableProject are false', (): void => { | ||||||||||||
| isEnvProjectSpy.mockReturnValue(false); | ||||||||||||
| isPkgSpy.mockReturnValue(false); | ||||||||||||
| expect( | ||||||||||||
| createProjectConfiguration(projectConfiguration, options) | ||||||||||||
| ).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(); | ||||||||||||
| expect(environmentTargetsModule.verdaccioTargets).toHaveBeenCalledWith( | ||||||||||||
| projectConfiguration, | ||||||||||||
| { environmentsDir: normalizedOptions.environments.environmentsDir } | ||||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should call getEnvTargets ones with correct arguments', (): void => { | ||||||||||||
| createProjectConfiguration(projectConfiguration, options); | ||||||||||||
| expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledOnce(); | ||||||||||||
| expect(environmentTargetsModule.getEnvTargets).toHaveBeenCalledWith( | ||||||||||||
| projectConfiguration, | ||||||||||||
| normalizedOptions.environments | ||||||||||||
| ); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| it('should call updateEnvTargetNames ones with correct arguments', (): void => { | ||||||||||||
| createProjectConfiguration(projectConfiguration, options); | ||||||||||||
| expect( | ||||||||||||
| environmentTargetsModule.updateEnvTargetNames | ||||||||||||
| ).toHaveBeenCalledOnce(); | ||||||||||||
| expect(environmentTargetsModule.updateEnvTargetNames).toHaveBeenCalledWith( | ||||||||||||
| projectConfiguration, | ||||||||||||
| 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 => { | ||||||||||||
| createProjectConfiguration( | ||||||||||||
| { | ||||||||||||
| ...projectConfiguration, | ||||||||||||
| implicitDependencies, | ||||||||||||
| }, | ||||||||||||
| options | ||||||||||||
| ); | ||||||||||||
| expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+229
to
+231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| it('should not log warn if isE2eProject is false and implicitDependencies are given', (): void => { | ||||||||||||
| isEnvProjectSpy.mockReturnValue(false); | ||||||||||||
| createProjectConfiguration( | ||||||||||||
| { | ||||||||||||
| ...projectConfiguration, | ||||||||||||
| implicitDependencies, | ||||||||||||
| }, | ||||||||||||
| options | ||||||||||||
| ); | ||||||||||||
| expect(nxDevkitMockModule.logger.warn).toHaveBeenCalledTimes(0); | ||||||||||||
| }); | ||||||||||||
|
Comment on lines
+241
to
+242
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
| 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); | ||||||||||||
| }); | ||||||||||||
| }); | ||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General best practices for setup spy's and configuring spy's: