Skip to content

Commit

Permalink
improve custom step identifier type
Browse files Browse the repository at this point in the history
  • Loading branch information
bgawkuc committed Jun 14, 2024
1 parent 852ef29 commit d7b053c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/types/modules/act.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {StepIdentifier as ActStepIdentifier, GithubWorkflowStep, StepIdentifierUsingId, StepIdentifierUsingName} from '@kie/act-js/build/src/step-mocker/step-mocker.types';
import type {GithubWorkflowStep, StepIdentifier} from '@kie/act-js/build/src/step-mocker/step-mocker.types';

declare module '@kie/act-js' {
type CustemStepIdentifier = {
Expand All @@ -9,9 +9,7 @@ declare module '@kie/act-js' {
with?: string;
envs?: string[];
inputs?: string[];
};
} & Omit<StepIdentifier, 'name' | 'id' | 'run' | 'mockWith'>;

type StepIdentifier = ActStepIdentifier;

export type {StepIdentifierUsingId, StepIdentifierUsingName, GithubWorkflowStep, StepIdentifier, CustemStepIdentifier};
export type {GithubWorkflowStep, StepIdentifier, CustemStepIdentifier};
}
9 changes: 5 additions & 4 deletions workflow_tests/utils/JobMocker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {CustemStepIdentifier, StepIdentifier, StepIdentifierUsingName} from '@kie/act-js';
import type {CustemStepIdentifier, StepIdentifier} from '@kie/act-js';
import type {PathOrFileDescriptor} from 'fs';
import fs from 'fs';
import path from 'path';
Expand Down Expand Up @@ -51,12 +51,13 @@ class JobMocker {
delete job.with;
}
job.steps = mockJob.steps.map((step) => {
const customStep = step as CustemStepIdentifier;
const mockStep: CustemStepIdentifier = {
name: (step as StepIdentifierUsingName).name,
name: customStep.name,
run: step.mockWith,
};
if ((step as CustemStepIdentifier).id) {
mockStep.id = (step as CustemStepIdentifier).id;
if (customStep.id) {
mockStep.id = customStep.id;
}
if (jobWith) {
mockStep.with = jobWith;
Expand Down
14 changes: 5 additions & 9 deletions workflow_tests/utils/preGenerateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ const getMockFileContent = (workflowName: string, jobs: Record<string, YamlMockJ
let mockStepsContent = `\n// ${jobId.toLowerCase()}`;
const stepMocks: string[] = [];
job.steps.forEach((step) => {
const stepMockName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__${(step as CustemStepIdentifier).name
const customStep = step as CustemStepIdentifier;
const stepMockName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__${customStep.name
.replaceAll(' ', '_')
.replaceAll('-', '_')
.replaceAll(',', '')
Expand All @@ -227,7 +228,7 @@ const getMockFileContent = (workflowName: string, jobs: Record<string, YamlMockJ
.replaceAll('.js', '')
.toUpperCase()}__STEP_MOCK`;
stepMocks.push(stepMockName);
mockStepsContent += mockStepTemplate(stepMockName, step as CustemStepIdentifier, jobId);
mockStepsContent += mockStepTemplate(stepMockName, customStep, jobId);
});

const jobMocksName = `${workflowName.toUpperCase()}__${jobId.toUpperCase()}__STEP_MOCKS`;
Expand All @@ -245,13 +246,8 @@ const getAssertionsFileContent = (jobs: Record<string, YamlMockJob>): string =>
Object.entries(jobs).forEach(([jobId, job]) => {
let stepAssertionsContent = '';
job.steps.forEach((step: CustemStepIdentifier | StepIdentifier) => {
stepAssertionsContent += stepAssertionTemplate(
(step as CustemStepIdentifier).name,
jobId.toUpperCase(),
(step as CustemStepIdentifier).name,
(step as CustemStepIdentifier).inputs,
(step as CustemStepIdentifier).envs,
);
const customStep = step as CustemStepIdentifier;
stepAssertionsContent += stepAssertionTemplate(customStep.name, jobId.toUpperCase(), customStep.name, customStep.inputs, customStep.envs);
});
const jobAssertionName = `assert${jobId.charAt(0).toUpperCase() + jobId.slice(1)}JobExecuted`;
jobAssertions.push(jobAssertionName);
Expand Down

0 comments on commit d7b053c

Please sign in to comment.