Skip to content

Commit

Permalink
EPMRPP-94905 || Time with microseconds support (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsterGet authored Sep 23, 2024
1 parent c130a48 commit ca79a97
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 56 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ on:
- README.md
- CHANGELOG.md
pull_request:
branches:
- develop
- master
paths-ignore:
- README.md
- CHANGELOG.md

jobs:
test:
Expand All @@ -33,7 +39,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install of node dependencies
- name: Install dependencies
run: npm install
- name: Build the source code
run: npm run build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install of node dependencies
- name: Install dependencies
run: npm install
- name: Build the source code
run: npm run build
Expand All @@ -47,7 +47,7 @@ jobs:
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Install of node dependencies
- name: Install dependencies
run: npm install
- name: Build the source code
run: npm run build
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### Added
- Test case id, attributes and description providing via Reporting API.
- Test case id, attributes and description providing via [Reporting API](./README.md#reporting-api-methods).
### Changed
- `@reportportal/client-javascript` bumped to version `5.1.4`, new `launchUuidPrintOutput` types introduced: 'FILE', 'ENVIRONMENT'.
- 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.
- `@reportportal/client-javascript` bumped to version `5.3.0`, new `launchUuidPrintOutput` types introduced: 'FILE', 'ENVIRONMENT'.
### Security
- Updated versions of vulnerable packages (braces).

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ npm install --save-dev @reportportal/agent-js-vitest
import RPReporter from '@reportportal/agent-js-vitest'; // or import { RPReporter } from '@reportportal/agent-js-vitest';

const rpConfig = {
apiKey: '00000000-0000-0000-0000-000000000000',
endpoint: 'https://your.reportportal.server/api/v2',
apiKey: '<API_KEY>',
endpoint: 'https://your.reportportal.server/api/v1',
project: 'Your ReportPortal project name',
launch: 'Your launch name',
attributes: [
Expand Down Expand Up @@ -48,7 +48,7 @@ The full list of available options presented below.
| Option | Necessity | Default | Description |
|------------------------------------|-----------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| apiKey | Required | | User's ReportPortal token from which you want to send requests. It can be found on the profile page of this user. |
| endpoint | Required | | URL of your server. For example 'https://server:8080/api/v2'. |
| endpoint | Required | | URL of your server. For example 'https://server:8080/api/v1'. |
| launch | Required | | Name of launch at creation. |
| project | Required | | The name of the project in which the launches will be created. |
| attributes | Optional | [] | Launch attributes. |
Expand Down Expand Up @@ -79,6 +79,11 @@ The following options can be overridden using ENVIRONMENT variables:
}
```

## Asynchronous API

The client supports an asynchronous reporting (via the ReportPortal asynchronous API).
If you want the client to report through the asynchronous API, change `v1` to `v2` in the `endpoint` address.

## Reporting

When organizing tests, specify titles for `describe` blocks, as this is necessary to build the correct structure of reports.
Expand Down
15 changes: 7 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

module.exports = {
roots: ['<rootDir>/src'],
transform: { '.(ts|tsx)': 'ts-jest' },
transform: {
'.ts': ['ts-jest', {
diagnostics: {
pathRegex: '(/__tests__/.*?\\.(test|spec))\\.(ts|js)$',
},
}],
},
testEnvironment: 'node',
testRegex: '/__tests__/.*\\.(test|spec)?\\.(ts|js)$',
moduleFileExtensions: ['ts', 'js'],
Expand All @@ -31,11 +37,4 @@ module.exports = {
statements: 80,
},
},
globals: {
'ts-jest': {
diagnostics: {
pathRegex: '(/__tests__/.*?\\.(test|spec))\\.(ts|js)$',
},
},
},
};
47 changes: 38 additions & 9 deletions package-lock.json

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

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"name": "@reportportal/agent-js-vitest",
"version": "5.1.0",
"description": "Agent to integrate Vitest with ReportPortal.",
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf ./build",
"lint": "eslint \"src/**/*.ts\"",
"format": "npm run lint -- --fix",
"postbuild": "mkdir -p build && cp -R src/scripts build/",
"test": "jest",
"test:coverage": "jest --coverage"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"exports": {
Expand All @@ -14,21 +23,12 @@
"require": "./build/scripts/setup.js"
}
},
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf ./build",
"lint": "eslint \"src/**/*.ts\"",
"format": "npm run lint -- --fix",
"postbuild": "mkdir -p build && cp -R src/scripts build/",
"test": "jest",
"test:coverage": "jest --coverage"
},
"dependencies": {
"@reportportal/client-javascript": "~5.1.4"
},
"files": [
"/build"
],
"dependencies": {
"@reportportal/client-javascript": "~5.3.0"
},
"devDependencies": {
"vitest": "^1.6.0",
"@types/jest": "^29.5.12",
Expand Down
6 changes: 1 addition & 5 deletions src/__tests__/mocks/RPClientMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReportPortalConfig } from '../../models';

const mockedDate = Date.now();
export const mockedDate = '2024-09-23T12:20:59.392987Z';
export class RPClientMock {
private config: ReportPortalConfig;

Expand Down Expand Up @@ -30,10 +30,6 @@ export class RPClientMock {
promise: Promise.resolve('ok'),
});

public helpers = {
now: (): number => mockedDate,
};

public checkConnect = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});
Expand Down
9 changes: 6 additions & 3 deletions src/__tests__/onTaskUpdate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as vitest from 'vitest';
import clientHelpers from '@reportportal/client-javascript/lib/helpers';
import { RPReporter } from '../reporter';
import { config } from './mocks/configMock';
import { RPClientMock } from './mocks/RPClientMock';
import * as vitest from 'vitest';
import { RPClientMock, mockedDate } from './mocks/RPClientMock';
import { RPTaskMeta } from '../models';
import { STATUSES, TASK_STATUS } from '../constants';

describe('onTaskUpdate', () => {
jest.spyOn(clientHelpers, 'now').mockReturnValue(mockedDate);

let reporter: RPReporter;
const testTaskId = 'testTaskId';
const testItemId = 'testId';
Expand Down Expand Up @@ -44,7 +47,7 @@ describe('onTaskUpdate', () => {
attributes,
description,
testCaseId,
endTime: reporter.client.helpers.now(),
endTime: '2024-09-23T12:20:59.392987Z',
};

reporter.onTaskUpdate(packs);
Expand Down
8 changes: 4 additions & 4 deletions src/models/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Attribute, Issue } from './common';
import { TEST_ITEM_TYPES, LOG_LEVELS, LAUNCH_MODES } from '../constants';

export interface StartLaunchObjType {
startTime?: number;
startTime?: string | number;
attributes?: Array<Attribute>;
description?: string;
name?: string;
Expand All @@ -35,14 +35,14 @@ export interface StartTestObjType {
type: TEST_ITEM_TYPES;
attributes?: Array<Attribute>;
description?: string;
startTime?: number;
startTime?: string | number;
codeRef?: string;
testCaseId?: string;
retry?: boolean;
}

export interface FinishTestItemObjType {
endTime?: number;
endTime?: string | number;
status?: string;
attributes?: Attribute[];
description?: string;
Expand All @@ -59,7 +59,7 @@ export interface Attachment {
export interface LogRQ {
level?: LOG_LEVELS;
message?: string;
time?: number;
time?: string | number;
file?: Attachment;
}

Expand Down
11 changes: 6 additions & 5 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import RPClient from '@reportportal/client-javascript';
import clientHelpers from '@reportportal/client-javascript/lib/helpers';
// eslint-disable-next-line import/named
import { File, Reporter, Task, TaskResult, TaskResultPack, UserConsoleLog, Vitest } from 'vitest';
import {
Expand Down Expand Up @@ -96,7 +97,7 @@ export class RPReporter implements Reporter {

const startLaunchObj: StartLaunchObjType = {
name: launch,
startTime: this.client.helpers.now(),
startTime: clientHelpers.now(),
description,
attributes:
attributes && attributes.length ? attributes.concat(systemAttributes) : systemAttributes,
Expand All @@ -120,7 +121,7 @@ export class RPReporter implements Reporter {

startDescendants(descendant: Task, basePath: string, parentId?: string) {
const { name, id, type, mode } = descendant;
const startTime = this.client.helpers.now();
const startTime = clientHelpers.now();
const isSuite = type === 'suite';
const codeRef = getCodeRef(basePath, parentId ? name : '');

Expand Down Expand Up @@ -213,7 +214,7 @@ export class RPReporter implements Reporter {
getFinishTestItemObj(taskResult?: TaskResult): FinishTestItemObjType {
const finishTestItemObj: FinishTestItemObjType = {
status: STATUSES.FAILED,
endTime: this.client.helpers.now(),
endTime: clientHelpers.now(),
};

if (taskResult) {
Expand Down Expand Up @@ -244,7 +245,7 @@ export class RPReporter implements Reporter {
testItemId,
{
level: LOG_LEVELS.INFO,
time: this.client.helpers.now(),
time: clientHelpers.now(),
...logRqWithoutFile,
},
file,
Expand Down Expand Up @@ -278,7 +279,7 @@ export class RPReporter implements Reporter {
async onFinished() {
if (!this.config.launchId) {
const { promise } = this.client.finishLaunch(this.launchId, {
endTime: this.client.helpers.now(),
endTime: clientHelpers.now(),
});
this.addRequestToPromisesQueue(promise, 'Failed to finish launch.');
}
Expand Down
3 changes: 2 additions & 1 deletion src/reportingApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vitest from 'vitest';
import clientHelpers from '@reportportal/client-javascript/lib/helpers';
import * as Models from './models';
import { isRPTaskMeta } from './utils';

Expand All @@ -22,7 +23,7 @@ const attachment = (task: vitest.Task, data: Models.Attachment, description?: st
injectRPTaskMeta(task);
(task.meta as Models.RPTaskMeta).rpMeta.test.logs.push({
file: data,
time: Date.now(),
time: clientHelpers.now(),
message: description || data.name,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ declare module '@reportportal/client-javascript' {
public finishTestItem(itemId: string, itemObj: any): any;

Check warning on line 25 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 25 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
public sendLog(itemId: string, itemObj: any, fileObj?: any): any;
public checkConnect(): any;
public helpers: any;
}
}
File renamed without changes.
Loading

0 comments on commit ca79a97

Please sign in to comment.