Skip to content

Commit

Permalink
Merge pull request #480 from gemini-testing/users/shadowusr/HERMIONE-…
Browse files Browse the repository at this point in the history
…1052.basic-typescript-infra

Add typescript infrastructure
  • Loading branch information
shadowusr authored Jul 10, 2023
2 parents 1f631fb + c98c45b commit 420d4f9
Show file tree
Hide file tree
Showing 160 changed files with 27,579 additions and 20,282 deletions.
37 changes: 8 additions & 29 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
{
"plugins": [
["transform-runtime", {"polyfill": false}],
["babel-plugin-transform-builtin-extend", {"globals": ["Error", "Array"]}]
["@babel/plugin-transform-runtime"]
],
"env": {
"test": {
"presets": [
[
"env",
{"exclude": ["transform-es2015-classes"]}
],
"react",
"stage-0"
],
"plugins": ["dynamic-import-node"]
},
"production": {
"presets": [
"env",
"react",
"stage-0"
]
},
"development": {
"presets": [
"env",
"react",
"stage-0"
]
}
}
"presets": [
"@babel/preset-react",
["@babel/preset-env", { "modules": "commonjs"}],
"@babel/preset-typescript"
],
"sourceMaps": true,
"retainLines": true
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/.*
build
node_modules
hot
/lib/static/*.min.js
Expand Down
30 changes: 28 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
module.exports = {
extends: 'gemini-testing',
root: true
extends: ['gemini-testing', 'plugin:@typescript-eslint/recommended', 'plugin:react/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'react'],
root: true,
rules: {
'@typescript-eslint/no-empty-function': 'off'
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'error'
}
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off'
}
},
{
files: ['test/**'],
rules: {
// For convenient casting of test objects
'@typescript-eslint/no-explicit-any': 'off'
}
}
]
};
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
build
hot
sqlite.db
*.log
Expand Down
6 changes: 6 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

module.exports = {
recursive: true,
require: ["./test/ts-node", "./test/setup", "./test/assert-ext", "jsdom-global/register"],
};
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.*
test
hot
/lib/static/js/
/lib/static/report.css
lib/static/js/
lib/static/report.css

hermione-report
.hermione.conf.js
2 changes: 1 addition & 1 deletion lib/cli-commands/gui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

Expand Down
4 changes: 2 additions & 2 deletions lib/cli-commands/remove-unused-screens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ async function handleScreens(allScreenPaths, screensToRemove, {spinner, cliOpts}
logger.warn(
chalk.red(
`Screen by path: "${screenPath}" is not found in your file system. ` +
'Try to rebase your branch or download more recent report from CI.',
),
'Try to rebase your branch or download more recent report from CI.'
)
);
return false;
}
Expand Down
123 changes: 0 additions & 123 deletions lib/common-utils.js

This file was deleted.

114 changes: 114 additions & 0 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
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 {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[] = [
// non-final
RUNNING, QUEUED,

// final
ERROR, FAIL, UPDATED, SUCCESS, IDLE, SKIPPED
];

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 determineStatus = (statuses: string[]): string | null => {
if (!statuses.length) {
return SUCCESS;
}

const set = new Set(statuses);
for (const status of statusPriority) {
if (set.has(status)) {
return status;
}
}

console.error('Unknown statuses: ' + JSON.stringify(statuses));

return null;
};

export const isUrl = (str: string): boolean => {
if (typeof str !== 'string') {
return false;
}

const parsedUrl = url.parse(str);

return !!parsedUrl.host && !!parsedUrl.protocol;
};

export const buildUrl = (href: string, {host}: {host?: string} = {}): string => {
return host
? url.format(Object.assign(url.parse(href), {host}))
: href;
};

export const fetchFile = async <T = unknown>(url: string, options?: AxiosRequestConfig) : Promise<{data: T | null, status: number}> => {
try {
const {data, status} = await axios.get(url, options);

return {data, status};
} catch (e: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
logger.warn(`Error while fetching ${url}`, e);

// 'unknown' for request blocked by CORS policy
const status = e.response ? e.response.status : 'unknown';

return {data: null, status};
}
};

const isRelativeUrl = (url: string): boolean => {
try {
// eslint-disable-next-line no-new
new URL(url);

return false;
} catch (e) {
return true;
}
};

export const normalizeUrls = (urls: string[] = [], baseUrl: string): string[] => {
const baseUrlsSearch = new URL(baseUrl).search;

return urls.map(url => {
try {
const newUrl = new URL(url, baseUrl);

// URL's parameters can specify directory at file server
if (isRelativeUrl(url) && !newUrl.search) {
newUrl.search = baseUrlsSearch;
}

return newUrl.href;
} catch (e) {
logger.warn(`Can not normalize url '${url} for base url '${baseUrl}'`, e);

return url;
}
});
};

// TODO: use enum types instead of numbers below
export const isCheckboxChecked = (status: number): boolean => Number(status) === CHECKED;
export const isCheckboxIndeterminate = (status: number): boolean => Number(status) === INDETERMINATE;
export const isCheckboxUnchecked = (status: number): boolean => Number(status) === UNCHECKED;
export const getToggledCheckboxState = (status: number): number => isCheckboxChecked(status) ? UNCHECKED : CHECKED;
4 changes: 2 additions & 2 deletions lib/db-utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ exports.handleDatabases = async (dbJsonUrls, opts = {}) => {

return opts.formatData ? opts.formatData(dbJsonUrl) : [];
}
}),
),
})
)
);
};

Expand Down
Loading

0 comments on commit 420d4f9

Please sign in to comment.