Skip to content

Commit

Permalink
Merge pull request #130 from reportportal/update-deps
Browse files Browse the repository at this point in the history
Update deps. Add prettier
  • Loading branch information
AmsterGet authored Jul 17, 2023
2 parents a8c098c + 3eaf291 commit c10f04d
Show file tree
Hide file tree
Showing 14 changed files with 2,611 additions and 2,595 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "airbnb-base",
"extends": [
"airbnb-base",
"plugin:prettier/recommended",
"plugin:import/recommended"
],
"plugins": ["prettier"],
"globals": {
"expectAsync": true
},
Expand All @@ -8,7 +13,6 @@
"es6": true
},
"rules": {
"indent": ["error", 4],
"max-len": ["error", 120],
"valid-jsdoc": ["error", { "requireReturn": false }],
"consistent-return": 0,
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Changed
- `token` configuration option was renamed to `apiKey` to maintain common convention.
- `@reportportal/client-javascript` bumped to version `5.0.12`.
- Readme file updated.

## [5.0.5] - 2023-03-16
### Added
Expand Down
202 changes: 104 additions & 98 deletions __tests__/getOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,113 +18,119 @@
const fs = require('fs');
const path = require('path');
const process = require('process');
const {
options,
getAppOptions,
getEnvOptions,
} = require('../utils/getOptions');
const { options, getAppOptions, getEnvOptions } = require('../utils/getOptions');
const constants = require('../constants/index');

describe('Get Options script', () => {
const OLD_ENV = process.env;
const processCwdValue = process.cwd();

beforeEach(() => {
jest.resetModules();
process.env = { ...OLD_ENV };
delete process.env.NODE_ENV;
const OLD_ENV = process.env;
const processCwdValue = process.cwd();

beforeEach(() => {
jest.resetModules();
process.env = { ...OLD_ENV };
delete process.env.NODE_ENV;
});

afterEach(() => {
jest.clearAllMocks();
process.env = OLD_ENV;
});

describe('getEnvOptions', () => {
test("should return empty envOptions object if environments don't set", () => {
const envOptionsObject = getEnvOptions();

expect(envOptionsObject).toBeDefined();
expect(envOptionsObject).toEqual({});
});

afterEach(() => {
jest.clearAllMocks();
process.env = OLD_ENV;
test('should return envOptions object with correct values', () => {
const expectedEnvOptionsObject = {
suiteName: 'suite name',
output: 'output',
classNameTemplate: 'class name',
titleTemplate: 'title',
};
process.env = {
JEST_SUITE_NAME: 'suite name',
JEST_JUNIT_OUTPUT: 'output',
JEST_JUNIT_CLASSNAME: 'class name',
JEST_JUNIT_TITLE: 'title',
};

const envOptionsObject = getEnvOptions();

expect(envOptionsObject).toBeDefined();
expect(envOptionsObject).toEqual(expectedEnvOptionsObject);
});
});

describe('getEnvOptions', () => {
test('should return empty envOptions object if environments don\'t set', () => {
const envOptionsObject = getEnvOptions();

expect(envOptionsObject).toBeDefined();
expect(envOptionsObject).toEqual({});
});

test('should return envOptions object with correct values', () => {
const expectedEnvOptionsObject = {
suiteName: 'suite name',
output: 'output',
classNameTemplate: 'class name',
titleTemplate: 'title',
};
process.env = {
JEST_SUITE_NAME: 'suite name',
JEST_JUNIT_OUTPUT: 'output',
JEST_JUNIT_CLASSNAME: 'class name',
JEST_JUNIT_TITLE: 'title',
};

const envOptionsObject = getEnvOptions();

expect(envOptionsObject).toBeDefined();
expect(envOptionsObject).toEqual(expectedEnvOptionsObject);
});
});
describe('getAppOptions', () => {
test('should return empty AppOptions object if fs.existsSync return false', () => {
const pathToResolve = `${path.sep}path${path.sep}to${path.sep}directory`;
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(false);

describe('getAppOptions', () => {
test('should return empty AppOptions object if fs.existsSync return false', () => {
const pathToResolve = `${path.sep}path${path.sep}to${path.sep}directory`;
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(false);

const appOptionsObject = getAppOptions(pathToResolve);

expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({});
});

test('should return empty AppOptions object if fs.existsSync return true and type of options'
+ ' is not [object Object]', () => {
const spyProcessCwd = jest.spyOn(process, 'cwd');
// eslint-disable-next-line max-len
spyProcessCwd.mockReturnValue(`${processCwdValue}${path.sep}__tests__${path.sep}fixtures${path.sep}mockedPackageJsonString`);
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(true);

const appOptionsObject = getAppOptions(process.cwd());

expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({});

spyProcessCwd.mockClear();
});

test('should return AppOptions object if fs.existsSync return true and type of options'
+ ' is [object Object]', () => {
const spyProcessCwd = jest.spyOn(process, 'cwd');
// eslint-disable-next-line max-len
spyProcessCwd.mockReturnValue(`${processCwdValue}${path.sep}__tests__${path.sep}fixtures${path.sep}mockedPackageJsonObject`);
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(true);

const appOptionsObject = getAppOptions(process.cwd());

expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({ keyOne: 'valueOne' });
});
});
const appOptionsObject = getAppOptions(pathToResolve);

describe('options', () => {
test('should return options object with empty reporterOptions object', () => {
const expectedOptions = { ...constants.DEFAULT_OPTIONS };
const spyProcessCwd = jest.spyOn(process, 'cwd');
spyProcessCwd.mockReturnValue(processCwdValue);

const optionsObject = options();
expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({});
});

expect(optionsObject).toBeDefined();
expect(optionsObject).toEqual(expectedOptions);
});
test(
'should return empty AppOptions object if fs.existsSync return true and type of options' +
' is not [object Object]',
() => {
const spyProcessCwd = jest.spyOn(process, 'cwd');
// eslint-disable-next-line max-len
spyProcessCwd.mockReturnValue(
`${processCwdValue}${path.sep}__tests__${path.sep}fixtures${path.sep}mockedPackageJsonString`,
);
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(true);

const appOptionsObject = getAppOptions(process.cwd());

expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({});

spyProcessCwd.mockClear();
},
);

test(
'should return AppOptions object if fs.existsSync return true and type of options' +
' is [object Object]',
() => {
const spyProcessCwd = jest.spyOn(process, 'cwd');
// eslint-disable-next-line max-len
spyProcessCwd.mockReturnValue(
`${processCwdValue}${path.sep}__tests__${path.sep}fixtures${path.sep}mockedPackageJsonObject`,
);
jest.mock('fs');
fs.existsSync = jest.fn();
fs.existsSync.mockReturnValue(true);

const appOptionsObject = getAppOptions(process.cwd());

expect(appOptionsObject).toBeDefined();
expect(appOptionsObject).toEqual({ keyOne: 'valueOne' });
},
);
});

describe('options', () => {
test('should return options object with empty reporterOptions object', () => {
const expectedOptions = { ...constants.DEFAULT_OPTIONS };
const spyProcessCwd = jest.spyOn(process, 'cwd');
spyProcessCwd.mockReturnValue(processCwdValue);

const optionsObject = options();

expect(optionsObject).toBeDefined();
expect(optionsObject).toEqual(expectedOptions);
});
});
});
Loading

0 comments on commit c10f04d

Please sign in to comment.