Skip to content

Commit

Permalink
fix: parameters serialization (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Jul 13, 2024
1 parent 79a32d0 commit d6baf0c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/reporter/allure-adapter/normalizeParameters.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { AllureTestCaseResult, AllureTestStepResult, Parameter } from 'jest-allure2-reporter';

export function normalizeParameters(result: AllureTestCaseResult | AllureTestStepResult) {
return result.parameters?.map(stringifyParameter);
return result.parameters?.filter(excludeParameters).map(stringifyParameter);
}

function stringifyParameter({ name, value }: Parameter) {
return { name, value: String(value) };
function excludeParameters({ excluded }: Parameter) {
return !excluded;
}

function stringifyParameter(parameter: Parameter) {
return { ...parameter, value: String(parameter.value) };
}
3 changes: 1 addition & 2 deletions src/runtime/AllureRuntimeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ export class AllureRuntimeImplementation implements AllureRuntime {

parameter: AllureRuntime['parameter'] = (name, value, options) => {
typeAssertions.assertString(name, 'name');
typeAssertions.assertPrimitive(value, 'value');

this.#coreModule.parameter({
name,
value: String(value),
value: typeof value === 'string' ? value : util.inspect(value),
...options,
});
};
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/__snapshots__/runtime.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ exports[`AllureRuntime should add attachments within the steps 1`] = `
"name": "0",
"value": "fourth",
},
{
"name": "1",
"value": "{ key: 'value' }",
},
],
"stage": "interrupted",
"start": 5,
Expand Down
17 changes: 10 additions & 7 deletions src/runtime/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ describe('AllureRuntime', () => {

expect(resultingPath).toBe('/attachments/first');

const innerStep3 = runtime.createStep('inner step 3 ({{0}})', async (message: string) => {
runtime.attachment('attachment4', message, 'text/plain');
const innerStep3 = runtime.createStep(
'inner step 3 ({{0}})',
async (message: string, _extra: object) => {
runtime.attachment('attachment4', message, 'text/plain');

const error = new Error('Async error');
error.stack = 'Error: Async error\n at innerStep3';
throw error;
});
const error = new Error('Async error');
error.stack = 'Error: Async error\n at innerStep3';
throw error;
},
);

await runtime.step('outer step', async () => {
try {
Expand All @@ -68,7 +71,7 @@ describe('AllureRuntime', () => {
/* empty */
});
runtime.attachment('attachment3', 'third', 'text/plain');
await innerStep3('fourth').catch(() => {
await innerStep3('fourth', { key: 'value' }).catch(() => {
/* empty */
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface AllureRuntime {

parameter(name: string, value: unknown, options?: ParameterOptions): void;

parameters(parameters: Record<string, unknown>): void;
parameters(parameters: object): void;

status(status: Status, statusDetails?: StatusDetails): void;

Expand Down

0 comments on commit d6baf0c

Please sign in to comment.