Skip to content

Commit

Permalink
tests: add is env project basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianRomanski committed Jan 5, 2025
1 parent 0446e1d commit 12e8a70
Showing 1 changed file with 117 additions and 56 deletions.
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);
});

})

0 comments on commit 12e8a70

Please sign in to comment.