Skip to content

Commit

Permalink
Merge pull request #87 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.2
  • Loading branch information
AmsterGet authored Dec 12, 2022
2 parents 45596d3 + 07678d9 commit 0bd6319
Show file tree
Hide file tree
Showing 12 changed files with 2,269 additions and 3,692 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
name: publish

on:
release:
types:
- published
repository_dispatch:
types: [version-released]

jobs:
build:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '12'
- name: Configure git
run: |
git config --global user.email "reportportal.io"
Expand Down Expand Up @@ -139,3 +143,9 @@ jobs:
body: ${{ needs.create-tag.outputs.versionInfo }}
draft: false
prerelease: false
- name: Trigger the publish workflow
if: success()
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.GH_TOKEN }}
event-type: version-released
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
### Fixed
- `skippedIssue` config property processing using .mocharc or string values
- Skipped test duplication
- Config attributes parsing using .mocharc

### Security
- Versions of several vulnerable dependencies updated

### Added
- `mode` option for submitting results to Debug tab
- Latest error log to the step description

### Changed
- Package size reduced

## [5.0.1] - 2020-06-23
### Added
- Added link to the example in readme.
- Added link to the example in readme.

## [5.0.0] - 2020-06-22
### Added
Expand Down
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ npm install @reportportal/agent-js-mocha
```

## How to use:
Fill reporterOptions in Mocha configuration.
Fill reporterOptions in Mocha configuration.
```javascript
const Mocha = require("mocha");
let mochaMain = new Mocha({
reporter: '@reportportal/agent-js-mocha',
reporterOptions: {
"token": "00000000-0000-0000-0000-000000000000",
"token": "00000000-0000-0000-0000-000000000000",
"endpoint": "https://your.reportportal.server/api/v1",
"project": "YourReportPortalProjectName",
"launch": "YourLauncherName",
Expand All @@ -31,6 +31,25 @@ let mochaMain = new Mocha({
]
}
});
```
Using `.mocharc.js`:
```javascript
module.exports = {
'extension': ['js', 'cjs', 'mjs'],
'package': './package.json',
reporter: '@reportportal/agent-js-mocha',
'reporter-option':[
'endpoint=https://your.reportportal.server/api/v1',
'token=00000000-0000-0000-0000-000000000000',
'launch=YourLauncherName',
'project=YourReportPortalProjectName',
'attributes=YourKey:YourValue;YourValue',
],
'file': [
'spec/someTest.spec.js',
]
}

```

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

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

#### Integration with Sauce Labs

To integrate with Sauce Labs just add attributes:
To integrate with Sauce Labs just add attributes:

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

#### Report description for steps and suites

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

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.
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.

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

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

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

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.
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.

**Example:**
```javascript
Expand Down Expand Up @@ -233,7 +253,7 @@ describe('suite',()=>{
});
});
```

# Copyright Notice

Licensed under the [Apache License v2.0](LICENSE)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.1
5.0.2-SNAPSHOT
22 changes: 15 additions & 7 deletions lib/mochaReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { EVENTS } = require('@reportportal/client-javascript/lib/constants/events
const { entityType, hookTypes, hookTypesMap } = require('./constants/itemTypes');
const logLevels = require('./constants/logLevels');
const testStatuses = require('./constants/testStatuses');
const { getCodeRef, getAgentInfo } = require('./utils');
const { getCodeRef, getAgentInfo, parseAttributes } = require('./utils');

const {
EVENT_RUN_BEGIN,
Expand Down Expand Up @@ -151,7 +151,8 @@ class ReportportalAgent extends Mocha.reporters.Base {
system: true,
},
];
if (this.options.reporterOptions.skippedIssue === false) {
if (String(this.options.reporterOptions.skippedIssue).toLowerCase() === 'false') {
this.options.reporterOptions.skippedIssue = false;
const skippedIssueAttribute = {
key: 'skippedIssue',
value: 'false',
Expand All @@ -164,14 +165,14 @@ class ReportportalAgent extends Mocha.reporters.Base {

onLaunchStart() {
const systemAttributes = this.getSystemAttributes();
const launchAttributes = (this.options.reporterOptions.attributes || []).concat(
systemAttributes,
);
const attributes = parseAttributes(this.options.reporterOptions.attributes);
const launchAttributes = (attributes || []).concat(systemAttributes);
const { tempId, promise } = this.rpClient.startLaunch({
token: this.options.reporterOptions.token,
name: this.options.reporterOptions.launch,
startTime: this.rpClient.helpers.now(),
description: this.options.reporterOptions.description,
mode: this.options.reporterOptions.mode,
rerun: this.options.reporterOptions.rerun,
rerunOf: this.options.reporterOptions.rerunOf,
attributes: launchAttributes,
Expand Down Expand Up @@ -271,7 +272,12 @@ class ReportportalAgent extends Mocha.reporters.Base {
finishTest(test, autoStatus) {
if (this.currentTest) {
const testAttributes = this.attributes.get(this.currentTest.tempId);
const testDescription = this.descriptions.get(this.currentTest.tempId);
let testDescription = this.descriptions.get(this.currentTest.tempId);
if (test.err) {
testDescription = (testDescription || '').concat(
`\n\`\`\`error\n${test.err.stack}\n\`\`\``,
);
}
const testCaseId = this.testCaseIds.get(this.currentTest.tempId);
const testStatus = this.testItemStatuses.get(this.currentTest.tempId) || autoStatus;
const withoutIssue =
Expand Down Expand Up @@ -352,7 +358,9 @@ class ReportportalAgent extends Mocha.reporters.Base {
}

onTestPending(test) {
this.onTestStart(test);
if (this.currentTest === null) {
this.onTestStart(test);
}
this.finishTest(test, testStatuses.SKIPPED);
}

Expand Down
14 changes: 13 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ const getAgentInfo = () => ({
name: pjson.name,
});

module.exports = { getCodeRef, getAgentInfo };
const parseAttributes = (attributes) => {
if (typeof attributes === 'string') {
return attributes.split(';').map((attributeStr) => {
const attribute = attributeStr.split(':');
return attribute.length === 2
? { key: attribute[0], value: attribute[1] }
: { value: attribute[0] };
});
}
return attributes;
};

module.exports = { getCodeRef, getAgentInfo, parseAttributes };
Loading

0 comments on commit 0bd6319

Please sign in to comment.