Skip to content

Commit 0bd6319

Browse files
authored
Merge pull request #87 from reportportal/develop
Release 5.0.2
2 parents 45596d3 + 07678d9 commit 0bd6319

12 files changed

Lines changed: 2269 additions & 3692 deletions

.github/workflows/publish.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
name: publish
1515

1616
on:
17-
release:
18-
types:
19-
- published
17+
repository_dispatch:
18+
types: [version-released]
2019

2120
jobs:
2221
build:

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ jobs:
7474
steps:
7575
- name: Checkout repository
7676
uses: actions/checkout@v2
77+
- name: Setup NodeJS
78+
uses: actions/setup-node@v2
79+
with:
80+
node-version: '12'
7781
- name: Configure git
7882
run: |
7983
git config --global user.email "reportportal.io"
@@ -139,3 +143,9 @@ jobs:
139143
body: ${{ needs.create-tag.outputs.versionInfo }}
140144
draft: false
141145
prerelease: false
146+
- name: Trigger the publish workflow
147+
if: success()
148+
uses: peter-evans/repository-dispatch@v1
149+
with:
150+
token: ${{ secrets.GH_TOKEN }}
151+
event-type: version-released

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
### Fixed
2+
- `skippedIssue` config property processing using .mocharc or string values
3+
- Skipped test duplication
4+
- Config attributes parsing using .mocharc
5+
6+
### Security
7+
- Versions of several vulnerable dependencies updated
8+
9+
### Added
10+
- `mode` option for submitting results to Debug tab
11+
- Latest error log to the step description
12+
13+
### Changed
14+
- Package size reduced
115

216
## [5.0.1] - 2020-06-23
317
### Added
4-
- Added link to the example in readme.
18+
- Added link to the example in readme.
519

620
## [5.0.0] - 2020-06-22
721
### Added

README.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ npm install @reportportal/agent-js-mocha
1010
```
1111

1212
## How to use:
13-
Fill reporterOptions in Mocha configuration.
13+
Fill reporterOptions in Mocha configuration.
1414
```javascript
1515
const Mocha = require("mocha");
1616
let mochaMain = new Mocha({
1717
reporter: '@reportportal/agent-js-mocha',
1818
reporterOptions: {
19-
"token": "00000000-0000-0000-0000-000000000000",
19+
"token": "00000000-0000-0000-0000-000000000000",
2020
"endpoint": "https://your.reportportal.server/api/v1",
2121
"project": "YourReportPortalProjectName",
2222
"launch": "YourLauncherName",
@@ -31,6 +31,25 @@ let mochaMain = new Mocha({
3131
]
3232
}
3333
});
34+
```
35+
Using `.mocharc.js`:
36+
```javascript
37+
module.exports = {
38+
'extension': ['js', 'cjs', 'mjs'],
39+
'package': './package.json',
40+
reporter: '@reportportal/agent-js-mocha',
41+
'reporter-option':[
42+
'endpoint=https://your.reportportal.server/api/v1',
43+
'token=00000000-0000-0000-0000-000000000000',
44+
'launch=YourLauncherName',
45+
'project=YourReportPortalProjectName',
46+
'attributes=YourKey:YourValue;YourValue',
47+
],
48+
'file': [
49+
'spec/someTest.spec.js',
50+
]
51+
}
52+
3453
```
3554

3655
#### You can find an example of using Mocha Reporter [here](https://github.com/reportportal/examples-js/tree/master/example-mocha).
@@ -44,7 +63,8 @@ Runs support following options:
4463
| token | User's Report Portal token from which you want to send requests. It can be found on the profile page of this user.|
4564
| endpoint | URL of your server. For example 'https://server:8080/api/v1'. |
4665
| launch | Name of launch at creation. |
47-
| project | The name of the project in which the launches will be created. |
66+
| project | The name of the project in which the launches will be created.
67+
| mode | *Default: "default".* Results will be submitting to Launches tab<br> *"debug"* - Results will be submitting to Debug tab. |
4868
| rerun | *Default: false.* Enable [rerun](https://github.com/reportportal/documentation/blob/master/src/md/src/DevGuides/rerun.md)|
4969
| rerunOf | UUID of launch you want to rerun. If not specified, report portal will update the latest launch with the same name|
5070
| reportHooks | *Default: false.* Determines report before and after hooks or not. |
@@ -112,7 +132,7 @@ describe('suite',()=>{
112132
```
113133
#### Report attributes for steps and suites
114134

115-
**addAttributes (*attributes*)**. Add attributes(tags) to the current test/suite. Should be called inside of corresponding test or suite.</br>
135+
**addAttributes (*attributes*)**. Add attributes(tags) to the current test/suite. Should be called inside of corresponding test or suite.</br>
116136
*attributes* is array of pairs of key and value:
117137
```javascript
118138
[{
@@ -141,7 +161,7 @@ describe('suite',()=>{
141161

142162
#### Integration with Sauce Labs
143163

144-
To integrate with Sauce Labs just add attributes:
164+
To integrate with Sauce Labs just add attributes:
145165

146166
```javascript
147167
[{
@@ -155,9 +175,9 @@ To integrate with Sauce Labs just add attributes:
155175

156176
#### Report description for steps and suites
157177

158-
**setDescription (*description*)**. Set text description to the current test/suite. Should be called inside of corresponding test or suite.</br>
178+
**setDescription (*description*)**. Set text description to the current test/suite. Should be called inside of corresponding test or suite.</br>
159179

160-
Mocha doesn't allow functional calls directly into describe section. You can call setDescription inside of before/after hooks to set description to the corresponding suite.
180+
Mocha doesn't allow functional calls directly into describe section. You can call setDescription inside of before/after hooks to set description to the corresponding suite.
161181

162182
**Example:**
163183
```javascript
@@ -175,9 +195,9 @@ describe('suite',()=>{
175195

176196
#### Report test case id for steps and suites
177197

178-
**setTestCaseId (*testCaseId*)**. Set test case id to the current test/suite. Should be called inside of corresponding test or suite.</br>
198+
**setTestCaseId (*testCaseId*)**. Set test case id to the current test/suite. Should be called inside of corresponding test or suite.</br>
179199

180-
Mocha doesn't allow functional calls directly into describe section. You can call setTestCaseId inside of before/after hooks to set test case id to the corresponding suite.
200+
Mocha doesn't allow functional calls directly into describe section. You can call setTestCaseId inside of before/after hooks to set test case id to the corresponding suite.
181201

182202
**Example:**
183203
```javascript
@@ -233,7 +253,7 @@ describe('suite',()=>{
233253
});
234254
});
235255
```
236-
256+
237257
# Copyright Notice
238258

239259
Licensed under the [Apache License v2.0](LICENSE)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.1
1+
5.0.2-SNAPSHOT

lib/mochaReporter.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const { EVENTS } = require('@reportportal/client-javascript/lib/constants/events
2121
const { entityType, hookTypes, hookTypesMap } = require('./constants/itemTypes');
2222
const logLevels = require('./constants/logLevels');
2323
const testStatuses = require('./constants/testStatuses');
24-
const { getCodeRef, getAgentInfo } = require('./utils');
24+
const { getCodeRef, getAgentInfo, parseAttributes } = require('./utils');
2525

2626
const {
2727
EVENT_RUN_BEGIN,
@@ -151,7 +151,8 @@ class ReportportalAgent extends Mocha.reporters.Base {
151151
system: true,
152152
},
153153
];
154-
if (this.options.reporterOptions.skippedIssue === false) {
154+
if (String(this.options.reporterOptions.skippedIssue).toLowerCase() === 'false') {
155+
this.options.reporterOptions.skippedIssue = false;
155156
const skippedIssueAttribute = {
156157
key: 'skippedIssue',
157158
value: 'false',
@@ -164,14 +165,14 @@ class ReportportalAgent extends Mocha.reporters.Base {
164165

165166
onLaunchStart() {
166167
const systemAttributes = this.getSystemAttributes();
167-
const launchAttributes = (this.options.reporterOptions.attributes || []).concat(
168-
systemAttributes,
169-
);
168+
const attributes = parseAttributes(this.options.reporterOptions.attributes);
169+
const launchAttributes = (attributes || []).concat(systemAttributes);
170170
const { tempId, promise } = this.rpClient.startLaunch({
171171
token: this.options.reporterOptions.token,
172172
name: this.options.reporterOptions.launch,
173173
startTime: this.rpClient.helpers.now(),
174174
description: this.options.reporterOptions.description,
175+
mode: this.options.reporterOptions.mode,
175176
rerun: this.options.reporterOptions.rerun,
176177
rerunOf: this.options.reporterOptions.rerunOf,
177178
attributes: launchAttributes,
@@ -271,7 +272,12 @@ class ReportportalAgent extends Mocha.reporters.Base {
271272
finishTest(test, autoStatus) {
272273
if (this.currentTest) {
273274
const testAttributes = this.attributes.get(this.currentTest.tempId);
274-
const testDescription = this.descriptions.get(this.currentTest.tempId);
275+
let testDescription = this.descriptions.get(this.currentTest.tempId);
276+
if (test.err) {
277+
testDescription = (testDescription || '').concat(
278+
`\n\`\`\`error\n${test.err.stack}\n\`\`\``,
279+
);
280+
}
275281
const testCaseId = this.testCaseIds.get(this.currentTest.tempId);
276282
const testStatus = this.testItemStatuses.get(this.currentTest.tempId) || autoStatus;
277283
const withoutIssue =
@@ -352,7 +358,9 @@ class ReportportalAgent extends Mocha.reporters.Base {
352358
}
353359

354360
onTestPending(test) {
355-
this.onTestStart(test);
361+
if (this.currentTest === null) {
362+
this.onTestStart(test);
363+
}
356364
this.finishTest(test, testStatuses.SKIPPED);
357365
}
358366

lib/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ const getAgentInfo = () => ({
3030
name: pjson.name,
3131
});
3232

33-
module.exports = { getCodeRef, getAgentInfo };
33+
const parseAttributes = (attributes) => {
34+
if (typeof attributes === 'string') {
35+
return attributes.split(';').map((attributeStr) => {
36+
const attribute = attributeStr.split(':');
37+
return attribute.length === 2
38+
? { key: attribute[0], value: attribute[1] }
39+
: { value: attribute[0] };
40+
});
41+
}
42+
return attributes;
43+
};
44+
45+
module.exports = { getCodeRef, getAgentInfo, parseAttributes };

0 commit comments

Comments
 (0)