-
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: add is env project basic tests
- Loading branch information
1 parent
0446e1d
commit 12e8a70
Showing
1 changed file
with
117 additions
and
56 deletions.
There are no files selected for viewing
173 changes: 117 additions & 56 deletions
173
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,61 +1,122 @@ | ||
import { describe } from 'vitest'; | ||
import { describe, expect } from 'vitest'; | ||
import { ProjectConfiguration } from '@nx/devkit'; | ||
import { isEnvProject } from './environment.targets'; | ||
import { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; | ||
|
||
describe('isEnvProject', () => { | ||
//export function isEnvProject( | ||
// projectConfig: ProjectConfiguration, | ||
// options: NormalizedCreateNodeOptions['environments'] | ||
// ): boolean { | ||
// const { tags: existingTags = [], targets } = projectConfig; | ||
// const existingTargetNames = Object.keys(targets ?? {}); | ||
// const { | ||
// filterByTags: environmentsTagFilters, | ||
// targetNames: environmentTargetNames, | ||
// } = options; | ||
// | ||
|
||
|
||
// if (!existingTargetNames || !environmentTargetNames) { | ||
// return false; | ||
// } | ||
// | ||
// if ( | ||
// existingTargetNames.some((existingTarget) => | ||
// environmentTargetNames.includes(existingTarget) | ||
// ) | ||
// ) { | ||
// if (existingTags && environmentsTagFilters) { | ||
// return existingTags.some((existingTag) => | ||
// environmentsTagFilters.includes(existingTag) | ||
// ); | ||
// } | ||
// return true; | ||
// } | ||
// | ||
// return false; | ||
// } | ||
|
||
// IT test | ||
// if (!existingTargetNames || !environmentTargetNames) { | ||
// return false; | ||
// } | ||
|
||
// IT test | ||
// if ( | ||
// existingTargetNames.some((existingTarget) => | ||
// environmentTargetNames.includes(existingTarget) | ||
// ) | ||
// ) { | ||
// IT test | ||
// if (existingTags && environmentsTagFilters) { | ||
// return existingTags.some((existingTag) => | ||
// environmentsTagFilters.includes(existingTag) | ||
// ); | ||
// } | ||
|
||
// return true; | ||
// } | ||
// IT test | ||
// // return false; | ||
const projectConfig: ProjectConfiguration = { | ||
root: '', | ||
tags: ['env:production', 'type:library'], | ||
targets: {} | ||
}; | ||
const normalizedCreateNodeOptions: NormalizedCreateNodeOptions['environments'] = { | ||
environmentsDir: '', | ||
targetNames: null, | ||
filterByTags: ['env:production'] | ||
}; | ||
|
||
it('should return false if existingTargetNames are not present', () => { | ||
const options = {...normalizedCreateNodeOptions, targetNames: ['mockTarget']} | ||
const config = {...projectConfig, targets: null} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if environmentTargetNames are not present', () => { | ||
const config = { | ||
...projectConfig, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const result = isEnvProject(config, normalizedCreateNodeOptions); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if existingTargetNames, and existingTargetNames are not present ', () => { | ||
const result = isEnvProject(projectConfig, normalizedCreateNodeOptions); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
|
||
it('should return false if none of the existingTargetNames match any of the environmentTargetNames', () => { | ||
const config = { | ||
...projectConfig, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const options = {...normalizedCreateNodeOptions, targetNames: ['mockTarget']} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return true if any existingTargetNames match environmentTargetNames and no tags', () => { | ||
// i have to set tags to null | ||
const config = { | ||
...projectConfig, | ||
tags: null, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const options = {...normalizedCreateNodeOptions, targetNames: ['cola', 'mock', 'build']} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true if any existingTargetNames match environmentTargetNames and no filterByTags', () => { | ||
// i have to set filter by tags to null | ||
const config = { | ||
...projectConfig, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const options = { | ||
...normalizedCreateNodeOptions, | ||
targetNames: ['cola', 'mock', 'build'], | ||
filterByTags: null | ||
} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true if any existingTargetNames match environmentTargetNames and existingTags are present with environmentsTagFilters, and any existingTags match any environmentsTagFilters', () => { | ||
const config = { | ||
...projectConfig, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const options = { | ||
...normalizedCreateNodeOptions, | ||
targetNames: ['cola', 'mock', 'build'], | ||
} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false if any existingTargetNames match environmentTargetNames and existingTags are present with environmentsTagFilters, and NONE existingTags match any environmentsTagFilters', () => { | ||
const config = { | ||
...projectConfig, | ||
targets: { | ||
build: {}, | ||
test: {}, | ||
} | ||
} | ||
const options = { | ||
...normalizedCreateNodeOptions, | ||
targetNames: ['cola', 'mock', 'build'], | ||
filterByTags: ['mock-tag-no-match'] | ||
} | ||
const result = isEnvProject(config, options); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
}) |