Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cucumberjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
},
"devDependencies": {
"@cucumber/cucumber": "^7.3.2",
"cucumberjs-qase-reporter": "^2.0.0-beta.3"
"cucumberjs-qase-reporter": "^2.0.3"
}
}
3 changes: 1 addition & 2 deletions examples/cucumberjs/qase.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"api": {
"token": "api_key"
},

"project": "project_code",

"uploadAttachments": true,
"run": {
"complete": true
}
Expand Down
1 change: 1 addition & 0 deletions examples/cucumberjs/step_definitions/simple_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Given, When, Then } = require('@cucumber/cucumber');

Given('I have a step', function() {
console.log('I have a step');
this.attach('I\'m an attachment', 'text/plain');
});

Given('I have another step', function() {
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

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

18 changes: 18 additions & 0 deletions qase-cucumberjs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# qase-cucumberjs@2.0.3

## What's new

Support attachments in the test results.

```js
const { Given, Then } = require('cucumber');

Given('I have a step with attachment', async function () {
await this.attach('Hello, world!', 'text/plain');
});

Then('I have a step with attachment', async function () {
await this.attach('Hello, world!', 'text/plain');
});
```

# qase-cucumberjs@2.0.2

## What's new
Expand Down
5 changes: 3 additions & 2 deletions qase-cucumberjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cucumberjs-qase-reporter",
"version": "2.0.2",
"version": "2.0.3",
"description": "Qase TMS CucumberJS Reporter",
"homepage": "https://github.com/qase-tms/qase-javascript",
"main": "./dist/index.js",
Expand Down Expand Up @@ -49,6 +49,7 @@
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.2",
"jest": "^29.5.0",
"ts-jest": "^29.1.0"
"ts-jest": "^29.1.0",
"uuid": "^9.0.0"
}
}
44 changes: 36 additions & 8 deletions qase-cucumberjs/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
TestStepFinished,
} from '@cucumber/messages';
import {
Attachment, CompoundError,
Attachment,
CompoundError,
Relation,
StepStatusEnum,
StepType,
Expand All @@ -19,6 +20,7 @@ import {
} from 'qase-javascript-commons';
import { TestCase } from '@cucumber/messages/dist/esm/src/messages';
import { Status } from '@cucumber/cucumber';
import { v4 as uuidv4 } from 'uuid';

type TestStepResultStatus = (typeof Status)[keyof typeof Status];

Expand Down Expand Up @@ -106,18 +108,18 @@ export class Storage {
* @param {Attach} attachment
*/
public addAttachment(attachment: Attach): void {
if (attachment.testCaseStartedId && attachment.fileName) {
if (!this.attachments[attachment.testCaseStartedId]) {
this.attachments[attachment.testCaseStartedId] = [];
if (attachment.testStepId) {
if (!this.attachments[attachment.testStepId]) {
this.attachments[attachment.testStepId] = [];
}

this.attachments[attachment.testCaseStartedId]?.push({
file_name: attachment.fileName,
this.attachments[attachment.testStepId]?.push({
file_name: this.getFileNameFromMediaType(attachment.mediaType),
mime_type: attachment.mediaType,
file_path: null,
content: attachment.body,
size: 0,
id: attachment.fileName,
id: uuidv4(),
});
}
}
Expand Down Expand Up @@ -281,7 +283,7 @@ export class Storage {
end_time: null,
duration: finished.testStepResult.duration.seconds,
},
attachments: [],
attachments: this.attachments[s.id] ?? [],
steps: [],
parent_id: null,
}
Expand Down Expand Up @@ -394,4 +396,30 @@ export class Storage {

return error;
}

private getFileNameFromMediaType(mediaType: string): string {
const extensions: Record<string, string> = {
'text/plain': 'txt',
'application/json': 'json',
'image/png': 'png',
'image/jpeg': 'jpg',
'image/gif': 'gif',
'text/html': 'html',
'application/pdf': 'pdf',
'application/xml': 'xml',
'application/zip': 'zip',
'application/msword': 'doc',
'application/vnd.ms-excel': 'xls',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
};

const extension = extensions[mediaType];

if (extension) {
return `file.${extension}`;
} else {
return 'file';
}
}
}