Skip to content

Commit

Permalink
EPMRPP-82475 || Test runner migration to Jest (#208)
Browse files Browse the repository at this point in the history
* update tests

* update tests

* fix

* collect coverage via jest only

* update package-lock.json
  • Loading branch information
artsiomBandarenka authored Jul 31, 2024
1 parent 6530dd4 commit b2d4f46
Show file tree
Hide file tree
Showing 10 changed files with 2,441 additions and 1,026 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"env": {
"node": true,
"es6": true,
"jasmine": true
"jest": true
},
"rules": {
"valid-jsdoc": ["error", { "requireReturn": false }],
Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
moduleFileExtensions: ['js'],
"testMatch": [
"<rootDir>/spec/**/*[sS]pec.js"
],
coverageReporters: ["lcov", "text-summary"],
bail: false,
};
3,127 changes: 2,270 additions & 857 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"clean": "rimraf ./build",
"lint": "eslint ./statistics/**/* ./lib/**/* ./spec/**/*",
"format": "npm run lint -- --fix",
"test": "nyc ./node_modules/jasmine/bin/jasmine.js",
"test:coverage": "nyc report --reporter=lcov --reporter=text-summary"
"test": "jest",
"test:coverage": "jest --coverage"
},
"directories": {
"lib": "./lib"
Expand All @@ -33,7 +33,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/jasmine": "^4.6.4",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.8",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "^5.62.0",
Expand All @@ -44,13 +44,12 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"jasmine": "^3.10.0",
"jasmine-ts": "^0.4.0",
"jest": "^29.7.0",
"lodash": "^4.17.21",
"nock": "^13.5.0",
"nyc": "^15.1.0",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
},
Expand Down
33 changes: 15 additions & 18 deletions spec/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ describe('Config commons test suite', () => {
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
});

it(
'should throw ReportPortalRequiredOptionError in case of option ' + 'not present in options',
() => {
let error;
try {
getRequiredOption({ other: 1 }, 'project');
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
},
);
it('should throw ReportPortalRequiredOptionError in case of option not present in options', () => {
let error;
try {
getRequiredOption({ other: 1 }, 'project');
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
});
});

describe('getApiKey', () => {
Expand All @@ -52,7 +49,7 @@ describe('Config commons test suite', () => {
});

it('should print warning to console if deprecated token option used', () => {
spyOn(console, 'warn');
jest.spyOn(console, 'warn').mockImplementation();

getApiKey({ token: '1' });

Expand All @@ -75,7 +72,7 @@ describe('Config commons test suite', () => {

describe('getClientConfig', () => {
it('should print ReportPortalValidationError error to the console in case of options is not an object type', () => {
spyOn(console, 'dir');
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig('options');

expect(console.dir).toHaveBeenCalledWith(

Check warning on line 78 in spec/config.spec.js

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

Check warning on line 78 in spec/config.spec.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

Check warning on line 78 in spec/config.spec.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check warning on line 78 in spec/config.spec.js

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

Check warning on line 78 in spec/config.spec.js

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement
Expand All @@ -84,7 +81,7 @@ describe('Config commons test suite', () => {
});

it('should print ReportPortalRequiredOptionError to the console in case of "endpoint" option missed', () => {
spyOn(console, 'dir');
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
apiKey: '123',
project: 'prj',
Expand All @@ -94,7 +91,7 @@ describe('Config commons test suite', () => {
});

it('should print ReportPortalRequiredOptionError to the console in case of "project" option missed', () => {
spyOn(console, 'dir');
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
apiKey: '123',
endpoint: 'https://abc.com',
Expand All @@ -104,7 +101,7 @@ describe('Config commons test suite', () => {
});

it('should print ReportPortalRequiredOptionError to the console in case of "apiKey" option missed', () => {
spyOn(console, 'dir');
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
project: 'prj',
endpoint: 'https://abc.com',
Expand Down
23 changes: 9 additions & 14 deletions spec/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const RestClient = require('../lib/rest');
const pjson = require('../package.json');

describe('Helpers', () => {

describe('formatName', () => {
it('slice last 256 symbols', () => {
expect(helpers.formatName(`a${'b'.repeat(256)}`)).toBe('b'.repeat(256));
Expand All @@ -30,7 +29,7 @@ describe('Helpers', () => {

describe('getServerResults', () => {
it('calls RestClient#request', () => {
spyOn(RestClient, 'request');
jest.spyOn(RestClient, 'request').mockImplementation();

helpers.getServerResult(
'http://localhost:80/api/v1',
Expand Down Expand Up @@ -58,7 +57,7 @@ describe('Helpers', () => {

describe('readLaunchesFromFile', () => {
it('should return the right ids', () => {
spyOn(glob, 'sync').and.returnValue(['rplaunch-fileOne.tmp', 'rplaunch-fileTwo.tmp']);
jest.spyOn(glob, 'sync').mockReturnValue(['rplaunch-fileOne.tmp', 'rplaunch-fileTwo.tmp']);

const ids = helpers.readLaunchesFromFile();

Expand All @@ -68,19 +67,19 @@ describe('Helpers', () => {

describe('saveLaunchIdToFile', () => {
it('should call fs.open method with right parameters', () => {
spyOn(fs, 'open');
jest.spyOn(fs, 'open').mockImplementation();

helpers.saveLaunchIdToFile('fileOne');

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

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

describe('saveLaunchUuidToFile', () => {
it('should call fs.open method with right parameters', () => {
spyOn(fs, 'open');
jest.spyOn(fs, 'open').mockImplementation();

helpers.saveLaunchUuidToFile('fileOne');

expect(fs.open).toHaveBeenCalledWith(
'rp-launch-uuid-fileOne.tmp',
'w',
jasmine.any(Function),
);
expect(fs.open).toHaveBeenCalledWith('rp-launch-uuid-fileOne.tmp', 'w', expect.any(Function));
});
});
});
14 changes: 7 additions & 7 deletions spec/publicReportingAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { EVENTS } = require('../lib/constants/events');

describe('PublicReportingAPI', () => {
it('setDescription should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.setDescription('text', 'suite');

Expand All @@ -14,7 +14,7 @@ describe('PublicReportingAPI', () => {
});

it('addAttributes should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.addAttributes([{ value: 'value' }], 'suite');

Expand All @@ -25,7 +25,7 @@ describe('PublicReportingAPI', () => {
});

it('addLog should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.addLog({ level: 'INFO', message: 'message' }, 'suite');

Expand All @@ -36,7 +36,7 @@ describe('PublicReportingAPI', () => {
});

it('addLaunchLog should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.addLaunchLog({ level: 'INFO', message: 'message' });

Expand All @@ -47,7 +47,7 @@ describe('PublicReportingAPI', () => {
});

it('setTestCaseId should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.setTestCaseId('testCaseId', 'suite');

Expand All @@ -58,15 +58,15 @@ describe('PublicReportingAPI', () => {
});

it('setLaunchStatus should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.setLaunchStatus('passed');

expect(process.emit).toHaveBeenCalledWith(EVENTS.SET_LAUNCH_STATUS, 'passed');
});

it('setStatus should trigger process.emit with correct parameters', () => {
spyOn(process, 'emit');
jest.spyOn(process, 'emit').mockImplementation();

PublicReportingAPI.setStatus('passed', 'suite');

Expand Down
Loading

0 comments on commit b2d4f46

Please sign in to comment.