fix(types): leave a single js-flavor=ts snippet in JSDoc (#8669)

This commit is contained in:
Dmitry Gozman 2021-09-02 16:18:22 -07:00 committed by GitHub
parent 620712a5d9
commit 962a33993f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 1414 deletions

1479
types/test.d.ts vendored

File diff suppressed because it is too large Load diff

View file

@ -281,33 +281,7 @@ export interface FullResult {
* You can create a custom reporter by implementing a class with some of the reporter methods. Make sure to export this
* class as default.
*
* ```js js-flavor=js
* // my-awesome-reporter.js
* // @ts-check
*
* /** @implements {import('@playwright/test/reporter').Reporter} *\/
* class MyReporter {
* onBegin(config, suite) {
* console.log(`Starting the run with ${suite.allTests().length} tests`);
* }
*
* onTestBegin(test) {
* console.log(`Starting test ${test.title}`);
* }
*
* onTestEnd(test, result) {
* console.log(`Finished test ${test.title}: ${result.status}`);
* }
*
* onEnd(result) {
* console.log(`Finished the run: ${result.status}`);
* }
* }
*
* module.exports = MyReporter;
* ```
*
* ```js js-flavor=ts
* ```ts
* // my-awesome-reporter.ts
* import { Reporter } from '@playwright/test/reporter';
*
@ -333,19 +307,7 @@ export interface FullResult {
*
* Now use this reporter with [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter).
*
* ```js js-flavor=js
* // playwright.config.js
* // @ts-check
*
* /** @type {import('@playwright/test').PlaywrightTestConfig} *\/
* const config = {
* reporter: './my-awesome-reporter.js',
* };
*
* module.exports = config;
* ```
*
* ```js js-flavor=ts
* ```ts
* // playwright.config.ts
* import { PlaywrightTestConfig } from '@playwright/test';
*

View file

@ -293,10 +293,15 @@ class TypesGenerator {
};
let skipExample = false;
for (let line of comment.split('\n')) {
const match = line.match(/```(\w+)/);
const match = line.match(/```(\w+)(\s+js-flavor=(\w+))?/);
if (match) {
const lang = match[1];
skipExample = !["html", "yml", "bash", "js"].includes(lang);
let flavor = 'ts';
if (match[3]) {
flavor = match[3];
line = line.replace(/js-flavor=\w+/, '').replace(/```\w+/, '```ts');
}
skipExample = !["html", "yml", "bash", "js"].includes(lang) || flavor !== 'ts';
} else if (skipExample && line.trim().startsWith('```')) {
skipExample = false;
continue;