Skip to content

Commit 1d0d438

Browse files
authored
Merge pull request #141 from joomcode/fix/map-additional-payload-in-steps
fix: map additional payload in step via mapLogPayloadInReport
2 parents ade8ef2 + bd1aefa commit 1d0d438

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/step.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {setCustomInspectOnFunction} from './utils/fn';
44
import {generalLog} from './utils/generalLog';
55
import {logAndGetLogEvent} from './utils/log';
66
import {setReadonlyProperty} from './utils/object';
7-
import {processStepError, runStepBody} from './utils/step';
7+
import {processStepError, runStepBody, updateStepPayload} from './utils/step';
88

99
import type {
1010
LogEvent,
@@ -87,7 +87,7 @@ export const step = async (
8787
setReadonlyProperty(logEvent, 'endTime', endTime);
8888

8989
if (payload !== undefined) {
90-
setReadonlyProperty(logEvent, 'payload', {...logEvent.payload, ...payload});
90+
updateStepPayload(logEvent, payload);
9191
}
9292

9393
generalLog(`Step "${name}" completed`, {

src/utils/step/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export {getTopStep} from './getTopStep';
44
export {processStepError} from './processStepError';
55
/** @internal */
66
export {runStepBody} from './runStepBody';
7+
/** @internal */
8+
export {updateStepPayload} from './updateStepPayload';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {getFullPackConfig} from '../config';
2+
import {setReadonlyProperty} from '../object';
3+
4+
import type {LogEvent, LogPayload} from '../../types/internal';
5+
6+
/**
7+
* Updates `step` log payload with the values returned by the step body.
8+
* @internal
9+
*/
10+
export const updateStepPayload = (logEvent: LogEvent, additionalPayload: LogPayload): void => {
11+
const {mapLogPayloadInReport} = getFullPackConfig();
12+
13+
const payloadInReport = mapLogPayloadInReport(logEvent.message, additionalPayload, logEvent.type);
14+
15+
if (payloadInReport !== undefined && payloadInReport !== 'skipLog') {
16+
setReadonlyProperty(logEvent, 'payload', {...logEvent.payload, ...payloadInReport});
17+
}
18+
};

0 commit comments

Comments
 (0)