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

fix: prevent double exit from tests subprocess #65

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rules:
complexity: [error, {max: 10}]
curly: [error, all]
default-param-last: off
dot-notation: off
import/exports-last: error
import/extensions: [error, never]
import/named: error
Expand Down Expand Up @@ -151,16 +152,25 @@ rules:
- ['^\..*\u0000$']
sort-keys: [error, asc, {caseSensitive: true, natural: false}]
typescript-sort-keys/string-enum: error
'@typescript-eslint/adjacent-overload-signatures': error
'@typescript-eslint/array-type': error
'@typescript-eslint/ban-types': [error, {extendDefaults: true, types: {'{}': false}}]
'@typescript-eslint/class-literal-property-style': error
'@typescript-eslint/consistent-generic-constructors': error
'@typescript-eslint/consistent-indexed-object-style': error
'@typescript-eslint/consistent-type-assertions':
[error, {assertionStyle: as, objectLiteralTypeAssertions: never}]
'@typescript-eslint/consistent-type-definitions': [error, type]
'@typescript-eslint/consistent-type-exports': error
'@typescript-eslint/consistent-type-imports': [error, {disallowTypeAnnotations: false}]
'@typescript-eslint/default-param-last': error
'@typescript-eslint/dot-notation': error
'@typescript-eslint/explicit-function-return-type': [error, {allowExpressions: true}]
'@typescript-eslint/explicit-member-accessibility': [error, {accessibility: no-public}]
'@typescript-eslint/explicit-module-boundary-types': error
'@typescript-eslint/max-params': [error, {max: 3}]
'@typescript-eslint/member-ordering': [error, {default: {order: alphabetically}}]
'@typescript-eslint/method-signature-style': error
'@typescript-eslint/naming-convention':
- error
- {selector: default, format: [strictCamelCase, StrictPascalCase], leadingUnderscore: allow}
Expand All @@ -173,6 +183,7 @@ rules:
- {selector: [objectLiteralProperty, typeProperty], format: null, modifiers: [requiresQuotes]}
- {selector: [classProperty, typeMethod], filter: '^toJSON$', format: null}
'@typescript-eslint/no-import-type-side-effects': error
'@typescript-eslint/no-inferrable-types': error
'@typescript-eslint/no-invalid-void-type':
[error, {allowInGenericTypeArguments: true, allowAsThisParameter: true}]
'@typescript-eslint/no-namespace': [error, {allowDeclarations: true}]
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"testcafe-without-typecheck": "3.5.0-rc.2"
},
"devDependencies": {
"@types/node": "20.11.17",
"@types/node": "20.11.19",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
"assert-package-lock-is-consistent": "1.0.0",
"devtools-protocol": "0.0.1259648",
"devtools-protocol": "0.0.1261483",
"eslint": "8.56.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-simple-import-sort": "12.0.0",
"eslint-plugin-typescript-sort-keys": "3.1.0",
"husky": "9.0.10",
"husky": "9.0.11",
"prettier": "3.2.5",
"testcafe": "3.5.0",
"typescript": "5.3.3"
Expand Down
7 changes: 5 additions & 2 deletions src/actions/takeScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TakeScreenshot = ((path?: string) => Promise<void>) &
export const takeScreenshot: TakeScreenshot = (pathOrOptions) => {
const options = typeof pathOrOptions === 'string' ? {path: pathOrOptions} : pathOrOptions;
const {
fullPage,
fullPage = false,
path: pathToScreenshot,
timeout = DEFAULT_TAKE_SCREENSHOT_TIMEOUT_IN_MS,
} = options ?? {};
Expand All @@ -31,7 +31,10 @@ export const takeScreenshot: TakeScreenshot = (pathOrOptions) => {
LogEventType.InternalAction,
);

const takeScreenshotOptions = {fullPage, path: pathToScreenshot} as Inner.TakeScreenshotOptions;
const takeScreenshotOptions: Inner.TakeScreenshotOptions = {
fullPage,
path: pathToScreenshot as string,
};
const takeScreenshotPromise = testController.takeScreenshot(takeScreenshotOptions);

if (!(timeout > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/context/waitForEventsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getWaitForEventsState = (
hashOfNotCompleteRequests: Object.create(
null,
) as WaitForEventsState['hashOfNotCompleteRequests'],
hook: {} as RequestHookToWaitForEvents,
hook: {} as unknown as RequestHookToWaitForEvents,
redirects: Object.create(null) as Record<Url, Url>,
requestPredicates: new Set<RequestPredicateWithPromise>(),
responsePredicates: new Set<ResponsePredicateWithPromise>(),
Expand Down
55 changes: 28 additions & 27 deletions src/types/cdp/cdpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,43 @@ export type CdpClient = Readonly<{
close: () => Promise<void>;
host: string;
local: boolean;
on: ((event: 'event', callback: (message: EventMessage) => void) => void) &
((event: 'disconnect' | 'ready', callback: () => void) => void) &
(<T extends keyof ProtocolMappingApi.Events>(
event: T,
callback: (params: ProtocolMappingApi.Events[T][0], sessionId?: string) => void,
) => void) &
((event: string, callback: (params: object, sessionId?: string) => void) => void);
port: number;
protocol: Readonly<{
domains: readonly Domain[];
version: Readonly<{major: string; minor: string}>;
}>;
secure: boolean;
target: Target | string | ((targets: readonly Target[]) => Target | number) | undefined;
useHostName: boolean;
webSocketUrl: string;
on(event: 'event', callback: (message: EventMessage) => void): void;
on(event: 'disconnect' | 'ready', callback: () => void): void;
// '<domain>.<method>' i.e. Network.requestWillBeSent
on<T extends keyof ProtocolMappingApi.Events>(
event: T,
callback: (params: ProtocolMappingApi.Events[T][0], sessionId?: string) => void,
): void;
// '<domain>.<method>.<sessionId>' i.e. Network.requestWillBeSent.abc123
on(event: string, callback: (params: object, sessionId?: string) => void): void;
// client.send(method, [params], [sessionId], [callback])
send<T extends keyof ProtocolMappingApi.Commands>(event: T, callback: SendCallback<T>): void;
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
callback: SendCallback<T>,
): void;
send<T extends keyof ProtocolMappingApi.Commands>(
send: (<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId: string,
callback: SendCallback<T>,
): void;
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params?: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId?: string,
): Promise<ProtocolMappingApi.Commands[T]['returnType']>;
) => void) &
(<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
callback: SendCallback<T>,
) => void) &
(<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId: string,
callback: SendCallback<T>,
) => void) &
(<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params?: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId?: string,
) => Promise<ProtocolMappingApi.Commands[T]['returnType']>);
target: Target | string | ((targets: readonly Target[]) => Target | number) | undefined;
useHostName: boolean;
webSocketUrl: string;
}> &
EventPromises<ProtocolMappingApi.Events> &
EventCallbacks<ProtocolMappingApi.Events> &
Expand Down
2 changes: 1 addition & 1 deletion src/types/extends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ declare module 'testcafe-without-typecheck' {
interface TestController {
readonly testRun: DeepReadonly<{
browserConnection: TestCafeBrowserConnection;
emit: (this: void, eventName: string) => Promise<void>;
errs: readonly OriginalTestRunError[];
test: {testFile: {filename: string}};
emit(this: void, eventName: string): Promise<void>;
}>;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ declare module 'testcafe-without-typecheck/lib/native-automation/request-hooks/e
declare module 'testcafe-without-typecheck/lib/api/test-run-tracker' {
type InternalTestRun = {
controller: Readonly<Record<string, unknown>>;
executeAction: (apiMethodName: string, command: unknown, callsite: unknown) => Promise<unknown>;
executeCommand: (command: unknown) => Promise<unknown>;
id: string;
executeAction(apiMethodName: string, command: unknown, callsite: unknown): Promise<unknown>;
executeCommand(command: unknown): Promise<unknown>;
};

type Fn = (...args: never[]) => unknown;

const testRunTracker: Readonly<{
activeTestRuns: Record<string, InternalTestRun>;
/**
* Wraps function in context tracker for asynchronous calls.
*/
_createContextSwitchingFunctionHook(ctxSwitchingFn: Fn, patchedArgsCount: number): Fn;
addTrackingMarkerToFunction(testRunId: string, fn: Fn): Fn;
ensureEnabled(): void;
resolveContextTestRun(): InternalTestRun;
_createContextSwitchingFunctionHook: (ctxSwitchingFn: Fn, patchedArgsCount: number) => Fn;
activeTestRuns: Record<string, InternalTestRun>;
addTrackingMarkerToFunction: (testRunId: string, fn: Fn) => Fn;
ensureEnabled: () => void;
resolveContextTestRun: () => InternalTestRun;
}>;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/types/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type DataPropertyDescriptor<Value> = Readonly<
GenericPropertyDescriptor;

type AccessorPropertyDescriptor<Value> = Readonly<
{get?(): Value; set(value: Value): void} | {get(): Value; set?(value: Value): void}
| {get: () => Value; set?: (value: Value) => void}
| {get?: () => Value; set: (value: Value) => void}
> &
GenericPropertyDescriptor;

Expand Down
52 changes: 26 additions & 26 deletions src/types/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,89 +86,89 @@ export type Selector = ReplaceObjectSelectors<Inner.SelectorAPI> &
*/
export type SelectorCustomMethods = Readonly<{
/** Finds all child elements (not nodes) of all nodes in the matching set and filters them by locatorId. */
childByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
childByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all child elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */
childByLocatorParameter(
childByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Creates a selector that filters a matching set by locatorId. */
filterByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
filterByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Creates a selector that filters a matching set by locator parameter. */
filterByLocatorParameter(
filterByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Finds all descendants of all nodes in the matching set and filters them by locatorId. */
findByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
findByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all descendants of all nodes in the matching set and filters them by locator parameter. */
findByLocatorParameter(
findByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Get string description of selector if any. */
getDescription(this: TestCafeSelector): string | undefined;
getDescription: (this: TestCafeSelector) => string | undefined;

/** Returns the value of the locator id. */
getLocatorId(this: TestCafeSelector): Promise<string | null>;
getLocatorId: (this: TestCafeSelector) => Promise<string | null>;

/** Returns the value of the locator parameter. */
getLocatorParameter(this: TestCafeSelector, parameter: string): Promise<string | null>;
getLocatorParameter: (this: TestCafeSelector, parameter: string) => Promise<string | null>;

/** true if the element has the locator id. */
hasLocatorId(this: TestCafeSelector): Promise<boolean>;
hasLocatorId: (this: TestCafeSelector) => Promise<boolean>;

/** true if the element has the locator parameter. */
hasLocatorParameter(this: TestCafeSelector, parameter: string): Promise<boolean>;
hasLocatorParameter: (this: TestCafeSelector, parameter: string) => Promise<boolean>;

/** Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */
nextSiblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
nextSiblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */
nextSiblingByLocatorParameter(
nextSiblingByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Finds all parents of all nodes in the matching set and filters them by locatorId. */
parentByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
parentByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all parents of all nodes in the matching set and filters them by locator parameter. */
parentByLocatorParameter(
parentByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */
prevSiblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
prevSiblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */
prevSiblingByLocatorParameter(
prevSiblingByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;

/** Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */
siblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector;
siblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector;

/** Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */
siblingByLocatorParameter(
siblingByLocatorParameter: (
this: TestCafeSelector,
parameter: string,
value: string,
): TestCafeSelector;
) => TestCafeSelector;
}>;

/**
Expand Down
Loading
Loading