Skip to content
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

Release 5.2.0 #93

Merged
merged 10 commits into from
Oct 3, 2024
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 .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
run: npm install
- name: Run lint
run: npm run lint
- name: Check coverage
- name: Run tests and check coverage
run: npm run test:coverage
4 changes: 1 addition & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ jobs:
run: npm install
- name: Run lint
run: npm run lint
- name: Run tests
run: npm test
- name: Check coverage
- name: Run tests and check coverage
run: npm run test:coverage

publish-to-npm-and-gpr:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Changed
- **Breaking change** Drop support of Node.js 12. The version [5.1.0](https://github.com/reportportal/agent-js-jasmine/releases/tag/v5.1.0) is the latest that supports it.
- The agent now supports reporting the time for launches, test items and logs with microsecond precision in the ISO string format.
For logs, microsecond precision is available on the UI from ReportPortal [version 24.2](https://reportportal.io/docs/releases/Version24.2/#:~:text=import%20plugin.-,Microseconds,-added%20to%20timestamps).
- `@reportportal/client-javascript` bumped to version `5.3.0`.
### Security
- Updated versions of vulnerable packages (micromatch).

## [5.1.0] - 2024-07-16
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Agent to integrate Jasmine with ReportPortal.
* More about [Jasmine](https://jasmine.github.io/)
* More about [ReportPortal](http://reportportal.io/)
* More about [ReportPortal](https://reportportal.io/)

## Installation

Expand Down Expand Up @@ -43,7 +43,7 @@ The full list of available options presented below.
| project | Required | | The name of the project in which the launches will be created. |
| attributes | Optional | [] | Launch attributes. |
| description | Optional | '' | Launch description. |
| rerun | Optional | false | Enable [rerun](https://reportportal.io/docs/dev-guides/RerunDevelopersGuide) |
| rerun | Optional | false | Enable [rerun](https://reportportal.io/docs/developers-guides/RerunDevelopersGuide/) |
| rerunOf | Optional | Not set | UUID of launch you want to rerun. If not specified, ReportPortal will update the latest launch with the same name |
| mode | Optional | 'DEFAULT' | Results will be submitted to Launches page <br/> *'DEBUG'* - Results will be submitted to Debug page. |
| skippedIssue | Optional | true | ReportPortal provides feature to mark skipped tests as not 'To Investigate'. <br/> Option could be equal boolean values: <br/> *true* - skipped tests considered as issues and will be marked as 'To Investigate' on ReportPortal. <br/> *false* - skipped tests will not be marked as 'To Investigate' on application. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
5.1.1-SNAPSHOT
54 changes: 54 additions & 0 deletions __mocks__/@reportportal/client-javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

class RPClientMock {
constructor(config) {
this.config = config;

this.startLaunch = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
tempId: 'tempLaunchId',
});

this.finishLaunch = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});

this.startTestItem = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
tempId: 'testItemId',
});

this.finishTestItem = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});

this.sendLog = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});

this.getPromiseFinishAllItems = jest.fn().mockResolvedValue({
promise: Promise.resolve('ok'),
});

this.checkConnect = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});
}
}

module.exports = RPClientMock;
43 changes: 22 additions & 21 deletions __tests__/jasmine-reportportal-reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const helpers = require('@reportportal/client-javascript/lib/helpers');
const Reporter = require('../lib/jasmine-reportportal-reporter');
const SpecificUtils = require('../lib/specificUtils');

describe('jasmine Report Portal reporter', () => {
const Reporter = require('../lib/jasmine-reportportal-reporter');
const SpecificUtils = require('../lib/specificUtils');
const mockedDate = '2024-09-23T12:20:59.392987Z';

describe('jasmine Report Portal reporter', () => {
let reporter;
const tempLaunchId = 'ewrf35432r';
let promise;
let baseTime;

beforeEach(() => {
jest.useFakeTimers();
jest.spyOn(helpers, 'now').mockReturnValue(mockedDate);
// TODO: should be replaced with unregistering specific listeners only
process.removeAllListeners();
const client = {
startTestItem() {},
finishTestItem() {},
sendLog() {},
};
const onSetLaunchStatus = function () {};

Check warning on line 36 in __tests__/jasmine-reportportal-reporter.spec.js

View workflow job for this annotation

GitHub Actions / test

Unexpected unnamed function

Check warning on line 36 in __tests__/jasmine-reportportal-reporter.spec.js

View workflow job for this annotation

GitHub Actions / test

Unexpected unnamed function
baseTime = new Date(2020, 4, 8);
jest.setSystemTime(baseTime);
reporter = new Reporter(
{
client,
Expand Down Expand Up @@ -363,7 +364,7 @@
level: 'level',
file: null,
message: 'message',
time: baseTime.valueOf(),
time: mockedDate,
},
],
};
Expand All @@ -381,13 +382,13 @@
level: 'level',
file: null,
message: 'message',
time: baseTime.valueOf(),
time: mockedDate,
},
{
level: 'level1',
file: null,
message: 'message1',
time: baseTime.valueOf(),
time: mockedDate,
},
],
};
Expand Down Expand Up @@ -448,7 +449,7 @@
{
message: 'message',
level: 'level',
time: baseTime.valueOf(),
time: mockedDate,
},
null
);
Expand All @@ -465,7 +466,7 @@
{
message: '',
level: 'level',
time: baseTime.valueOf(),
time: mockedDate,
},
undefined
);
Expand Down Expand Up @@ -604,7 +605,7 @@
description: 'text description',
testCaseId: 'testCaseId',
codeRef: 'codeRef',
startTime: baseTime.valueOf(),
startTime: mockedDate,
},
tempLaunchId,
null
Expand Down Expand Up @@ -653,7 +654,7 @@
description: 'test description',
name: 'test description',
codeRef: 'codeRef',
startTime: baseTime.valueOf(),
startTime: mockedDate,
},
tempLaunchId,
null
Expand All @@ -674,7 +675,7 @@
promise.then(() => {
expect(reporter.setParentInfo).toHaveBeenCalledWith({
tempId: '3452',
startTime: baseTime.valueOf(),
startTime: mockedDate,
});

done();
Expand Down Expand Up @@ -759,14 +760,14 @@
tempId: '3452',
promise: Promise.resolve(),
});
jest.spyOn(reporter, 'getHookStartTime').mockReturnValue(baseTime.valueOf());
jest.spyOn(reporter, 'getHookStartTime').mockReturnValue(mockedDate);

reporter.hookStarted('beforeAll');

expect(reporter.client.startTestItem).toHaveBeenCalledWith(
{
type: 'BEFORE_SUITE',
startTime: baseTime.valueOf(),
startTime: mockedDate,
name: 'beforeAll',
},
tempLaunchId,
Expand All @@ -787,7 +788,7 @@

expect(reporter.client.finishTestItem).toHaveBeenCalledWith('3452', {
status: 'passed',
endTime: baseTime.valueOf(),
endTime: mockedDate,
});
expect(reporter.itemStartTime).toEqual(null);
});
Expand All @@ -802,7 +803,7 @@

expect(reporter.client.finishTestItem).toHaveBeenCalledWith('3452', {
status: 'failed',
endTime: baseTime.valueOf(),
endTime: mockedDate,
});
});

Expand Down Expand Up @@ -879,7 +880,7 @@
{
message: 'message: error\nstackTrace: stack',
level: 'ERROR',
time: baseTime.valueOf(),
time: mockedDate,
},
null
);
Expand Down Expand Up @@ -978,7 +979,7 @@
{
message: 'message: error\nstackTrace: stack',
level: 'ERROR',
time: baseTime.valueOf(),
time: mockedDate,
},
null
);
Expand Down
7 changes: 5 additions & 2 deletions __tests__/reportportal-agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SpecificUtils = require('../lib/specificUtils');

const reporterOptions = {
apiKey: 'reportportalApiKey',
endpoint: 'endpoint',
endpoint: 'http://reportportal.example.com/api/v1',
project: 'projectName',
launch: 'launcherName',
description: 'description',
Expand All @@ -44,10 +44,13 @@ describe('Report Portal agent', () => {
let agent;

beforeAll(() => {
jest.clearAllMocks(); // Clear mocks before initialization
agent = new ReportportalAgent(options);
});

beforeEach(() => {
jest.clearAllMocks(); // Clear mocks before initialization
});

it('should be properly initialized', () => {
expect(agent.tempLaunchId).toBeDefined();
expect(agent.client).toBeDefined();
Expand Down
28 changes: 28 additions & 0 deletions __tests__/specificUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,33 @@ describe('Specific Utils', () => {
expect(escapeString).toBe('\\_test\\*');
});
});

describe('convertIsoStringToMicroseconds', () => {
it('converts ISO string with microseconds correctly', () => {
const isoString = '2024-09-20T14:32:35.304456Z';
const expectedMicroseconds = 1726842755304456;
expect(SpecificUtils.convertIsoStringToMicroseconds(isoString)).toBe(expectedMicroseconds);
});

it('handles microseconds accurately', () => {
const isoString = '2021-03-15T12:00:00.000001Z';
const expectedMicroseconds = 1615809600000001;
expect(SpecificUtils.convertIsoStringToMicroseconds(isoString)).toBe(expectedMicroseconds);
});

it('returns correct microseconds at epoch start', () => {
const isoString = '1970-01-01T00:00:00.000001Z';
const expectedMicroseconds = 1;
expect(SpecificUtils.convertIsoStringToMicroseconds(isoString)).toBe(expectedMicroseconds);
});
});

describe('getBeforeHookStartTime', () => {
it('should return the start time for the hook as reduced time from test item start by 1 millisecond', () => {
const itemStartTime = '2024-09-20T14:32:35.304456Z';
const expectedHookStartTime = '2024-09-20T14:32:35.303456Z';
expect(SpecificUtils.getBeforeHookStartTime(itemStartTime)).toBe(expectedHookStartTime);
});
});
});
});
4 changes: 3 additions & 1 deletion lib/jasmine-reportportal-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const { EVENTS } = require('@reportportal/client-javascript/lib/constants/events');
const { RP_STATUSES } = require('@reportportal/client-javascript/lib/constants/statuses');
const clientHelpers = require('@reportportal/client-javascript/lib/helpers');
const SpecificUtils = require('./specificUtils');
const { entityType, hookTypes, hookTypesMap } = require('./constants/itemTypes');
const LOG_LEVELS = require('./constants/logLevels');
Expand All @@ -23,7 +24,7 @@

const promiseErrorHandler = (promise) => {
promise.catch((err) => {
console.error(err);

Check warning on line 27 in lib/jasmine-reportportal-reporter.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 27 in lib/jasmine-reportportal-reporter.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
});
};

Expand Down Expand Up @@ -84,7 +85,7 @@
}

getTime() {
return new Date().valueOf();
return clientHelpers.now();
}

addAttributes(attr) {
Expand Down Expand Up @@ -282,6 +283,7 @@
});
}

// TODO: update
getHookStartTime(hookType, parent) {
if (hookType === entityType.BEFORE_METHOD || hookType === entityType.BEFORE_SUITE) {
return Math.max(parent && parent.startTime, this.itemStartTime - 1);
Expand Down
Loading