Skip to content
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
40 changes: 19 additions & 21 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"airbnb-base",
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:import/recommended"
],
"plugins": ["prettier", "import"],
"plugins": ["prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.eslint.json"
},
"globals": {
"expectAsync": true
},
"env": {
"node": true,
"es6": true,
"jest": true
"project": "./tsconfig.eslint.json"
},
"rules": {
"valid-jsdoc": ["error", { "requireReturn": false }],
"consistent-return": 0,
"@typescript-eslint/no-plusplus": 0,
"no-plusplus": 0,
"prettier/prettier": 2,
"class-methods-use-this": 0,
"no-else-return": 0,
"@typescript-eslint/lines-between-class-members": 0,
"lines-between-class-members": 0,
"import/no-extraneous-dependencies": 0,
"func-names": 0,
"import/prefer-default-export": 0,
"@typescript-eslint/naming-convention": 0,
"@typescript-eslint/dot-notation": 0,
"@typescript-eslint/ban-ts-ignore": 0,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove deprecated rule '@typescript-eslint/ban-ts-ignore' to prevent ESLint failure

This rule was removed years ago and will trigger “Definition for rule not found”.

Apply this diff:

-    "@typescript-eslint/ban-ts-ignore": 0,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"@typescript-eslint/ban-ts-ignore": 0,
🤖 Prompt for AI Agents
In .eslintrc around line 32, remove the deprecated rule entry
"@typescript-eslint/ban-ts-ignore": 0 because it no longer exists and causes
“Definition for rule not found” ESLint errors; either delete that line entirely
or replace it with the current equivalent (for example
"@typescript-eslint/ban-ts-comment": "off"/0 or another desired setting) to
prevent the ESLint failure.

"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-floating-promises": 2,
"max-classes-per-file": 0
"@typescript-eslint/no-implied-eval": 0,
"dot-notation": 0,
"@typescript-eslint/naming-convention": 0
}
}
2 changes: 1 addition & 1 deletion .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18, 20, 22]
node: [16, 18, 20, 22, 24]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
20 changes: 10 additions & 10 deletions __tests__/client-id.spec.js → __tests__/client-id.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require('fs');
const util = require('util');
const os = require('os');
const path = require('path');
const { v4: uuidv4 } = require('uuid');
const { getClientId } = require('../statistics/client-id');
import fs from 'fs';
import util from 'util';
import os from 'os';
import path from 'path';
import { v4 as uuidv4 } from 'uuid';
import { getClientId } from '../statistics/client-id';

const uuidv4Validation = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const clientIdFile = path.join(os.homedir(), '.rp', 'rp.properties');
Expand Down Expand Up @@ -36,12 +36,12 @@ describe('Client ID test suite', () => {
await unlink(clientIdFile);
const clientId = await getClientId();
const content = await readFile(clientIdFile, 'utf-8');
expect(content).toMatch(new RegExp(`^client\\.id\\s*=\\s*${clientId}\\s*(?:$|\n)`));
expect(content).toContain(`client.id=${clientId}`);
});

it('getClientId should read client ID from ~/.rp/rp.properties', async () => {
await unlink(clientIdFile);
const clientId = uuidv4(undefined, undefined, 0);
const clientId = uuidv4();
await writeFile(clientIdFile, `client.id=${clientId}\n`, 'utf-8');
expect(await getClientId()).toEqual(clientId);
});
Expand All @@ -51,7 +51,7 @@ describe('Client ID test suite', () => {
'first line',
async () => {
await unlink(clientIdFile);
const clientId = uuidv4(undefined, undefined, 0);
const clientId = uuidv4();
await writeFile(clientIdFile, `client.id=${clientId}\ntest.property=555\n`, 'utf-8');
expect(await getClientId()).toEqual(clientId);
},
Expand All @@ -62,7 +62,7 @@ describe('Client ID test suite', () => {
'first line',
async () => {
await unlink(clientIdFile);
const clientId = uuidv4(undefined, undefined, 0);
const clientId = uuidv4();
await writeFile(clientIdFile, `test.property=555\nclient.id=${clientId}\n`, 'utf-8');
expect(await getClientId()).toEqual(clientId);
},
Expand Down
10 changes: 5 additions & 5 deletions __tests__/config.spec.js → __tests__/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { getClientConfig, getRequiredOption, getApiKey } = require('../lib/commons/config');
const {
import { getClientConfig, getRequiredOption, getApiKey } from '../lib/commons/config';
import {
ReportPortalRequiredOptionError,
ReportPortalValidationError,
} = require('../lib/commons/errors');
} from '../lib/commons/errors';

describe('Config commons test suite', () => {
describe('getRequiredOption', () => {
Expand All @@ -26,7 +26,7 @@
it('should throw ReportPortalRequiredOptionError in case of option not present in options', () => {
let error;
try {
getRequiredOption({ other: 1 }, 'project');
getRequiredOption({ other: 1 } as any, 'project');

Check warning on line 29 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (22)

Unexpected any. Specify a different type

Check warning on line 29 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected any. Specify a different type

Check warning on line 29 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (24)

Unexpected any. Specify a different type

Check warning on line 29 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected any. Specify a different type

Check warning on line 29 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected any. Specify a different type
} catch (e) {
error = e;
}
Expand Down Expand Up @@ -73,7 +73,7 @@
describe('getClientConfig', () => {
it('should print ReportPortalValidationError error to the console in case of options is not an object type', () => {
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig('options');
getClientConfig('options' as any);

Check warning on line 76 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (22)

Unexpected any. Specify a different type

Check warning on line 76 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected any. Specify a different type

Check warning on line 76 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (24)

Unexpected any. Specify a different type

Check warning on line 76 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected any. Specify a different type

Check warning on line 76 in __tests__/config.spec.ts

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected any. Specify a different type

expect(console.dir).toHaveBeenCalledWith(
new ReportPortalValidationError('`options` must be an object.'),
Expand Down
49 changes: 40 additions & 9 deletions __tests__/helpers.spec.js → __tests__/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const os = require('os');
const fs = require('fs');
const glob = require('glob');
const helpers = require('../lib/helpers');
const pjson = require('../package.json');
import os from 'os';
import fs from 'fs';
import glob from 'glob';
import * as helpers from '../lib/helpers';
import pjson from '../package.json';

describe('Helpers', () => {
describe('formatName', () => {
Expand All @@ -22,7 +22,7 @@ describe('Helpers', () => {

describe('now', () => {
it('returns milliseconds from unix time', () => {
expect(new Date() - helpers.now()).toBeLessThan(100); // less than 100 miliseconds difference
expect(new Date().getTime() - helpers.now()).toBeLessThan(100); // less than 100 miliseconds difference
});
});

Expand All @@ -44,13 +44,22 @@ describe('Helpers', () => {

expect(fs.open).toHaveBeenCalledWith('rplaunch-fileOne.tmp', 'w', expect.any(Function));
});

it('should throw error when fs.open fails', () => {
const mockError = new Error('File system error');
jest.spyOn(fs, 'open').mockImplementation(() => {
throw mockError;
});

expect(() => helpers.saveLaunchIdToFile('fileOne')).toThrow('File system error');
});
});

describe('getSystemAttribute', () => {
it('should return correct system attributes', () => {
jest.spyOn(os, 'type').mockReturnValue('osType');
jest.spyOn(os, 'arch').mockReturnValue('osArchitecture');
jest.spyOn(os, 'totalmem').mockReturnValue('1');
jest.spyOn(os, 'totalmem').mockReturnValue(1);
const nodeVersion = process.version;
const expectedAttr = [
{
Expand Down Expand Up @@ -83,7 +92,7 @@ describe('Helpers', () => {

describe('generateTestCaseId', () => {
it('should return undefined if there is no codeRef', () => {
const testCaseId = helpers.generateTestCaseId();
const testCaseId = helpers.generateTestCaseId('');

expect(testCaseId).toEqual(undefined);
});
Expand All @@ -101,7 +110,7 @@ describe('Helpers', () => {
value: 'value',
},
{ value: 'valueTwo' },
{ key: 'keyTwo' },
{ key: 'keyTwo', value: '' },
{
key: 'keyThree',
value: 'valueThree',
Expand All @@ -112,6 +121,19 @@ describe('Helpers', () => {

expect(testCaseId).toEqual('codeRef[value,valueTwo,valueThree]');
});

it('should filter out parameters with falsy values', () => {
const parameters = [
{ value: 'value1' },
{ value: '' },
{ value: 'value2' },
{ value: 'value3' },
];

const testCaseId = helpers.generateTestCaseId('codeRef', parameters);

expect(testCaseId).toEqual('codeRef[value1,value2,value3]');
});
});

describe('saveLaunchUuidToFile', () => {
Expand All @@ -122,5 +144,14 @@ describe('Helpers', () => {

expect(fs.open).toHaveBeenCalledWith('rp-launch-uuid-fileOne.tmp', 'w', expect.any(Function));
});

it('should throw error when fs.open fails', () => {
const mockError = new Error('File system error');
jest.spyOn(fs, 'open').mockImplementation(() => {
throw mockError;
});

expect(() => helpers.saveLaunchUuidToFile('fileOne')).toThrow('File system error');
});
});
});
53 changes: 53 additions & 0 deletions __tests__/outputs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { OUTPUT_TYPES } from '../lib/constants/outputs';

describe('OUTPUT_TYPES', () => {
let consoleLogSpy: jest.SpyInstance;
let consoleErrorSpy: jest.SpyInstance;

beforeEach(() => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
process.env.RP_LAUNCH_UUID = '';
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('STDOUT', () => {
it('should log launch UUID to console.log', () => {
const testUuid = 'test-launch-uuid-123';

OUTPUT_TYPES.STDOUT(testUuid);

expect(consoleLogSpy).toHaveBeenCalledWith(`Report Portal Launch UUID: ${testUuid}`);
});
});

describe('STDERR', () => {
it('should log launch UUID to console.error', () => {
const testUuid = 'test-launch-uuid-456';

OUTPUT_TYPES.STDERR(testUuid);

expect(consoleErrorSpy).toHaveBeenCalledWith(`Report Portal Launch UUID: ${testUuid}`);
});
});

describe('ENVIRONMENT', () => {
it('should set RP_LAUNCH_UUID environment variable', () => {
const testUuid = 'test-launch-uuid-789';

OUTPUT_TYPES.ENVIRONMENT(testUuid);

expect(process.env.RP_LAUNCH_UUID).toBe(testUuid);
});
});

describe('FILE', () => {
it('should be a function reference to helpers.saveLaunchUuidToFile', () => {
expect(typeof OUTPUT_TYPES.FILE).toBe('function');
expect(OUTPUT_TYPES.FILE).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const PublicReportingAPI = require('../lib/publicReportingAPI');
const { EVENTS } = require('../lib/constants/events');
import PublicReportingAPI from '../lib/publicReportingAPI';

Check warning on line 1 in __tests__/publicReportingAPI.spec.ts

View workflow job for this annotation

GitHub Actions / test (22)

Using exported name 'PublicReportingAPI' as identifier for default export

Check warning on line 1 in __tests__/publicReportingAPI.spec.ts

View workflow job for this annotation

GitHub Actions / test (16)

Using exported name 'PublicReportingAPI' as identifier for default export

Check warning on line 1 in __tests__/publicReportingAPI.spec.ts

View workflow job for this annotation

GitHub Actions / test (24)

Using exported name 'PublicReportingAPI' as identifier for default export

Check warning on line 1 in __tests__/publicReportingAPI.spec.ts

View workflow job for this annotation

GitHub Actions / test (20)

Using exported name 'PublicReportingAPI' as identifier for default export

Check warning on line 1 in __tests__/publicReportingAPI.spec.ts

View workflow job for this annotation

GitHub Actions / test (18)

Using exported name 'PublicReportingAPI' as identifier for default export
import { EVENTS } from '../lib/constants/events';

describe('PublicReportingAPI', () => {
it('setDescription should trigger process.emit with correct parameters', () => {
Expand Down
Loading