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

RPP-82475 Test runner migration to Jest #208

Merged
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 .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 @@
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,11 +49,11 @@
});

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

getApiKey({ token: '1' });

expect(console.warn).toHaveBeenCalledWith(

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

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement
`Option 'token' is deprecated. Use 'apiKey' instead.`,
);
});
Expand All @@ -75,42 +72,42 @@

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 (20)

Unexpected console statement

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 (12)

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 (14)

Unexpected console statement
new ReportPortalValidationError('`options` must be an object.'),
);
});

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',
});

expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('endpoint'));

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

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement
});

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',
});

expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('project'));

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

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement
});

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',
});

expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('apiKey'));

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

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement
});
});
});
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
Loading