-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: verdaccio targets failing test
- Loading branch information
1 parent
f375096
commit 97609e6
Showing
1 changed file
with
108 additions
and
57 deletions.
There are no files selected for viewing
165 changes: 108 additions & 57 deletions
165
projects/nx-verdaccio/src/plugin/targets/environment.targets.unit-test.ts
This file contains 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 |
---|---|---|
@@ -1,73 +1,124 @@ | ||
import { describe, expect } from 'vitest'; | ||
import { ProjectConfiguration } from '@nx/devkit'; | ||
import { isEnvProject } from './environment.targets'; | ||
import { isEnvProject, verdaccioTargets } from './environment.targets'; | ||
import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; | ||
import { join } from 'path'; | ||
import { PACKAGE_NAME } from '../constants'; | ||
import { EXECUTOR_ENVIRONMENT_KILL_PROCESS } from '../../executors/kill-process/constant'; | ||
|
||
describe('isEnvProject', () => { | ||
const projectConfig: ProjectConfiguration = { | ||
root: '', | ||
tags: ['env:production', 'type:library'], | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
}; | ||
const normalizedOptions: NormalizedCreateNodeOptions['environments'] = { | ||
environmentsDir: '', | ||
targetNames: ['cola', 'mock', 'build'], | ||
filterByTags: ['env:production'] | ||
}; | ||
const projectConfig: ProjectConfiguration = { | ||
root: '', | ||
tags: ['env:production', 'type:library'], | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
}; | ||
const normalizedOptions: NormalizedCreateNodeOptions['environments'] = { | ||
environmentsDir: '', | ||
targetNames: ['cola', 'mock', 'build'], | ||
filterByTags: ['env:production'] | ||
}; | ||
|
||
it('should returns false if targets missing', () => { | ||
const config = { ...projectConfig, targets: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(false); | ||
}); | ||
it('should returns false if targets missing', () => { | ||
const config = { ...projectConfig, targets: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should returns false if targetNames missing', () => { | ||
const options = {...normalizedOptions, targetNames: null} | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
}); | ||
it('should returns false if targetNames missing', () => { | ||
const options = {...normalizedOptions, targetNames: null} | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should returns false if targetNames and targets missing', () => { | ||
const config = { ...projectConfig, targets: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(false); | ||
}); | ||
it('should returns false if targetNames and targets missing', () => { | ||
const config = { ...projectConfig, targets: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should returns false if targetNames don’t match environmentTargetNames', () => { | ||
const options = { ...normalizedOptions, targetNames: ['mockTarget'] }; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
}); | ||
it('should returns false if targetNames don’t match environmentTargetNames', () => { | ||
const options = { ...normalizedOptions, targetNames: ['mockTarget'] }; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should returns true if targetNames match and no tags', () => { | ||
const config = { ...projectConfig, tags: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(true); | ||
}); | ||
it('should returns true if targetNames match and no tags', () => { | ||
const config = { ...projectConfig, tags: null }; | ||
const result = isEnvProject(config, normalizedOptions); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should returns true if targetNames match and no filterByTags', () => { | ||
const options = { | ||
...normalizedOptions, | ||
filterByTags: null | ||
}; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(true); | ||
}); | ||
it('should returns true if targetNames match and no filterByTags', () => { | ||
const options = { | ||
...normalizedOptions, | ||
filterByTags: null | ||
}; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should returns true if targetNames match and tags match filterByTags', () => { | ||
const result = isEnvProject(projectConfig, normalizedOptions); | ||
expect(result).toBe(true); | ||
}); | ||
it('should returns true if targetNames match and tags match filterByTags', () => { | ||
const result = isEnvProject(projectConfig, normalizedOptions); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should returns false if targetNames match but tags don’t match filterByTags', () => { | ||
const options = { | ||
...normalizedOptions, | ||
filterByTags: ['mock-tag-no-match'] | ||
it('should returns false if targetNames match but tags don’t match filterByTags', () => { | ||
const options = { | ||
...normalizedOptions, | ||
filterByTags: ['mock-tag-no-match'] | ||
}; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('verdaccioTargets', () => { | ||
vi.mock('path', () => ({ | ||
join: vi.fn((...args) => args.join('/')), | ||
})); | ||
vi.mock('./utils', () => ({ | ||
uniquePort: vi.fn(() => 4873), // Mocking a fixed port | ||
})); | ||
|
||
it('should generate correct Verdaccio start and stop targets', () => { | ||
const mockProjectConfig = { name: 'test-project', root: 'test' }; | ||
const mockOptions = { | ||
environmentsDir: 'environments', | ||
customOption: 'custom-value', | ||
}; | ||
const result = isEnvProject(projectConfig, options); | ||
expect(result).toBe(false); | ||
const VERDACCIO_STORAGE_DIR = 'storage'; | ||
const result = verdaccioTargets(mockProjectConfig, mockOptions); | ||
|
||
// Expected environment directory | ||
const expectedEnvironmentDir = 'environments/test-project'; | ||
|
||
expect(result).toEqual({ | ||
TARGET_ENVIRONMENT_VERDACCIO_START: { | ||
outputs: [`${expectedEnvironmentDir}/${VERDACCIO_STORAGE_DIR}`], | ||
executor: '@nx/js:verdaccio', | ||
options: { | ||
config: '.verdaccio/config.yml', | ||
port: 4873, | ||
storage: `${expectedEnvironmentDir}/${VERDACCIO_STORAGE_DIR}`, | ||
clear: true, | ||
environmentDir: expectedEnvironmentDir, | ||
projectName: 'test-project', | ||
customOption: 'custom-value', | ||
}, | ||
}, | ||
TARGET_ENVIRONMENT_VERDACCIO_STOP: { | ||
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_KILL_PROCESS}`, | ||
options: { | ||
filePath: 'environments/registry.json', | ||
customOption: 'custom-value', | ||
}, | ||
}, | ||
}); | ||
|
||
// Ensure mocked functions are called correctly | ||
expect(join).toHaveBeenCalledWith('environments', 'test-project'); | ||
}); | ||
}); |