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

chore: re-write some files to typescript - part 3 #489

Merged
merged 25 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7b021b0
chore: rename static report builder to typescript
shadowusr Aug 17, 2023
d28ecdb
chore: rename plugin-events to typescript
shadowusr Aug 18, 2023
ab721d9
chore: re-write plugin-events to typescript
shadowusr Aug 18, 2023
639e3ee
chore: re-write local-images-saver to typescript
shadowusr Aug 18, 2023
6d22922
chore: re-write browser constants to typescript
shadowusr Aug 18, 2023
15579a4
chore: rename base tests tree builder to typescript
shadowusr Aug 18, 2023
057feed
chore: re-write base tests tree builder to typescript
shadowusr Aug 18, 2023
3fa6add
chore: rename static tests tree builder to typescript
shadowusr Aug 18, 2023
0848c69
chore: re-write static tests tree builder to typescript
shadowusr Aug 19, 2023
1f22f1c
chore: rename db-utils/common to typescript
shadowusr Aug 19, 2023
7ae821e
chore: re-write db-utils/common to typescript
shadowusr Aug 19, 2023
571c775
chore: rename db-utils/server to typescript
shadowusr Aug 19, 2023
6fc1559
chore: re-write db-utils/server to typescript
shadowusr Aug 19, 2023
214df65
chore: rename plugin-api to typescript
shadowusr Aug 19, 2023
f95b736
chore: re-write plugin-api to typescript
shadowusr Aug 19, 2023
d4f1a16
chore: re-write static report builder to typescript
shadowusr Aug 19, 2023
676353a
chore: re-write create-workers to typescript
shadowusr Aug 19, 2023
72f998e
chore: re-write cli-commands/index to typescript
shadowusr Aug 19, 2023
9581923
chore: re-write defaults constants to typescript
shadowusr Aug 20, 2023
25fb2b3
chore: re-write save-formats constants to typescript
shadowusr Aug 20, 2023
36b35ad
chore: re-write custom-gui-asserts to typescript
shadowusr Aug 20, 2023
dd01de8
chore: re-write config to typescript
shadowusr Aug 21, 2023
9b21715
chore: re-write plugin-adapter to typescript
shadowusr Aug 21, 2023
a2ea259
chore: re-write suite-adapter to typescript
shadowusr Aug 22, 2023
6d04d3e
chore: fix cliCommands imports
shadowusr Aug 22, 2023
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 docs/en/html-reporter-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A database instance is passed to the event handler.
### Usage example

```javascript
const parseConfig = require('./config');
const {parseConfig} = require('./config');

module.exports = (hermione, opts) => {
const pluginConfig = parseConfig(opts);
Expand Down
2 changes: 1 addition & 1 deletion docs/ru/html-reporter-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ hermione.htmlReporter.on(hermione.htmlReporter.events.DATABASE_CREATED, (db) =>
### Пример использования

```javascript
const parseConfig = require('./config');
const {parseConfig} = require('./config');

module.exports = (hermione, opts) => {
const pluginConfig = parseConfig(opts);
Expand Down
4 changes: 2 additions & 2 deletions hermione.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const os = require('os');
const PQueue = require('p-queue');
const PluginAdapter = require('./lib/plugin-adapter');
const createWorkers = require('./lib/workers/create-workers');
const {PluginAdapter} = require('./lib/plugin-adapter');
const {createWorkers} = require('./lib/workers/create-workers');

let workers;

Expand Down
4 changes: 3 additions & 1 deletion lib/cli-commands/gui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

const {cliCommands} = require('.');
const runGui = require('../gui').default;
const Api = require('../gui/api');
const {GUI: commandName} = require('./');

const {GUI: commandName} = cliCommands;

module.exports = (program, pluginConfig, hermione) => {
// must be executed here because it adds `gui` field in `gemini` and `hermione tool`,
Expand Down
6 changes: 2 additions & 4 deletions lib/cli-commands/index.js → lib/cli-commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

module.exports = {
export const cliCommands = {
GUI: 'gui',
MERGE_REPORTS: 'merge-reports',
REMOVE_UNUSED_SCREENS: 'remove-unused-screens'
};
} as const;
4 changes: 3 additions & 1 deletion lib/cli-commands/merge-reports.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

const {MERGE_REPORTS: commandName} = require('./');
const {cliCommands} = require('.');
const mergeReports = require('../merge-reports');
const {logError} = require('../server-utils');

const {MERGE_REPORTS: commandName} = cliCommands;

module.exports = (program, pluginConfig, hermione) => {
program
.command(`${commandName} [paths...]`)
Expand Down
4 changes: 3 additions & 1 deletion lib/cli-commands/remove-unused-screens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const chalk = require('chalk');
const filesize = require('filesize');
const Promise = require('bluebird');

const {REMOVE_UNUSED_SCREENS: commandName} = require('..');
const {cliCommands} = require('..');
const {getTestsFromFs, findScreens, askQuestion, identifyOutdatedScreens, identifyUnusedScreens, removeScreens} = require('./utils');
const {DATABASE_URLS_JSON_NAME, LOCAL_DATABASE_NAME} = require('../../constants/database');
const {logger} = require('../../common-utils');

const {REMOVE_UNUSED_SCREENS: commandName} = cliCommands;

// TODO: remove hack after add ability to add controllers from plugin in silent mode
function proxyHermione() {
const proxyHandler = {
Expand Down
20 changes: 10 additions & 10 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import crypto from 'crypto';
import {pick} from 'lodash';
import url from 'url';
import axios, {AxiosRequestConfig} from 'axios';
import {SUCCESS, FAIL, ERROR, SKIPPED, UPDATED, IDLE, RUNNING, QUEUED} from './constants/test-statuses';
import {SUCCESS, FAIL, ERROR, SKIPPED, UPDATED, IDLE, RUNNING, QUEUED, TestStatus} from './constants';

import {UNCHECKED, INDETERMINATE, CHECKED} from './constants/checked-statuses';
export const getShortMD5 = (str: string): string => {
return crypto.createHash('md5').update(str, 'ascii').digest('hex').substr(0, 7);
};

const statusPriority: string[] = [
const statusPriority: TestStatus[] = [
// non-final
RUNNING, QUEUED,

Expand All @@ -19,15 +19,15 @@ const statusPriority: string[] = [

export const logger = pick(console, ['log', 'warn', 'error']);

export const isSuccessStatus = (status: string): boolean => status === SUCCESS;
export const isFailStatus = (status: string): boolean => status === FAIL;
export const isIdleStatus = (status: string): boolean => status === IDLE;
export const isRunningStatus = (status: string): boolean => status === RUNNING;
export const isErroredStatus = (status: string): boolean => status === ERROR;
export const isSkippedStatus = (status: string): boolean => status === SKIPPED;
export const isUpdatedStatus = (status: string): boolean => status === UPDATED;
export const isSuccessStatus = (status: TestStatus): boolean => status === SUCCESS;
export const isFailStatus = (status: TestStatus): boolean => status === FAIL;
export const isIdleStatus = (status: TestStatus): boolean => status === IDLE;
export const isRunningStatus = (status: TestStatus): boolean => status === RUNNING;
export const isErroredStatus = (status: TestStatus): boolean => status === ERROR;
export const isSkippedStatus = (status: TestStatus): boolean => status === SKIPPED;
export const isUpdatedStatus = (status: TestStatus): boolean => status === UPDATED;

export const determineStatus = (statuses: string[]): string | null => {
export const determineStatus = (statuses: TestStatus[]): TestStatus | null => {
if (!statuses.length) {
return SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
import {isUndefined, isArray, isEmpty, isFunction, isPlainObject, isString} from 'lodash';
import CustomGuiControlTypes from '../gui/constants/custom-gui-control-types';

const {isUndefined, isArray, isEmpty, isFunction, isPlainObject, isString} = require('lodash');
const SUPPORTED_CONTROL_TYPES: string[] = Object.values(CustomGuiControlTypes);

const SUPPORTED_CONTROL_TYPES = Object.values(require('../gui/constants/custom-gui-control-types'));

const assertSectionGroupType = (context, type) => {
const assertSectionGroupType = (context: string, type: unknown): void => {
if (isUndefined(type)) {
throw new Error(`${context} must contain field "type"`);
}
Expand All @@ -16,7 +15,7 @@ const assertSectionGroupType = (context, type) => {
}
};

const assertSectionGroupControls = (context, controls) => {
const assertSectionGroupControls = (context: string, controls: unknown): void => {
if (isUndefined(controls)) {
throw new Error(`${context} must contain field "controls"`);
}
Expand All @@ -26,14 +25,14 @@ const assertSectionGroupControls = (context, controls) => {
if (isEmpty(controls)) {
throw new Error(`${context} must contain non-empty array in the field "controls"`);
}
controls.forEach((control) => {
controls.forEach((control: unknown) => {
if (!isPlainObject(control)) {
throw new Error(`${context} must contain objects in the array "controls"`);
}
});
};

const assertSectionGroupAction = (context, action) => {
const assertSectionGroupAction = (context: string, action: unknown): void => {
if (isUndefined(action)) {
throw new Error(`${context} must contain field "action"`);
}
Expand All @@ -42,34 +41,35 @@ const assertSectionGroupAction = (context, action) => {
}
};

const assertSectionGroup = (sectionName, group, groupIndex) => {
const assertSectionGroup = (sectionName: string, group: unknown, groupIndex: number): void => {
const context = `customGui["${sectionName}"][${groupIndex}]`;

if (!isPlainObject(group)) {
throw new Error(`${context} must be plain object, but got ${typeof group}`);
}

assertSectionGroupType(context, group.type);
assertSectionGroupControls(context, group.controls);
assertSectionGroupAction(context, group.action);
const groupObj = group as Record<string, unknown>;

assertSectionGroupType(context, groupObj.type);
assertSectionGroupControls(context, groupObj.controls);
assertSectionGroupAction(context, groupObj.action);
};

const assertSection = (section, sectionName) => {
const assertSection = (section: unknown, sectionName: string): void => {
if (!isArray(section)) {
throw new Error(`customGui["${sectionName}"] must be an array, but got ${typeof section}`);
}
section.forEach((group, groupIndex) => assertSectionGroup(sectionName, group, groupIndex));
section.forEach((group: unknown, groupIndex: number) => assertSectionGroup(sectionName, group, groupIndex));
};

const assertCustomGui = (customGui) => {
export const assertCustomGui = (customGui: unknown): void => {
if (!isPlainObject(customGui)) {
throw new Error(`"customGui" option must be plain object, but got ${typeof customGui}`);
}
for (const sectionName in customGui) {
assertSection(customGui[sectionName], sectionName);
}
};

module.exports = {
assertCustomGui
const customGuiObj = customGui as Record<string, unknown>;

for (const sectionName in customGuiObj) {
assertSection(customGuiObj[sectionName], sectionName);
}
};
Loading
Loading