Skip to content

Commit

Permalink
fix: error with output of duration in HTML report
Browse files Browse the repository at this point in the history
chore: turn on rule `@typescript-eslint/naming-convention`
  • Loading branch information
uid11 committed Oct 11, 2023
1 parent 17cdcbd commit 20377ff
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 35 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ rules:
'@typescript-eslint/default-param-last': error
'@typescript-eslint/explicit-function-return-type': [error, {allowExpressions: true}]
'@typescript-eslint/explicit-member-accessibility': [error, {accessibility: no-public}]
'@typescript-eslint/naming-convention':
- error
- {selector: default, format: [strictCamelCase, StrictPascalCase], leadingUnderscore: allow}
- {
selector: variable,
format: [strictCamelCase, StrictPascalCase, UPPER_CASE],
leadingUnderscore: allow,
}
- {selector: typeLike, format: [StrictPascalCase]}
- {selector: [objectLiteralProperty, typeProperty], format: null, modifiers: [requiresQuotes]}
- {selector: [classProperty, typeMethod], filter: '^toJSON$', format: null}
'@typescript-eslint/no-invalid-void-type':
[error, {allowInGenericTypeArguments: true, allowAsThisParameter: true}]
'@typescript-eslint/no-namespace': [error, {allowDeclarations: true}]
Expand Down
8 changes: 4 additions & 4 deletions src/ApiRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import {Route} from './Route';
import type {
Method,
Request,
REQUEST_KEY_TYPE,
RequestKeyType,
Response,
RESPONSE_KEY_TYPE,
ResponseKeyType,
Url,
} from './types/internal';

/**
* Inner key for request type.
*/
declare const REQUEST_KEY: REQUEST_KEY_TYPE;
declare const REQUEST_KEY: RequestKeyType;

/**
* Inner key for response type.
*/
declare const RESPONSE_KEY: RESPONSE_KEY_TYPE;
declare const RESPONSE_KEY: ResponseKeyType;

/**
* Abstract route for API requests.
Expand Down
4 changes: 2 additions & 2 deletions src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {assertValueIsTrue} from './utils/asserts';
import {getFullPackConfig} from './utils/getFullPackConfig';

import type {PageRoute} from './PageRoute';
import type {AsyncVoid, PageClassTypeArgs, PARAMS_KEY_TYPE} from './types/internal';
import type {AsyncVoid, PageClassTypeArgs, ParamsKeyType} from './types/internal';

/**
* Inner key for parameters type.
*/
declare const PARAMS_KEY: PARAMS_KEY_TYPE;
declare const PARAMS_KEY: ParamsKeyType;

/**
* Abstract page with base methods.
Expand Down
4 changes: 2 additions & 2 deletions src/Route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {SLASHES_AT_THE_END_REGEXP, SLASHES_AT_THE_START_REGEXP} from './constants/internal';

import type {PARAMS_KEY_TYPE, Url, ZeroOrOneArg} from './types/internal';
import type {ParamsKeyType, Url, ZeroOrOneArg} from './types/internal';

declare const PARAMS_KEY: PARAMS_KEY_TYPE;
declare const PARAMS_KEY: ParamsKeyType;

/**
* Abstract route with base methods.
Expand Down
2 changes: 1 addition & 1 deletion src/constants/pixelmatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const DEFAULT_PIXELMATCH_OPTIONS: PixelmatchOptions = {
*/
diffColorAlt: undefined,
diffMask: false, // draw the diff over a transparent background (a mask)
includeAA: false, // whether to skip anti-aliasing detection
includeAa: false, // whether to skip anti-aliasing detection
threshold: 0.1, // matching threshold (0 to 1); smaller is more sensitive
};
4 changes: 2 additions & 2 deletions src/types/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {RunLabel} from './runLabel';
* @internal
*/
export type E2edEnvironment = {
E2ED_DEBUG?: string;
PWD?: string;
['E2ED_DEBUG']?: string;
['PWD']?: string;
[PATH_TO_PACK_VARIABLE_NAME]?: string;
[RUN_ENVIRONMENT_VARIABLE_NAME]?: RunEnvironment;
[RUN_LABEL_VARIABLE_NAME]?: RunLabel;
Expand Down
2 changes: 1 addition & 1 deletion src/types/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type {Cookie, CookieHeaderString, SameSite, SetCookieHeaderString} from './cookie';
export type {Headers, MapHeaders, MapOptions, Method, Query, Request, Response, Url} from './http';
export type {REQUEST_KEY_TYPE, RESPONSE_KEY_TYPE} from './internalKeys';
export type {RequestKeyType, ResponseKeyType} from './internalKeys';
export type {StatusCode} from './statusCode';
4 changes: 2 additions & 2 deletions src/types/http/internalKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ declare const RESPONSE_KEY: unique symbol;
/**
* Type of inner key for request type.
*/
export type REQUEST_KEY_TYPE = typeof REQUEST_KEY;
export type RequestKeyType = typeof REQUEST_KEY;

/**
* Type of inner key for response type.
*/
export type RESPONSE_KEY_TYPE = typeof RESPONSE_KEY;
export type ResponseKeyType = typeof RESPONSE_KEY;
6 changes: 3 additions & 3 deletions src/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export type {
Method,
Query,
Request,
REQUEST_KEY_TYPE,
RequestKeyType,
Response,
RESPONSE_KEY_TYPE,
ResponseKeyType,
SameSite,
SetCookieHeaderString,
StatusCode,
Expand Down Expand Up @@ -140,7 +140,7 @@ export type {
Normalize,
ObjectEntries,
OptionalIfValueIncludeDefault,
PARAMS_KEY_TYPE,
ParamsKeyType,
UnionToIntersection,
UnwrapSet,
Values,
Expand Down
10 changes: 5 additions & 5 deletions src/types/pixelmatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* RGB color presentation (as three numbers).
* @internal
*/
type RGBTuple = readonly [number, number, number];
type RgbTuple = readonly [number, number, number];

/**
* Image data as buffer or typed array.
Expand All @@ -15,11 +15,11 @@ export type ImgData = Buffer | Uint8Array | Uint8ClampedArray;
* @internal
*/
export type PixelmatchOptions = Readonly<{
aaColor: RGBTuple;
aaColor: RgbTuple;
alpha: number;
diffColor: RGBTuple;
diffColorAlt: RGBTuple | undefined;
diffColor: RgbTuple;
diffColorAlt: RgbTuple | undefined;
diffMask: boolean;
includeAA: boolean;
includeAa: boolean;
threshold: number;
}>;
1 change: 1 addition & 0 deletions src/types/stackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type StackFrame<F extends Fn = Fn, This = unknown> = Readonly<{
getColumnNumber(): number;
getFunction(): F;
getEvalOrigin(): string;
// eslint-disable-next-line @typescript-eslint/naming-convention
getScriptNameOrSourceURL(): string;
isNative(): boolean;
isToplevel(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/types/startInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type PackageInfo = Readonly<{packagePath: AbsolutePathToDirectory; versio
* Not internal because it is used in report data.
*/
export type StartInfo<FullPackConfigArg = FullPackConfig> = Readonly<{
PWD: string | undefined;
absolutePathToProjectRootDirectory: AbsolutePathToDirectory;
'cwd()': string;
e2ed: PackageInfo;
Expand All @@ -25,6 +24,7 @@ export type StartInfo<FullPackConfigArg = FullPackConfig> = Readonly<{
nodeVersion: string;
pathToPack: FilePathFromRoot;
'process.argv': readonly string[];
pwd: string | undefined;
runEnvironment: RunEnvironment;
startTimeInMs: UtcTimeInMs;
testCafeHammerheadUp: PackageInfo;
Expand Down
4 changes: 2 additions & 2 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type Any = any;
* Returns the type of instance params.
*/
export type GetParamsType<Class> = Class extends {[PARAMS_KEY]: unknown}
? Normalize<Class[PARAMS_KEY_TYPE]>
? Normalize<Class[ParamsKeyType]>
: never;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ export type OptionalIfValueIncludeDefault<
/**
* Type of inner key for params type.
*/
export type PARAMS_KEY_TYPE = typeof PARAMS_KEY;
export type ParamsKeyType = typeof PARAMS_KEY;

/**
* Takes a union, and returns the intersection of the elements of the union.
Expand Down
1 change: 1 addition & 0 deletions src/utils/pixelmatch/isPixelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import type {ImgData} from '../../types/internal';
*/
export const isPixelData = (img: ImgData): boolean =>
ArrayBuffer.isView(img) &&
// eslint-disable-next-line @typescript-eslint/naming-convention
(img.constructor as {BYTES_PER_ELEMENT?: number}).BYTES_PER_ELEMENT === 1;
2 changes: 1 addition & 1 deletion src/utils/pixelmatch/pixelmatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const pixelmatch = (

if (Math.abs(delta) > maxDelta) {
if (
!options.includeAA &&
!options.includeAa &&
(isAntialiased(img1, x, y, width, height, img2) ||
isAntialiased(img2, x, y, width, height, img1))
) {
Expand Down
16 changes: 9 additions & 7 deletions src/utils/promise/waitForAllProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import type {UnwrapPromise} from '../../types/internal';

type PromiseObject = Record<string, Promise<unknown>>;

type Return<PO extends PromiseObject> = Promise<{[Key in keyof PO]: UnwrapPromise<PO[Key]>}>;
type Return<Value extends PromiseObject> = Promise<{
[Key in keyof Value]: UnwrapPromise<Value[Key]>;
}>;

/**
* Wait for all object properties are resolved,
* and return an object with those properties and their values.
* Waits for all object properties are resolved,
* and returns an object with those properties and their values.
*/
export const waitForAllProperties = async <PO extends PromiseObject>(
promiseObject: PO,
): Return<PO> =>
export const waitForAllProperties = async <Value extends PromiseObject>(
promiseObject: Value,
): Return<Value> =>
Object.fromEntries(
await Promise.all(
Object.entries(promiseObject).map(([key, maybePromise]) =>
Promise.resolve(maybePromise).then((result) => [key, result]),
),
),
) as Return<PO>;
) as Return<Value>;
2 changes: 1 addition & 1 deletion src/utils/report/client/render/renderDuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export function renderDuration(durationInMs: number): SafeHtml {
parts.unshift(`${durationInHours}h`);
}

return createSafeHtmlWithoutSanitize`${parts.slice(-2).join(' ')}`;
return createSafeHtmlWithoutSanitize`${parts.slice(0, 2).join(' ')}`;
}
2 changes: 1 addition & 1 deletion src/utils/startInfo/getStartInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const getStartInfo = (): StartInfo => {
);

return {
PWD: e2edEnvironment.PWD,
absolutePathToProjectRootDirectory: ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY,
'cwd()': process.cwd(),
e2ed,
Expand All @@ -48,6 +47,7 @@ export const getStartInfo = (): StartInfo => {
nodeVersion: process.version,
pathToPack: getPathToPack(),
'process.argv': [...process.argv],
pwd: e2edEnvironment.PWD,
runEnvironment,
startTimeInMs,
testCafeHammerheadUp,
Expand Down

0 comments on commit 20377ff

Please sign in to comment.