@flemist/simple-utils 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/build/common/test/index.d.ts +1 -0
  2. package/build/common/test/match/Matcher.d.ts +14 -0
  3. package/build/common/test/match/check.d.ts +9 -0
  4. package/build/common/test/match/helpers.d.ts +4 -0
  5. package/build/common/test/match/index.d.ts +3 -0
  6. package/build/common/test/match/match.d.ts +6 -0
  7. package/build/common/test/match/matchers/MatchInstanceOf.d.ts +11 -0
  8. package/build/common/test/match/matchers/MatcherAny.d.ts +6 -0
  9. package/build/common/test/match/matchers/MatcherArray.d.ts +12 -0
  10. package/build/common/test/match/matchers/MatcherArrayItem.d.ts +10 -0
  11. package/build/common/test/match/matchers/MatcherConvert.d.ts +10 -0
  12. package/build/common/test/match/matchers/MatcherCustom.d.ts +9 -0
  13. package/build/common/test/match/matchers/MatcherFew.d.ts +13 -0
  14. package/build/common/test/match/matchers/MatcherIn.d.ts +12 -0
  15. package/build/common/test/match/matchers/MatcherIs.d.ts +10 -0
  16. package/build/common/test/match/matchers/MatcherNever.d.ts +6 -0
  17. package/build/common/test/match/matchers/MatcherNot.d.ts +9 -0
  18. package/build/common/test/match/matchers/MatcherNumber.d.ts +15 -0
  19. package/build/common/test/match/matchers/MatcherObject.d.ts +14 -0
  20. package/build/common/test/match/matchers/MatcherObjectEntry.d.ts +11 -0
  21. package/build/common/test/match/matchers/MatcherRef.d.ts +10 -0
  22. package/build/common/test/match/matchers/MatcherString.d.ts +10 -0
  23. package/build/common/test/match/matchers/constants.d.ts +1 -0
  24. package/build/common/test/match/matchers/index.d.ts +1 -0
  25. package/build/common/test/match/matchers/matchers.d.ts +92 -0
  26. package/build/common/test/match/report.d.ts +5 -0
  27. package/build/common/test/match/types.d.ts +24 -0
  28. package/build/node/test/e2e/check/checkPageHttpErrors.d.ts +25 -0
  29. package/build/node/test/e2e/check/index.d.ts +3 -0
  30. package/build/node/test/e2e/check/subscribeJsErrors.d.ts +10 -0
  31. package/build/node/test/e2e/check/types.d.ts +1 -0
  32. package/build/node/test/e2e/index.d.ts +3 -0
  33. package/build/node/test/e2e/setPlaywrightPriorityLow.d.ts +1 -0
  34. package/build/node/test/e2e/test/delayOnError.d.ts +3 -0
  35. package/build/node/test/e2e/test/index.d.ts +6 -0
  36. package/build/node/test/e2e/test/initPage.d.ts +25 -0
  37. package/build/node/test/e2e/test/testPage.d.ts +17 -0
  38. package/build/node/test/e2e/test/types.d.ts +7 -0
  39. package/build/node/test/e2e/test/useBrowser.d.ts +5 -0
  40. package/build/node/test/e2e/test/useBrowserContext.d.ts +5 -0
  41. package/build/node/test/index.d.ts +2 -0
  42. package/build/node/test/refactor/createPagesElementsChangesTest.d.ts +11 -0
  43. package/build/node/test/refactor/forcePseudoClasses.d.ts +5 -0
  44. package/build/node/test/refactor/getAllElements.d.ts +2 -0
  45. package/build/node/test/refactor/getElementsStyleDiff.d.ts +2 -0
  46. package/build/node/test/refactor/getObjectsDiff.d.ts +6 -0
  47. package/build/node/test/refactor/index.d.ts +7 -0
  48. package/build/node/test/refactor/loadSaveJson.d.ts +2 -0
  49. package/build/node/test/refactor/types.d.ts +72 -0
  50. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ export * from './match';
@@ -0,0 +1,14 @@
1
+ import { MatchResult3 } from './types';
2
+ export type MatcherArgsName<T> = string | ((actual?: T) => string) | null;
3
+ export type MatcherArgs<T> = {
4
+ name?: MatcherArgsName<T>;
5
+ };
6
+ export declare abstract class Matcher<Actual, Args extends MatcherArgs<any> | null | undefined = any> {
7
+ protected _args: Args;
8
+ constructor(args?: Args);
9
+ set(args: Partial<Args>): this;
10
+ name(name?: MatcherArgsName<Actual>): this;
11
+ abstract match(actual: Actual): MatchResult3;
12
+ protected abstract nameDefault(actual?: Actual): string;
13
+ toString(actual?: Actual): string;
14
+ }
@@ -0,0 +1,9 @@
1
+ import { Expected } from './types';
2
+ import { PromiseOrValue } from '@flemist/async-utils';
3
+ export declare class CheckError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ export declare function check<T>(actual: T): (expected: Expected<T>, onError?: (error: Error) => void) => void;
7
+ export declare function checkFunc<T>(func: () => Promise<T>): (expectedValue: Expected<T>, expectedError?: Expected<any>) => Promise<T>;
8
+ export declare function checkFunc<T>(func: () => T): (expectedValue: Expected<T>, expectedError?: Expected<any>) => T;
9
+ export declare function checkFunc<T>(func: () => PromiseOrValue<T>): (expectedValue: Expected<T>, expectedError?: Expected<any>) => PromiseOrValue<T>;
@@ -0,0 +1,4 @@
1
+ import { Matcher, MatcherArgs } from './Matcher';
2
+ export declare function isMatcher(value: any): value is Matcher<any>;
3
+ export declare function expectedToString(expected: any): string;
4
+ export declare function argsToString(args: MatcherArgs<any> | null | undefined, ...excludeKeys: string[]): string;
@@ -0,0 +1,3 @@
1
+ export * from './matchers';
2
+ export { match } from './match';
3
+ export { check } from './check';
@@ -0,0 +1,6 @@
1
+ import { Expected, MatchResult, MatchResult3 } from './types';
2
+ export declare function validateMatchResult<T>(_result: MatchResult<T>): MatchResult<T>;
3
+ export declare function createMatchResultError<T>(actual: T, expected: Expected<T>, error: Error): MatchResult<T>;
4
+ export declare function createMatchResultBoolean<T>(actual: T, expected: Expected<T>, result: boolean): MatchResult<T>;
5
+ export declare function createMatchResult<T>(actual: T, expected: Expected<T>, result: MatchResult3): MatchResult<T>;
6
+ export declare function match<T>(actual: T, expected: Expected<T>): MatchResult<T>;
@@ -0,0 +1,11 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchInstanceOfArgs<T> = MatcherArgs<T> & {
4
+ expected: {
5
+ new (...args: any[]): T;
6
+ };
7
+ };
8
+ export declare class MatcherInstanceOf<T> extends Matcher<T, MatchInstanceOfArgs<T>> {
9
+ match(actual: T): MatchResult3;
10
+ nameDefault(): string;
11
+ }
@@ -0,0 +1,6 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher } from '../Matcher';
3
+ export declare class MatcherAny extends Matcher<any> {
4
+ match(): MatchResult3;
5
+ nameDefault(): string;
6
+ }
@@ -0,0 +1,12 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchArray<T extends any[]> = Array<Expected<T[number]>>;
4
+ export type MatcherArrayArgs<T extends any[]> = MatcherArgs<T> & {
5
+ expected?: MatchArray<T> | null;
6
+ matchType?: 'equals' | 'includes';
7
+ maxReportItems?: number;
8
+ };
9
+ export declare class MatcherArray<T extends any[]> extends Matcher<T, MatcherArrayArgs<T> | null | undefined> {
10
+ match(actual: T): MatchResult3;
11
+ nameDefault(): string;
12
+ }
@@ -0,0 +1,10 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchArrayItemArgs<T> = MatcherArgs<T[]> & {
4
+ expected: Expected<T>;
5
+ maxReportItems?: number;
6
+ };
7
+ export declare class MatcherArrayItem<T> extends Matcher<T[], MatchArrayItemArgs<T>> {
8
+ match(actual: T[]): MatchResult3;
9
+ nameDefault(): string;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchConvertArgs<T, U> = MatcherArgs<T> & {
4
+ convert: (actual: T) => U;
5
+ expected: Expected<U>;
6
+ };
7
+ export declare class MatcherConvert<T, U> extends Matcher<T, MatchConvertArgs<T, U>> {
8
+ match(actual: T): MatchResult3;
9
+ nameDefault(): string;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchCustomArgs<T> = MatcherArgs<T> & {
4
+ matcher: Matcher<T> | ((actual: T) => MatchResult3);
5
+ };
6
+ export declare class MatcherCustom<T> extends Matcher<T, MatchCustomArgs<T>> {
7
+ match(actual: T): MatchResult3;
8
+ nameDefault(actual?: T): string;
9
+ }
@@ -0,0 +1,13 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchFewArgs<T> = MatcherArgs<T> & {
4
+ type: 'or' | 'and';
5
+ expecteds: Array<Expected<T>>;
6
+ /** If true, then it will not check remains unnecessary expecteds.
7
+ * So there will be less information in logs especially if you use 'Not' operator */
8
+ pipe?: boolean | null;
9
+ };
10
+ export declare class MatcherFew<T> extends Matcher<T, MatchFewArgs<T>> {
11
+ match(actual: T): MatchResult3;
12
+ nameDefault(): string;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchInArgs<T> = MatcherArgs<T> & {
4
+ expected: Set<T>;
5
+ };
6
+ export declare class MatcherIn<T> extends Matcher<T, MatchInArgs<T>> {
7
+ constructor(args: Omit<MatchInArgs<T>, 'expected'> & {
8
+ expected: Set<T> | Iterable<T>;
9
+ });
10
+ match(actual: T): MatchResult3;
11
+ nameDefault(): string;
12
+ }
@@ -0,0 +1,10 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchIsArgs<T> = MatcherArgs<T> & {
4
+ expected: T;
5
+ nonStrict?: boolean | null;
6
+ };
7
+ export declare class MatcherIs<T> extends Matcher<T, MatchIsArgs<T>> {
8
+ match(actual: T): MatchResult3;
9
+ nameDefault(): string;
10
+ }
@@ -0,0 +1,6 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher } from '../Matcher';
3
+ export declare class MatcherNever extends Matcher<any> {
4
+ match(): MatchResult3;
5
+ nameDefault(): string;
6
+ }
@@ -0,0 +1,9 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchNotArgs<T> = MatcherArgs<T> & {
4
+ expected: Expected<T>;
5
+ };
6
+ export declare class MatcherNot<T> extends Matcher<T, MatchNotArgs<T>> {
7
+ match(actual: T): MatchResult3;
8
+ nameDefault(): string;
9
+ }
@@ -0,0 +1,15 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchNumberArgsRange = MatcherArgs<number> & {
4
+ min?: number | null;
5
+ max?: number | null;
6
+ allowInfinity?: boolean | null;
7
+ allowNaN?: boolean | null;
8
+ };
9
+ export type MatchNumberArgs = MatchNumberArgsRange & {
10
+ float?: boolean | null;
11
+ };
12
+ export declare class MatcherNumber extends Matcher<number, MatchNumberArgs | undefined | null> {
13
+ match(actual: number): MatchResult3;
14
+ nameDefault(): string;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchObject<T> = {
4
+ [K in keyof T]: Expected<T[K]>;
5
+ };
6
+ export type MatcherObjectArgs<T> = MatcherArgs<T> & {
7
+ expected?: MatchObject<T> | null;
8
+ ignoreExtraKeys?: boolean;
9
+ maxReportItems?: number;
10
+ };
11
+ export declare class MatcherObject<T> extends Matcher<T, MatcherObjectArgs<T> | undefined | null> {
12
+ match(actual: T): MatchResult3;
13
+ nameDefault(): string;
14
+ }
@@ -0,0 +1,11 @@
1
+ import { Expected, MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchObjectEntry<T> = Expected<[keyof T, T[keyof T]]>;
4
+ export type MatcherObjectEntryArgs<T> = MatcherArgs<T> & {
5
+ expected?: MatchObjectEntry<T> | null;
6
+ maxReportItems?: number;
7
+ };
8
+ export declare class MatcherObjectEntry<T> extends Matcher<T, MatcherObjectEntryArgs<T> | undefined | null> {
9
+ match(actual: T): MatchResult3;
10
+ nameDefault(): string;
11
+ }
@@ -0,0 +1,10 @@
1
+ import { Matcher } from '../Matcher';
2
+ import { Expected, MatchResult3 } from '../types';
3
+ export declare class MatcherRef<T> extends Matcher<T> {
4
+ private _hasExpected;
5
+ private _expected;
6
+ get expected(): Expected<T>;
7
+ set expected(value: Expected<T>);
8
+ match(actual: T): MatchResult3;
9
+ nameDefault(): string;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { MatchResult3 } from '../types';
2
+ import { Matcher, MatcherArgs } from '../Matcher';
3
+ export type MatchStringPattern = RegExp | ((actual: string) => MatchResult3);
4
+ export type MatchStringArgs = MatcherArgs<string> & {
5
+ pattern?: MatchStringPattern | null;
6
+ };
7
+ export declare class MatcherString extends Matcher<string, MatchStringArgs | undefined | null> {
8
+ match(actual: string): MatchResult3;
9
+ nameDefault(): string;
10
+ }
@@ -0,0 +1 @@
1
+ export declare const MAX_REPORT_ITEMS_DEFAULT = 10;
@@ -0,0 +1 @@
1
+ export * from './matchers';
@@ -0,0 +1,92 @@
1
+ import { MatchArray, MatcherArray } from './MatcherArray';
2
+ import { MatcherAny } from './MatcherAny';
3
+ import { Expected, MatchResult3 } from '../types';
4
+ import { MatcherConvert } from './MatcherConvert';
5
+ import { MatcherIs } from './MatcherIs';
6
+ import { MatcherNumber, MatchNumberArgs, MatchNumberArgsRange } from './MatcherNumber';
7
+ import { MatcherObject, MatchObject } from './MatcherObject';
8
+ import { MatcherString, MatchStringPattern } from './MatcherString';
9
+ import { MatcherInstanceOf } from './MatchInstanceOf';
10
+ import { MatcherIn } from './MatcherIn';
11
+ import { MatcherFew } from './MatcherFew';
12
+ import { MatcherCustom } from './MatcherCustom';
13
+ import { MatcherNot } from './MatcherNot';
14
+ import { Matcher, MatcherArgsName } from '../Matcher';
15
+ import { MatcherNever } from './MatcherNever';
16
+ import { ValueState } from '@flemist/async-utils';
17
+ import { MatcherObjectEntry } from './MatcherObjectEntry';
18
+ import { MatcherRef } from './MatcherRef';
19
+ export declare function matchArray<T extends any[]>(expected?: MatchArray<T> | null): MatcherArray<T>;
20
+ export declare function matchArrayIncludes<T extends any[]>(expected: MatchArray<T>): MatcherArray<T>;
21
+ export declare function matchAny(): MatcherAny;
22
+ export declare function matchRef<T>(): MatcherRef<T>;
23
+ export declare function matchNever(name?: MatcherArgsName<any> | null): MatcherNever;
24
+ /** Check array length and then check each item with expected */
25
+ export declare function matchArrayItem<T>(expectedLength: Expected<number> | MatchIntArgs | null | undefined, expected: Expected<T>): Matcher<T[]>;
26
+ export declare function matchConvert<T, U>(name: MatcherArgsName<T>, convert: (actual: T) => U, expected: Expected<U>): MatcherConvert<T, U>;
27
+ export declare function matchIsNonStrict<T>(expected: T): MatcherIs<T>;
28
+ export declare function matchIs<T>(expected: T): MatcherIs<T>;
29
+ export declare function matchNumber(args?: MatchNumberArgs | null): MatcherNumber;
30
+ export type MatchIntArgs = MatchNumberArgsRange;
31
+ export declare function matchInt(args?: MatchIntArgs | null): MatcherNumber;
32
+ export type MatchFloatArgs = MatchNumberArgsRange;
33
+ export declare function matchFloat(args?: MatchFloatArgs | null): MatcherNumber;
34
+ export declare function matchObject<T>(expected?: MatchObject<T> | null): MatcherObject<T>;
35
+ export declare function matchDeep<T>(expected?: Expected<T> | null, toExpected?: <T>(value: T, key: string | number | null) => Expected<T> | null, key?: string | number | null): any;
36
+ export declare function matchObjectPartial<T>(expected?: MatchObject<Partial<T>> | null): MatcherObject<T>;
37
+ export declare function matchString(pattern?: MatchStringPattern | null): MatcherString;
38
+ export declare function matchInstanceOf<T>(expected: {
39
+ new (...args: any[]): T;
40
+ }): MatcherInstanceOf<T>;
41
+ export declare function matchTypeOf(expected: Expected<string>): MatcherConvert<any, string>;
42
+ export declare function matchConstructor<T>(expected: {
43
+ new (...args: any[]): T;
44
+ }): MatcherConvert<T, Function>;
45
+ export declare function matchBoolean(): MatcherConvert<any, string>;
46
+ export declare function matchNullish(): MatcherIs<any>;
47
+ export declare function matchNotNullish(): MatcherNot<any>;
48
+ export declare function matchOr<T>(...expecteds: Array<Expected<T>>): MatcherFew<T>;
49
+ export declare function matchAnd<T>(...expecteds: Array<Expected<T>>): MatcherFew<T>;
50
+ export declare function matchOrPipe<T>(...expecteds: Array<Expected<T>>): MatcherFew<T>;
51
+ export declare function matchAndPipe<T>(...expecteds: Array<Expected<T>>): MatcherFew<T>;
52
+ export declare function matchOptional<T>(expected: Expected<T>, required?: null | boolean): Expected<T>;
53
+ export declare function matchArrayLength(args?: MatchIntArgs | Expected<number> | null | undefined): MatcherFew<any[]>;
54
+ export declare function matchStringLength(args?: MatchIntArgs | Expected<number> | null | undefined): MatcherFew<string>;
55
+ export declare function matchObjectWith<T>(matcher: Matcher<T>): MatcherFew<T>;
56
+ /** Check if it is an array and then check with matcher */
57
+ export declare function matchArrayWith<T extends any[]>(matcher: Matcher<T[]>): MatcherFew<T>;
58
+ export declare function matchObjectKeys<T extends object>(expected: Expected<Array<keyof T>>): MatcherFew<T>;
59
+ export declare function matchObjectValues<T extends object>(expected: Expected<Array<T[keyof T]>>): MatcherFew<T>;
60
+ export declare function matchObjectEntries<T extends object>(expected: Expected<Array<[keyof T, T[keyof T]]>>): MatcherFew<T>;
61
+ export declare function matchObjectEntry<T extends object>(expected: Expected<[keyof T, T[keyof T]]>): MatcherObjectEntry<T>;
62
+ export declare function matchObjectKey<T extends object>(expected: Expected<keyof T>): MatcherObjectEntry<T>;
63
+ export declare function matchObjectValue<T extends object>(expected: Expected<T[keyof T]>): MatcherObjectEntry<T>;
64
+ export declare function matchObjectKeyValue<T extends object>(expectedKey: Expected<keyof T>, expectedValue: Expected<T[keyof T]>): MatcherObjectEntry<T>;
65
+ export declare function matchObjectKeysNotNull<T extends object>(expected: Expected<Array<keyof T>>): MatcherFew<T>;
66
+ export declare function matchIn<T>(expected: Set<T> | Iterable<T>): MatcherIn<T>;
67
+ export declare function matchEnum<T>(enumObject: {
68
+ [key: string]: T;
69
+ }): MatcherIn<T>;
70
+ export declare function matchCustom<T>(name: MatcherArgsName<T>, matcher: Matcher<T> | ((actual: T) => MatchResult3)): MatcherCustom<T>;
71
+ export type MatchRangeValueOptions = {
72
+ min?: number | null;
73
+ max?: number | null;
74
+ optional?: boolean | null;
75
+ float?: boolean | null;
76
+ };
77
+ export type MatchRangeOptions = {
78
+ common?: null | MatchRangeValueOptions;
79
+ from?: null | MatchRangeValueOptions;
80
+ to?: null | MatchRangeValueOptions;
81
+ };
82
+ export declare function matchIntDate(options?: MatchIntArgs): Matcher<number>;
83
+ export declare function matchRange(options?: MatchRangeOptions | null): MatcherFew<any[]>;
84
+ export declare function matchRangeDate(args?: MatchRangeOptions | null): MatcherFew<any[]>;
85
+ export declare function matchNot<T>(expected: Expected<T>): MatcherNot<T>;
86
+ export declare function matchUuid(): Matcher<string>;
87
+ export declare function matchValueState<T>(args: MatchObject<Partial<ValueState<T>>>): MatcherObject<ValueState<T>>;
88
+ export declare function matchArrayBuffer<T extends {
89
+ readonly byteLength: number;
90
+ }>(expected?: {
91
+ readonly byteLength: number;
92
+ } | string | null): Matcher<T>;
@@ -0,0 +1,5 @@
1
+ import { MatchResult, MatchResultNested } from './types';
2
+ export declare function filterMatchResultNested(matchResultNested: MatchResultNested, inverseResult: boolean): MatchResultNested | null;
3
+ export declare function filterMatchResult(matchResult: MatchResult<any>, inverseResult: boolean): MatchResult<any> | null;
4
+ export declare function matchResultNestedToString(matchResultNested: MatchResultNested, indent: string): string;
5
+ export declare function matchResultToString(matchResult: MatchResult<any>, indent: string): any;
@@ -0,0 +1,24 @@
1
+ import { Matcher } from './Matcher';
2
+ export type Expected<T> = T | Matcher<T>;
3
+ export type MatchResultNested = {
4
+ actualKey?: null | string | number;
5
+ expectedKey?: null | string | number;
6
+ result: MatchResult<any>;
7
+ };
8
+ export type MatchResult<T> = {
9
+ actual: T;
10
+ expected: Expected<T>;
11
+ result: boolean;
12
+ cause?: null | string;
13
+ nested?: null | MatchResultNested[];
14
+ error?: null | Error;
15
+ };
16
+ export interface MatchResult2 {
17
+ result: boolean;
18
+ cause?: string | null;
19
+ nested?: MatchResultNested[] | null;
20
+ }
21
+ export type MatchResult3 = boolean | string | MatchResult2;
22
+ export declare class MatchInternalError extends Error {
23
+ constructor(message: string);
24
+ }
@@ -0,0 +1,25 @@
1
+ import { Page } from 'playwright';
2
+ export type RegExpRule = {
3
+ value: boolean;
4
+ pattern: RegExp;
5
+ };
6
+ export type UrlWithError = {
7
+ url: URL;
8
+ error: string;
9
+ };
10
+ export type GetPageHttpErrorsTimeouts = {
11
+ downloadInternal?: null | number;
12
+ downloadExternal?: null | number;
13
+ total?: null | number;
14
+ };
15
+ export type GetPageHttpErrorsArgs = {
16
+ page: Page;
17
+ urlFilters?: RegExpRule[] | null;
18
+ timeouts?: null | GetPageHttpErrorsTimeouts;
19
+ };
20
+ export declare function getPageHttpErrors({ page, urlFilters, timeouts, }: GetPageHttpErrorsArgs): Promise<UrlWithError[] | undefined | null>;
21
+ export declare function checkPageHttpErrors({ page, urlFilters, errorFilter, }: {
22
+ page: Page;
23
+ urlFilters?: RegExpRule[] | null;
24
+ errorFilter?: ((args: UrlWithError) => boolean) | null;
25
+ }): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './checkPageHttpErrors';
3
+ export * from './subscribeJsErrors';
@@ -0,0 +1,10 @@
1
+ import { Page } from 'playwright';
2
+ import { OnError } from './types';
3
+ export declare function subscribeJsErrors({ page, filter, onError, }: {
4
+ page: Page;
5
+ filter?: ((args: {
6
+ url: URL;
7
+ error: string;
8
+ }) => boolean) | null;
9
+ onError: OnError;
10
+ }): Promise<void>;
@@ -0,0 +1 @@
1
+ export type OnError = (error: Error) => void;
@@ -0,0 +1,3 @@
1
+ export * from './check';
2
+ export * from './setPlaywrightPriorityLow';
3
+ export * from './test';
@@ -0,0 +1 @@
1
+ export declare function setPlaywrightPriorityLow(): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export declare function delayOnErrorSet(time: number): void;
2
+ export declare function delayOnErrorCall(): Promise<void> | undefined;
3
+ export declare function delayOnErrorWait(): Promise<void> | null;
@@ -0,0 +1,6 @@
1
+ export * from './types';
2
+ export * from './delayOnError';
3
+ export * from './initPage';
4
+ export * from './testPage';
5
+ export * from './useBrowser';
6
+ export * from './useBrowserContext';
@@ -0,0 +1,25 @@
1
+ import { RegExpRule, UrlWithError } from '../check/checkPageHttpErrors';
2
+ import { Page } from 'playwright';
3
+ import { IAbortSignalFast } from '@flemist/abort-controller-fast';
4
+ export type Filters = {
5
+ js?: {
6
+ filter?: null | ((args: {
7
+ url: URL;
8
+ error: string;
9
+ }) => boolean);
10
+ } | null;
11
+ http?: {
12
+ urlFilters?: RegExpRule[] | null;
13
+ errorFilter?: ((args: UrlWithError) => boolean) | null;
14
+ } | null;
15
+ };
16
+ export declare function initPage(args: {
17
+ page: Page;
18
+ /** for reporting only */
19
+ pageFilePath?: null | string;
20
+ abortSignal?: null | IAbortSignalFast;
21
+ filters?: null | Filters;
22
+ }): Promise<{
23
+ abortSignal: IAbortSignalFast;
24
+ checkErrors: () => Promise<void>;
25
+ }>;
@@ -0,0 +1,17 @@
1
+ import { TestFuncArgs } from './types';
2
+ import { Filters } from './initPage';
3
+ import { Page } from 'playwright';
4
+ import { IAbortSignalFast } from '@flemist/abort-controller-fast';
5
+ export type TestPageFuncArgs = TestFuncArgs & {
6
+ checkErrors: () => Promise<void>;
7
+ };
8
+ export type TestPageFunc = (args: TestPageFuncArgs) => Promise<void>;
9
+ export type TestPageArgs = {
10
+ page: Page;
11
+ abortSignal?: null | IAbortSignalFast;
12
+ filters?: null | Filters;
13
+ func: TestPageFunc;
14
+ /** for reporting only */
15
+ pageFilePath?: null | string;
16
+ };
17
+ export declare function testPage({ page, abortSignal: _abortSignal, filters, func, pageFilePath, }: TestPageArgs): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { Page } from 'playwright';
2
+ import { IAbortSignalFast } from '@flemist/abort-controller-fast';
3
+ export type TestFuncArgs = {
4
+ page: Page;
5
+ abortSignal: IAbortSignalFast;
6
+ };
7
+ export type TestFunc = (args: TestFuncArgs) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { Browser, BrowserType, LaunchOptions } from 'playwright';
2
+ export declare function useBrowser<T = void>({ browserType, options, }: {
3
+ browserType: BrowserType;
4
+ options?: null | LaunchOptions;
5
+ }): (func: (browser: Browser) => Promise<T>) => Promise<T>;
@@ -0,0 +1,5 @@
1
+ import { Browser, BrowserContext, BrowserContextOptions } from 'playwright';
2
+ export declare function useBrowserContext<T = void>({ browser, options, }: {
3
+ browser: Browser;
4
+ options?: null | BrowserContextOptions;
5
+ }): (func: (context: BrowserContext) => Promise<T>) => Promise<T>;
@@ -0,0 +1,2 @@
1
+ export * from './e2e';
2
+ export * from './refactor';
@@ -0,0 +1,11 @@
1
+ import { PagesElementsChangesTest, TPseudoStateConfig, TGetAllElementsFilters } from './types';
2
+ export type ObjectTransform = (value: any, keyOrIndex: string | number | null | undefined, parent: any | null | undefined, transform: ObjectTransform) => any;
3
+ export declare const objectTransform: ObjectTransform;
4
+ export declare function createPagesElementsChangesTest({ actualResultFile, expectedResultFile, diffResultFile, filters, transform, pseudoStates, }: {
5
+ actualResultFile: string;
6
+ expectedResultFile: string;
7
+ diffResultFile?: string;
8
+ filters?: TGetAllElementsFilters;
9
+ transform?: null | ObjectTransform;
10
+ pseudoStates?: null | TPseudoStateConfig[];
11
+ }): PagesElementsChangesTest;
@@ -0,0 +1,5 @@
1
+ import { CDPSession, Page } from 'playwright';
2
+ export declare function createCDPSession(page: Page): Promise<CDPSession>;
3
+ export declare function destroyCDPSession(cdp: CDPSession): Promise<void>;
4
+ export declare function usingCDPSession<Result>(page: Page, func: (cdp: CDPSession) => Promise<Result>): Promise<Result>;
5
+ export declare function forcePseudoClasses(cdp: CDPSession, pseudoClasses: string[]): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { TGetAllElementsArgs } from './types';
2
+ export declare function getAllElements(args: TGetAllElementsArgs): never;
@@ -0,0 +1,2 @@
1
+ import { TElement } from './types';
2
+ export declare function getElementsStyleDiff(base: TElement, state: TElement): TElement | null;
@@ -0,0 +1,6 @@
1
+ export declare const DIFF_OLD = "-";
2
+ export declare const DIFF_NEW = "+";
3
+ export declare function getObjectsDiff(valueOld: any, valueNew: any, handleDiff?: null | ((valueOld: any, valueNew: any, diffs: any) => any)): any[] | Record<string, any> | {
4
+ "-": any;
5
+ "+": any;
6
+ } | null;
@@ -0,0 +1,7 @@
1
+ export * from './types';
2
+ export * from './createPagesElementsChangesTest';
3
+ export * from './forcePseudoClasses';
4
+ export * from './getAllElements';
5
+ export * from './getElementsStyleDiff';
6
+ export * from './getObjectsDiff';
7
+ export * from './loadSaveJson';
@@ -0,0 +1,2 @@
1
+ export declare function saveJson(filePath: string, json: any): Promise<void>;
2
+ export declare function loadJson(filePath: string): Promise<any>;
@@ -0,0 +1,72 @@
1
+ import { Page } from 'playwright';
2
+ export type TNameValue = {
3
+ [key: string]: string;
4
+ };
5
+ export type TStyle = {
6
+ _: TNameValue;
7
+ before: TNameValue;
8
+ after: TNameValue;
9
+ };
10
+ export type TElement = {
11
+ tag: string;
12
+ selector: string;
13
+ classes: string[] | null | undefined;
14
+ attrs: TNameValue | null | undefined;
15
+ style: TStyle | null | undefined;
16
+ childs: TElement[] | null | undefined;
17
+ };
18
+ export type TGetAllElementsFilters = {
19
+ excludeAttrs?: string[];
20
+ /** Fix attribute values by replacing matching patterns; useful for removing generated hashes */
21
+ fixAttrs?: TFixPattern[];
22
+ /** Fix style values by replacing matching patterns in CSS property values */
23
+ fixStyles?: TFixPattern[];
24
+ /** Exclude matching classes from the `classes` array */
25
+ excludeClasses?: RegExp;
26
+ /** Exclude matching id from comparison data */
27
+ excludeIds?: RegExp;
28
+ /** Exclude matching classes from displayed `selector` in diffs */
29
+ excludeSelectorClasses?: RegExp;
30
+ /** Exclude matching id from displayed `selector` in diffs */
31
+ excludeSelectorIds?: RegExp;
32
+ /** Fix tag values by replacing matching patterns */
33
+ fixTags?: TReplacePattern[];
34
+ excludeStyles?: string[];
35
+ excludeSelectors?: string[];
36
+ };
37
+ export type TPseudoStateConfig = {
38
+ states: string[];
39
+ delay?: null | number;
40
+ };
41
+ export type TReplacePattern = {
42
+ search: RegExp;
43
+ replace: string;
44
+ };
45
+ export type TFixPattern = TReplacePattern & {
46
+ name: RegExp;
47
+ };
48
+ export type TGetAllElementsArgs = {
49
+ defaultStyle?: null | TStyle;
50
+ shouldEqualResult?: null | TElement;
51
+ filters?: null | TGetAllElementsFilters;
52
+ };
53
+ export type PagesElementsChangesHandlePage = (args: {
54
+ page: Page;
55
+ testId: string;
56
+ url: URL;
57
+ stateId: string;
58
+ filters?: TGetAllElementsFilters;
59
+ }) => Promise<void>;
60
+ export type PagesElementsChangesTest = {
61
+ init(page: Page): Promise<void>;
62
+ handlePage: PagesElementsChangesHandlePage;
63
+ end({ checkExistUrlsOnly }: {
64
+ checkExistUrlsOnly: boolean;
65
+ }): Promise<{
66
+ [testId: string]: {
67
+ [url: string]: {
68
+ [stateId: string]: TElement;
69
+ };
70
+ };
71
+ }>;
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/simple-utils",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Simple simple utils",
5
5
  "sideEffects": false,
6
6
  "types": "build/common/index.d.ts",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "scripts": {
67
67
  "========================= install =========================": "",
68
- "prepublishOnly": "run-p audit lint build test:all",
68
+ "_prepublishOnly": "run-p audit lint build test:all && npm login",
69
69
  "prepare": "node .husky/install.mjs",
70
70
  "install:playwright": "pnpm exec playwright install --with-deps",
71
71
  "========================= deploy =========================": "",