Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs: support optional methods (#13415)
Dmitry Gozmancef476b89fd6
diff --git a/docs/src/test-reporter-api/class-reporter.md b/docs/src/test-reporter-api/class-reporter.mdindex 92c6037f00..d7de639b58 100644--- a/docs/src/test-reporter-api/class-reporter.md+++ b/docs/src/test-reporter-api/class-reporter.md@@ -89,7 +89,7 @@ Here is a typical order of reporter calls:Additionally, [`method: Reporter.onStdOut`] and [`method: Reporter.onStdErr`] are called when standard output is produced in the worker process, possibly during a test execution,and [`method: Reporter.onError`] is called when something went wrong outside of the test execution.-## method: Reporter.onBegin+## optional method: Reporter.onBeginCalled once before running tests. All tests have been already discovered and put into a hierarchy of [Suite]s.@@ -105,7 +105,7 @@ The root suite that contains all projects, files and test cases.-## async method: Reporter.onEnd+## optional async method: Reporter.onEndCalled after all tests has been run, or testing has been interrupted. Note that this method may return a [Promise] and Playwright Test will await it.@@ -122,7 +122,7 @@ Result of the full test run.-## method: Reporter.onError+## optional method: Reporter.onErrorCalled on some global error, for example unhandled exception in the worker process.@@ -132,7 +132,7 @@ Called on some global error, for example unhandled exception in the worker proceThe error.-## method: Reporter.onStdErr+## optional method: Reporter.onStdErrCalled when something has been written to the standard error in the worker process.@@ -152,7 +152,7 @@ Test that was running. Note that output may happen when no test is running, in wResult of the test run, this object gets populated while the test runs.-## method: Reporter.onStdOut+## optional method: Reporter.onStdOutCalled when something has been written to the standard output in the worker process.@@ -171,7 +171,7 @@ Test that was running. Note that output may happen when no test is running, in wResult of the test run, this object gets populated while the test runs.-## method: Reporter.onStepBegin+## optional method: Reporter.onStepBeginCalled when a test step started in the worker process.@@ -190,7 +190,7 @@ Result of the test run, this object gets populated while the test runs.Test step instance that has started.-## method: Reporter.onStepEnd+## optional method: Reporter.onStepEndCalled when a test step finished in the worker process.@@ -209,7 +209,7 @@ Result of the test run.Test step instance that has finished.-## method: Reporter.onTestBegin+## optional method: Reporter.onTestBeginCalled after a test has been started in the worker process.@@ -224,7 +224,7 @@ Test that has been started.Result of the test run, this object gets populated while the test runs.-## method: Reporter.onTestEnd+## optional method: Reporter.onTestEndCalled after a test has been finished in the worker process.@@ -239,7 +239,7 @@ Test that has been finished.Result of the test run.-## method: Reporter.printsToStdio+## optional method: Reporter.printsToStdio- returns: <[boolean]>Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance user experience.diff --git a/packages/playwright-test/types/testReporter.d.ts b/packages/playwright-test/types/testReporter.d.tsindex 4580d552d4..8415ff7afe 100644--- a/packages/playwright-test/types/testReporter.d.ts+++ b/packages/playwright-test/types/testReporter.d.ts@@ -355,11 +355,6 @@ export interface FullResult {* went wrong outside of the test execution.*/export interface Reporter {- /**- * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance user- * experience.- */- printsToStdio?(): boolean;/*** Called once before running tests. All tests have been already discovered and put into a hierarchy of [Suite]s.* @param config Resolved configuration.@@ -367,31 +362,38 @@ export interface Reporter {*/onBegin?(config: FullConfig, suite: Suite): void;/**- * Called after a test has been started in the worker process.- * @param test Test that has been started.- * @param result Result of the test run, this object gets populated while the test runs.+ * Called after all tests has been run, or testing has been interrupted. Note that this method may return a [Promise] and+ * Playwright Test will await it.+ * @param result Result of the full test run. - `'passed'` - Everything went as expected.+ * - `'failed'` - Any test has failed.+ * - `'timedout'` - The+ * [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout) has been+ * reached.+ * - `'interrupted'` - Interrupted by the user.*/- onTestBegin?(test: TestCase, result: TestResult): void;+ onEnd?(result: FullResult): void | Promise<void>;/**- * Called when something has been written to the standard output in the worker process.- * @param chunk Output chunk.- * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].- * @param result Result of the test run, this object gets populated while the test runs.+ * Called on some global error, for example unhandled exception in the worker process.+ * @param error The error.*/- onStdOut?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;+ onError?(error: TestError): void;+/*** Called when something has been written to the standard error in the worker process.* @param chunk Output chunk.* @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].* @param result Result of the test run, this object gets populated while the test runs.*/- onStdErr?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;+ onStdErr?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;+/**- * Called after a test has been finished in the worker process.- * @param test Test that has been finished.- * @param result Result of the test run.+ * Called when something has been written to the standard output in the worker process.+ * @param chunk Output chunk.+ * @param test Test that was running. Note that output may happen when no test is running, in which case this will be [void].+ * @param result Result of the test run, this object gets populated while the test runs.*/- onTestEnd?(test: TestCase, result: TestResult): void;+ onStdOut?(chunk: string|Buffer, test: void|TestCase, result: void|TestResult): void;+/*** Called when a test step started in the worker process.* @param test Test that the step belongs to.@@ -399,6 +401,7 @@ export interface Reporter {* @param step Test step instance that has started.*/onStepBegin?(test: TestCase, result: TestResult, step: TestStep): void;+/*** Called when a test step finished in the worker process.* @param test Test that the step belongs to.@@ -406,23 +409,26 @@ export interface Reporter {* @param step Test step instance that has finished.*/onStepEnd?(test: TestCase, result: TestResult, step: TestStep): void;+/**- * Called on some global error, for example unhandled exception in the worker process.- * @param error The error.+ * Called after a test has been started in the worker process.+ * @param test Test that has been started.+ * @param result Result of the test run, this object gets populated while the test runs.*/- onError?(error: TestError): void;+ onTestBegin?(test: TestCase, result: TestResult): void;+/**- * Called after all tests has been run, or testing has been interrupted. Note that this method may return a [Promise] and- * Playwright Test will await it.- * @param result Result of the full test run. - `'passed'` - Everything went as expected.- * - `'failed'` - Any test has failed.- * - `'timedout'` - The- * [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout) has been- * reached.- * - `'interrupted'` - Interrupted by the user.+ * Called after a test has been finished in the worker process.+ * @param test Test that has been finished.+ * @param result Result of the test run.*/- onEnd?(result: FullResult): void | Promise<void>;-}+ onTestEnd?(test: TestCase, result: TestResult): void;++ /**+ * Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance user+ * experience.+ */+ printsToStdio?(): boolean;}// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459export {};diff --git a/utils/doclint/api_parser.js b/utils/doclint/api_parser.jsindex 4eb54ba168..1268ac0c7a 100644--- a/utils/doclint/api_parser.js+++ b/utils/doclint/api_parser.js@@ -83,7 +83,7 @@ class ApiParser {* @param {MarkdownNode} spec*/parseMember(spec) {- const match = spec.text.match(/(event|method|property|async method): ([^.]+)\.(.*)/);+ const match = spec.text.match(/(event|method|property|async method|optional method|optional async method): ([^.]+)\.(.*)/);if (!match)throw new Error('Invalid member: ' + spec.text);const name = match[3];@@ -105,10 +105,12 @@ class ApiParser {member = Documentation.Member.createEvent(extractLangs(spec), name, returnType, comments);if (match[1] === 'property')member = Documentation.Member.createProperty(extractLangs(spec), name, returnType, comments, !optional);- if (match[1] === 'method' || match[1] === 'async method') {+ if (['method', 'async method', 'optional method', 'optional async method'].includes(match[1])) {member = Documentation.Member.createMethod(extractLangs(spec), name, [], returnType, comments);- if (match[1] === 'async method')+ if (match[1].includes('async'))member.async = true;+ if (match[1].includes('optional'))+ member.required = false;}const clazz = this.classes.get(match[2]);const existingMember = clazz.membersArray.find(m => m.name === name && m.kind === member.kind);diff --git a/utils/doclint/documentation.js b/utils/doclint/documentation.jsindex 40b8c941dd..664eb4d6dd 100644--- a/utils/doclint/documentation.js+++ b/utils/doclint/documentation.js@@ -285,9 +285,8 @@ Documentation.Member = class {* @param {!Array<!Documentation.Member>} argsArray* @param {MarkdownNode[]=} spec* @param {boolean=} required- * @param {string[]=} templates*/- constructor(kind, langs, name, type, argsArray, spec = undefined, required = true, templates = []) {+ constructor(kind, langs, name, type, argsArray, spec = undefined, required = true) {this.kind = kind;this.langs = langs;this.name = name;diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.tsindex c47fc677b8..619553b603 100644--- a/utils/generate_types/overrides-testReporter.d.ts+++ b/utils/generate_types/overrides-testReporter.d.ts@@ -44,15 +44,7 @@ export interface FullResult {}export interface Reporter {- printsToStdio?(): boolean;onBegin?(config: FullConfig, suite: Suite): void;- onTestBegin?(test: TestCase, result: TestResult): void;- onStdOut?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;- onStdErr?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;- onTestEnd?(test: TestCase, result: TestResult): void;- onStepBegin?(test: TestCase, result: TestResult, step: TestStep): void;- onStepEnd?(test: TestCase, result: TestResult, step: TestStep): void;- onError?(error: TestError): void;onEnd?(result: FullResult): void | Promise<void>;}