Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganitzsh committed Oct 31, 2023
1 parent 0768580 commit c527f59
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 143 deletions.
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests.v2",
"request": "launch",
"args": [
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}",
"--config",
"${workspaceFolder}/jest.config.ts"
],
"env": {
"NODE_OPTIONS": "--experimental-vm-modules"
},
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
169 changes: 84 additions & 85 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/utilities/constants.ts

This file was deleted.

128 changes: 91 additions & 37 deletions src/utilities/inputProcessors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import * as actionsCore from '@actions/core';

import {
processInputAdditionalPlugins,
processInputCommitAssets,
processInputConfigFile,
processInputDisableChangelog,
processInputDryRun,
processInputNodeModule,
processInputReleaseAssets,
processInputReleaseBranches,
processInputReleaseRules,
} from './inputProcessors.js';

const getInputSpy = jest.spyOn(actionsCore, 'getInput').mockImplementation();
import { jest } from '@jest/globals';

const getInputSpy = jest.fn() as unknown as jest.SpiedFunction<
(_: never, packages: string[]) => unknown
>;

jest.unstable_mockModule('@actions/core', (): unknown => ({
getInput: getInputSpy,
}));

describe('processInputNodeModule', (): void => {
it("returns true when the value of the npm-package input is set to 'true'", (): void => {
it("reurns true when the value of the npm-package input is set to 'true'", async (): Promise<void> => {
expect.assertions(1);

const { processInputNodeModule } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue('true');

const result = processInputNodeModule();
Expand All @@ -27,9 +23,13 @@ describe('processInputNodeModule', (): void => {
});

describe('processInputDisableGenerateChangelog', (): void => {
it("returns true when the value of the disable-generate-changelog input is set to 'true'", (): void => {
it("returns true when the value of the disable-generate-changelog input is set to 'true'", async (): Promise<void> => {
expect.assertions(1);

const { processInputDisableChangelog } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue('true');

const result = processInputDisableChangelog();
Expand All @@ -39,9 +39,11 @@ describe('processInputDisableGenerateChangelog', (): void => {
});

describe('processInputDryRun', (): void => {
it("returns true when the value of the dry-run input is set to 'true'", (): void => {
it("returns true when the value of the dry-run input is set to 'true'", async (): Promise<void> => {
expect.assertions(1);

const { processInputDryRun } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue('true');

const result = processInputDryRun();
Expand All @@ -51,9 +53,13 @@ describe('processInputDryRun', (): void => {
});

describe('processInputReleaseBranches', (): void => {
it('throws an error if the input parameter value is set to an invalid JSON string', (): void => {
it('throws an error if the input parameter value is set to an invalid JSON string', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseBranches } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue('test');

expect(processInputReleaseBranches).toThrow(
Expand Down Expand Up @@ -85,9 +91,13 @@ describe('processInputReleaseBranches', (): void => {
},
])(
'throws an error if the input parameter is set to an invalid value %j',
({ value }: { value: string }): void => {
async ({ value }: { value: string }): Promise<void> => {
expect.assertions(1);

const { processInputReleaseBranches } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue(value);

try {
Expand All @@ -98,19 +108,26 @@ describe('processInputReleaseBranches', (): void => {
},
);

it("returns undefined if the input parameter value is set to an empty string''", (): void => {
it("returns undefined if the input parameter value is set to an empty string''", async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseBranches } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue('');

const result = processInputReleaseBranches();

expect(result).toBeUndefined();
});

it('returns a valid branches configuration array passed as json-string', (): void => {
it('returns a valid branches configuration array passed as json-string', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseBranches } = await import(
'./inputProcessors.js'
);
getInputSpy.mockReturnValue(
JSON.stringify([
'+([0-9])?(.{+([0-9]),x}).x',
Expand All @@ -136,9 +153,11 @@ describe('processInputReleaseBranches', (): void => {
});

describe('processInputReleaseRules', (): void => {
it('throws an error if the input parameter value is set to an invalid JSON string', (): void => {
it('throws an error if the input parameter value is set to an invalid JSON string', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce('test').mockReturnValueOnce('');

expect(processInputReleaseRules).toThrow(
Expand Down Expand Up @@ -167,19 +186,23 @@ describe('processInputReleaseRules', (): void => {
},
])(
'throws an error if the input parameter is set to an invalid value %j',
({ value }: { value: string }): void => {
async ({ value }: { value: string }): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce(value).mockReturnValueOnce('');

/* eslint-disable-next-line jest/require-to-throw-message */
expect(processInputReleaseRules).toThrow();
},
);

it("returns the default release rules if the input parameter value is set to an empty string''", (): void => {
it("returns the default release rules if the input parameter value is set to an empty string''", async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce('').mockReturnValueOnce('');

const result = processInputReleaseRules();
Expand All @@ -195,9 +218,11 @@ describe('processInputReleaseRules', (): void => {
]);
});

it('returns a valid branches configuration array passed as json-string', (): void => {
it('returns a valid branches configuration array passed as json-string', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy
.mockReturnValueOnce(
JSON.stringify([
Expand All @@ -219,9 +244,11 @@ describe('processInputReleaseRules', (): void => {
});

describe('processInputReleaseRulesAppend', (): void => {
it('throws an error if the release-rules-append input parameter value is set to an invalid JSON string', (): void => {
it('throws an error if the release-rules-append input parameter value is set to an invalid JSON string', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce('').mockReturnValueOnce('test');

expect(processInputReleaseRules).toThrow(
Expand Down Expand Up @@ -250,18 +277,23 @@ describe('processInputReleaseRulesAppend', (): void => {
},
])(
'throws an error if the release-rules-append input parameter is set to an invalid value %j',
({ value }: { value: string }): void => {
async ({ value }: { value: string }): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce('').mockReturnValueOnce(value);

/* eslint-disable-next-line jest/require-to-throw-message */
expect(processInputReleaseRules).toThrow();
},
);

it('throws and error when both release-rules and release-rules-append are defined', (): void => {
it('throws and error when both release-rules and release-rules-append are defined', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy
.mockReturnValueOnce(
JSON.stringify([
Expand All @@ -278,9 +310,11 @@ describe('processInputReleaseRulesAppend', (): void => {
);
});

it('returns default release rules with append rules added to the end', (): void => {
it('returns default release rules with append rules added to the end', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseRules } = await import('./inputProcessors.js');

getInputSpy.mockReturnValueOnce('').mockReturnValueOnce(
JSON.stringify([
{
Expand Down Expand Up @@ -315,9 +349,11 @@ describe('processInputReleaseRulesAppend', (): void => {
});

describe('processInputCommitAssets', (): void => {
it('returns an array of valid paths relative to the project root', (): void => {
it('returns an array of valid paths relative to the project root', async (): Promise<void> => {
expect.assertions(1);

const { processInputCommitAssets } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue(`
./src
`);
Expand All @@ -329,9 +365,11 @@ describe('processInputCommitAssets', (): void => {
});

describe('processInputReleaseAssets', (): void => {
it('returns an array of valid paths relative to the project root', (): void => {
it('returns an array of valid paths relative to the project root', async (): Promise<void> => {
expect.assertions(1);

const { processInputReleaseAssets } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue(`
./src
`);
Expand All @@ -343,19 +381,23 @@ describe('processInputReleaseAssets', (): void => {
});

describe('processInputConfigFile', (): void => {
it('returns a valid path relative to the project root', (): void => {
it('returns a valid path relative to the project root', async (): Promise<void> => {
expect.assertions(1);

const { processInputConfigFile } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue('./src.yaml');

const result = processInputConfigFile();

expect(result).toBe('./src.yaml');
});

it('throws if the provided path is not a YAML file', (): void => {
it('throws if the provided path is not a YAML file', async (): Promise<void> => {
expect.assertions(1);

const { processInputConfigFile } = await import('./inputProcessors.js');

getInputSpy.mockReturnValue('./src.json');

try {
Expand All @@ -367,9 +409,13 @@ describe('processInputConfigFile', (): void => {
});

describe('processInputAdditionalPlugins', (): void => {
it('returns an object in package.json format', (): void => {
it('returns an object in package.json format', async (): Promise<void> => {
expect.assertions(1);

const { processInputAdditionalPlugins } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue(
'{"@google/semantic-release-replace-plugin":"^4.0.2"}',
);
Expand All @@ -381,9 +427,13 @@ describe('processInputAdditionalPlugins', (): void => {
});
});

it('throws if the input is not valid JSON', (): void => {
it('throws if the input is not valid JSON', async (): Promise<void> => {
expect.assertions(1);

const { processInputAdditionalPlugins } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue('foo');

try {
Expand All @@ -393,9 +443,13 @@ describe('processInputAdditionalPlugins', (): void => {
}
});

it('throws if the object is not in package.json format', (): void => {
it('throws if the object is not in package.json format', async (): Promise<void> => {
expect.assertions(1);

const { processInputAdditionalPlugins } = await import(
'./inputProcessors.js'
);

getInputSpy.mockReturnValue('{"foo":1}');

try {
Expand Down
Loading

0 comments on commit c527f59

Please sign in to comment.