Skip to content

Allow setting description and attributes for suites #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class Reporter {
const suiteId = this.testItemIds.get(suite.id);
const suiteTestCaseId = this.suiteTestCaseIds.get(suite.title);
const suiteStatus = this.suiteStatuses.get(suite.title);
const suiteInfo = this.getCurrentSuiteInfo();

const finishTestItemPromise = this.client.finishTestItem(
suiteId,
Object.assign(
Expand All @@ -120,6 +122,8 @@ class Reporter {
},
suiteTestCaseId && { testCaseId: suiteTestCaseId },
suiteStatus && { status: suiteStatus },
suiteInfo && suiteInfo.description && { description: suiteInfo.description },
suiteInfo && suiteInfo.attributes && { attributes: suiteInfo.attributes },
),
).promise;
promiseErrorHandler(finishTestItemPromise, 'Fail to finish suite');
Expand Down Expand Up @@ -262,13 +266,21 @@ class Reporter {
}

addAttributes(attributes) {
this.currentTestFinishParams.attributes = this.currentTestFinishParams.attributes.concat(
attributes || [],
);
if (this.currentTestTempInfo == null && this.getCurrentSuiteInfo() != null) {
this.getCurrentSuiteInfo().attributes = attributes;
} else {
this.currentTestFinishParams.attributes = this.currentTestFinishParams.attributes.concat(
attributes || [],
);
}
}

setDescription(description) {
this.currentTestFinishParams.description = description;
if (this.currentTestTempInfo == null && this.getCurrentSuiteInfo() != null) {
this.getCurrentSuiteInfo().description = description;
} else {
this.currentTestFinishParams.description = description;
}
}

setTestCaseId({ testCaseId, suiteTitle }) {
Expand Down
30 changes: 30 additions & 0 deletions test/reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,36 @@ describe('reporter script', () => {
expect(spyFinishTestItem).toHaveBeenCalledTimes(1);
expect(spyFinishTestItem).toHaveBeenCalledWith('tempSuiteId', { endTime: currentDate });
});

it('finishTestItem should have description and attributes from suite stack top item', function() {
const spyFinishTestItem = jest.spyOn(reporter.client, 'finishTestItem');

const attributes = [{ key: 'test key', value: 'test value' }];
const description = 'test description';

reporter.testItemIds.set('suiteId', 'tempSuiteId');
reporter.suitesStackTempInfo.push({
tempId: 'tempSuiteId',
title: 'suite title',
});

const suiteEndObject = {
id: 'suiteId',
endTime: currentDate,
};

reporter.addAttributes(attributes);
reporter.setDescription(description);
reporter.suiteEnd(suiteEndObject);

expect(spyFinishTestItem).toHaveBeenCalledTimes(1);
expect(spyFinishTestItem).toHaveBeenCalledWith('tempSuiteId', {
description,
endTime: currentDate,
attributes,
});
});

it('end suite with testCaseId: finishTestItem should be called with testCaseId', function() {
const spyFinishTestItem = jest.spyOn(reporter.client, 'finishTestItem');
reporter.testItemIds.set('suiteId', 'tempSuiteId');
Expand Down