Skip to content

Commit

Permalink
fix(newman-reporter-allure): fix reporter error in case of empty exec (
Browse files Browse the repository at this point in the history
…fixes #1114, via #1121)
  • Loading branch information
baev authored Aug 29, 2024
1 parent 0c4d92a commit 9c6ff31
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 82 deletions.
69 changes: 39 additions & 30 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/newman-reporter-allure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"@types/babel__core": "^7",
"@types/babel__preset-env": "^7",
"@types/eslint": "^8.56.11",
"@types/newman": "^5.3.3",
"@types/newman": "^5.3.6",
"@types/node": "^20.14.2",
"@types/postman-collection": "^3.5.7",
"@types/postman-collection": "^3.5.10",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"allure-commandline": "^2.29.0",
Expand All @@ -77,7 +77,7 @@
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"msw": "1",
"newman": "^6.1.2",
"newman": "^6.2.1",
"npm-run-all2": "^6.1.2",
"postman-collection": "^4.2.1",
"rimraf": "^6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/newman-reporter-allure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AllureReporter {
return;
}

currentPmItem.prerequest = args.executions[0]?.script.exec?.join("\n");
currentPmItem.prerequest = args.executions[0]?.script?.exec?.join("\n");
}

onBeforeItem(err: any, args: { item: Item; cursor: Cursor }) {
Expand Down Expand Up @@ -266,7 +266,7 @@ class AllureReporter {
return;
}

const execScript = args.executions[0]?.script.exec?.join("\n");
const execScript = args.executions[0]?.script?.exec?.join("\n");

if (!execScript) {
return;
Expand Down
80 changes: 80 additions & 0 deletions packages/newman-reporter-allure/test/spec/exec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable @stylistic/quotes */
import { afterAll, afterEach, beforeAll, expect, test } from "vitest";
import { server } from "../mocks/server.js";
import { runNewmanCollection } from "../utils.js";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

test("empty exec", async () => {
const { tests } = await runNewmanCollection({
item: [
{
name: "Header Test Request",
event: [
{
listen: "test",
script: {
exec: [""],
type: "text/javascript",
},
},
{
listen: "prerequest",
script: {
exec: [""],
type: "text/javascript",
},
},
],
request: {
method: "GET",
header: [
{
key: "A-Header",
value: "with some value",
},
{
key: "B-Header",
value: "with other value",
},
],
body: {
mode: "raw",
raw: '{\r\n testVal1: "body",\r\n testVal2: 1,\r\n testVal3: true,\r\n}',
},
url: {
host: ["example", "com"],
path: ["headers"],
},
},
response: [],
},
],
});

expect(tests).toHaveLength(1);
expect(tests[0].attachments).toEqual([
{
name: "Request Headers",
source: expect.stringContaining("attachment.json"),
type: "application/json",
},
{
name: "Request Body",
source: expect.stringContaining("attachment.txt"),
type: "text/plain",
},
{
name: "Response Headers",
source: expect.stringContaining("attachment.json"),
type: "application/json",
},
{
name: "Response Body",
source: expect.stringContaining("attachment.txt"),
type: "text/plain",
},
]);
});
7 changes: 5 additions & 2 deletions packages/newman-reporter-allure/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MessageReader } from "allure-js-commons/sdk/reporter";
export const runNewmanCollection = async (collection: CollectionDefinition): Promise<AllureResults> => {
const reader = new MessageReader();

const allureResults: AllureResults = await new Promise((resolve) => {
const allureResults: AllureResults = await new Promise((resolve, reject) => {
const newmanEmitter = run(
{
collection,
Expand All @@ -15,7 +15,10 @@ export const runNewmanCollection = async (collection: CollectionDefinition): Pro
allure: {},
},
},
() => {
(err) => {
if (err) {
return reject(err);
}
return resolve(reader.results);
},
);
Expand Down
Loading

0 comments on commit 9c6ff31

Please sign in to comment.