Skip to content
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

Build If-merge #927

Merged
merged 24 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
729080a
fix(util): improve `isDirectoryExists` function in the fs.ts
manushak Aug 1, 2024
b5222ef
test(mocks): update fs.ts mocks
manushak Aug 1, 2024
c52ae5a
fix(config): move `DIRECTORY_NOT_FOUND` from if-check into common config
manushak Aug 1, 2024
431b30a
fix(util): move `DIRECTORY_NOT_FOUND` from if-check into common config
manushak Aug 1, 2024
d02cf9c
fix(config): remove `optional: false` from if-csv to allow the lib to…
manushak Aug 1, 2024
0ebccdf
fix(config): remove `PARAMS_NOT_PRESENT` unneseccary string from if-csv
manushak Aug 1, 2024
0dafebd
test(util): update if-check test related to changes
manushak Aug 1, 2024
addd01b
feat(config): add config and string for if-merge
manushak Aug 1, 2024
875c863
feat(types): add `IFMergeArgs` type
manushak Aug 1, 2024
a11de2e
feat(util): add args.ts for if-merge
manushak Aug 1, 2024
0b680ee
feat(util): add helpers functions for if-merge
manushak Aug 1, 2024
ac575ef
test(util): add tests for args.ts and helpers.ts
manushak Aug 1, 2024
54a46d9
feat(src): add if-merge logic
manushak Aug 1, 2024
1fa4326
feat(package): add `if-merge` command tool into package.json
manushak Aug 1, 2024
8196169
Update package.json
manushak Aug 1, 2024
49b2b5b
fix(package): revert package name to correct one
manushak Aug 1, 2024
6f99d7f
test(util): add eslint comment
manushak Aug 1, 2024
a828eb3
feat(util): imporve `mergeManifests` helper function
manushak Aug 1, 2024
5729b2b
fix(config): add `output` flag
manushak Aug 8, 2024
902a810
fix(types): add `output` into IFMergeArgs type
manushak Aug 8, 2024
7efa837
fix(util): update logic to print result if the `output` is not provided
manushak Aug 8, 2024
ec1693b
test(util): update tests
manushak Aug 8, 2024
862ca01
Merge branch 'main' into if-merge
manushak Aug 8, 2024
dd24689
fix(util): compose unique name for tree children
manushak Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@grnsft/if",
"name": "if-environment",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bug is still here, please fix when you have window

"description": "Impact Framework",
"version": "0.5.0",
"author": {
Expand All @@ -11,7 +11,8 @@
"if-run": "./build/if-run/index.js",
"if-env": "./build/if-env/index.js",
"if-check": "./build/if-check/index.js",
"if-csv": "./build/if-csv/index.js"
"if-csv": "./build/if-csv/index.js",
"if-merge": "./build/if-merge/index.js"
},
"bugs": {
"url": "https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
Expand Down Expand Up @@ -80,6 +81,7 @@
"if-csv": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-csv/index.ts",
"if-diff": "npx ts-node src/if-diff/index.ts",
"if-env": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-env/index.ts",
"if-merge": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-merge/index.ts",
"if-run": "npx ts-node src/if-run/index.ts",
"lint": "gts lint",
"pre-commit": "lint-staged",
Expand All @@ -89,4 +91,4 @@
"test": "jest --verbose --testPathPattern=src/__tests__/"
},
"stability": "stable"
}
}
manushak marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion src/__mocks__/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export const readdir = (directoryPath: string) => {
export const lstat = (filePath: string) => {
if (
filePath.includes('mock-directory') ||
filePath.includes('mock-sub-directory/subdir')
filePath.includes('mock-sub-directory/subdir') ||
filePath === 'true'
) {
return {
isDirectory: () => true,
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/if-check/util/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const {
CliSourceFileError,
ParseCliParamsError,
} = ERRORS;
const {DIRECTORY_NOT_FOUND, IF_CHECK_FLAGS_MISSING} = STRINGS;
const {SOURCE_IS_NOT_YAML, MANIFEST_NOT_FOUND} = COMMON_STRINGS;
const {IF_CHECK_FLAGS_MISSING} = STRINGS;
const {SOURCE_IS_NOT_YAML, MANIFEST_NOT_FOUND, DIRECTORY_NOT_FOUND} =
COMMON_STRINGS;

describe('if-check/util: ', () => {
const originalEnv = process.env;
Expand Down
163 changes: 163 additions & 0 deletions src/__tests__/if-merge/util/args.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import * as path from 'path';

jest.mock('../../../common/util/fs', () => ({
isFileExists: () => {
if (process.env.fileExists === 'true') {
return true;
}
return false;
},
isDirectoryExists: () => {
if (process.env.directoryExists === 'true') {
return true;
}
return false;
},
}));

jest.mock('ts-command-line-args', () => ({
__esModule: true,
parse: () => {
switch (process.env.result) {
case 'manifests-are-provided':
return {manifests: ['mock-manifest1.yaml', 'mock-manifest2.yaml']};
case 'directory-is-provided':
return {manifests: ['/mock-directory']};
case 'flags-are-not-provided':
return {manifests: undefined, name: undefined, description: undefined};
case 'manifest-is-not-yaml':
return {manifests: ['mock-manifest1.yaml', './mock-manifest2']};
case 'env-throw-error':
throw new Error('mock-error');
case 'env-throw':
throw 'mock-error';
default:
return {
manifests: ['mock-manifest1.yaml', 'mock-manifest2.yaml'],
output: 'mock-output',
};
}
},
}));

import {ERRORS} from '@grnsft/if-core/utils';

import {parseIfMergeArgs} from '../../../if-merge/util/args';

import {STRINGS as COMMON_STRINGS} from '../../../common/config';

import {STRINGS} from '../../../if-merge/config';

const {InvalidDirectoryError, CliSourceFileError, ParseCliParamsError} = ERRORS;

const {DIRECTORY_NOT_FOUND, MANIFEST_NOT_FOUND} = COMMON_STRINGS;
const {MANIFEST_IS_NOT_YAML} = STRINGS;

describe('if-merge/util/args: ', () => {
const originalEnv = process.env;

describe('parseIfMergeArgs(): ', () => {
const manifests = [
path.join(process.cwd(), 'mock-manifest1.yaml'),
path.join(process.cwd(), 'mock-manifest2.yaml'),
];
it('executes when `manifest` is provided.', async () => {
process.env.fileExists = 'true';
process.env.result = 'manifests-are-provided';
const response = await parseIfMergeArgs();

expect.assertions(1);

expect(response).toEqual({
name: undefined,
description: undefined,
manifests,
});
});

it('executes when the directory is provided.', async () => {
process.env.directoryExists = 'true';
process.env.result = 'directory-is-provided';

const response = await parseIfMergeArgs();

expect.assertions(1);

expect(response).toEqual({
name: undefined,
description: undefined,
manifests: ['/mock-directory'],
});
});

it('throws an error when the directory does not exist.', async () => {
process.env.directoryExists = 'false';
process.env.result = 'directory-is-provided';
expect.assertions(1);

try {
await parseIfMergeArgs();
} catch (error) {
expect(error).toEqual(new InvalidDirectoryError(DIRECTORY_NOT_FOUND));
}
});

it('throws an error if one of manifests is not a yaml.', async () => {
process.env.fileExists = 'true';
process.env.result = 'manifest-is-not-yaml';
expect.assertions(1);

try {
await parseIfMergeArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(
new CliSourceFileError(MANIFEST_IS_NOT_YAML('./mock-manifest2'))
);
}
}
});

it('throws an error if `manifest` path is invalid.', async () => {
process.env.fileExists = 'false';
process.env.result = 'manifest-is-not-yaml';
expect.assertions(1);

try {
await parseIfMergeArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(
new ParseCliParamsError(`mock-manifest1.yaml ${MANIFEST_NOT_FOUND}`)
);
}
}
});

it('throws an error if parsing failed.', async () => {
process.env.result = 'env-throw-error';
expect.assertions(1);

try {
await parseIfMergeArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(new ParseCliParamsError('mock-error'));
}
}
});

it('throws error if parsing failed (not instance of error).', async () => {
process.env.result = 'env-throw';
expect.assertions(1);

try {
await parseIfMergeArgs();
} catch (error) {
expect(error).toEqual('mock-error');
}
});
});

process.env = originalEnv;
});
Loading