testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Add API for more flexible setting of "skip-js-error" option(closes #2775)

Open Artem-Babich opened this issue 2 years ago • 0 comments

Purpose

In some cases, it is necessary to specify more flexible parameters for the skipJsErrors option rather than the regular bool flag.

API

interface SkipJsErrorsOptions {
    message?: string;
    stack?: string;
    pageUrl?: string
}

interface SkipJsErrorsCallback {
    fn: (opts: SkipJsErrorsOptions) => boolean;
    dependencies: Dictionary<unknown>;
}

//CLI and Configuration:
type SkipJsErrorsOptionValue = SkipJsErrorsOptions | boolean;


//Runner
interface RunnerRunOptions {
    skipJsErrors?: boolean | SkipJsErrorsOptions | SkipJsErrorsCallback;
}

//TestController
interface TestController {
  /**
   * Set skipJsErrors options
   *
   * @param options - SkipJsErrorsOptions or boolean.
   */
  skipJsErrors (options: boolean | SkipJsErrorsOptions): TestControllerPromise;
  
  /**
   * Set skipJsErrors handler
   *
   * @param fn - A callback function that will be called for each client error.
   * @param dependencies - Any objects or variables used in the context of the function.
   */
  skipJsErrors (fn: (options: SkipJsErrorsOptions) => boolean, dependencies?: { [key: string]: any }): TestControllerPromise;
}

//Fixture and Test methods:
interface FixtureFn {
    /**
     * Set skipJsError options.
     *
     * @param options - boolean flag or SkipJsErrorsOptions.
     */
    skipJsErrors (options: boolean | SkipJsErrorsOptions): this;

    /**
     * Set skipJsError handler.
     *
     * @param fn - Callback function.
     * @param dependencies - Any objects or variables used in the context of the function.
     */
    skipJsErrors (fn: (options: SkipJsErrorsOptions) => boolean, dependencies?: { [key: string]: any }): this;
}

interface TestFn {
    /**
     * Set skipJsError options.
     *
     * @param options - boolean flag or SkipJsErrorsOptions.
     */
    skipJsErrors (options: boolean | SkipJsErrorsOptions): this;

    /**
     * Set skipJsError handler.
     *
     * @param fn - Callback function.
     * @param dependencies - Any objects or variables used in the context of the function.
     */
    skipJsErrors (fn: (options: SkipJsErrorsOptions) => boolean, dependencies?: { [key: string]: any }): this;
}

Examples:


fixture.skipJsErrors(true);
fixture.skipJsErrors({ message: 'someErr', pageUrl:'https://example.com', stack: 'someStack' });
fixture.skipJsErrors(({ message, pageUrl, stack }) => message === ERROR_MESSAGE, { ERROR_MESSAGE });

test.skipJsErrors(true);
test.skipJsErrors({ message: 'someErr', pageUrl:'https://example.com', stack: 'someStack' });
test.skipJsErrors(({ message, pageUrl, stack }) => message === ERROR_MESSAGE, { ERROR_MESSAGE });

test('test', async t=>{
  await t.skipJsErrors(true);
  await t.skipJsErrors({ message: 'someErr', pageUrl:'https://example.com', stack: 'someStack' });
  await t.skipJsErrors(({ message, pageUrl, stack }) => message === ERROR_MESSAGE, { ERROR_MESSAGE });
});
//CLI:
testcafe chrome test.js -e message=testMessage,stack=testStack,pageUrl=testPageUrl

Artem-Babich avatar Jul 25 '22 22:07 Artem-Babich

Release v2.0.0-rc.1 addresses this.

github-actions[bot] avatar Aug 25 '22 10:08 github-actions[bot]

Release v2.0.0-rc.1 addresses this.

github-actions[bot] avatar Aug 25 '22 10:08 github-actions[bot]