From 30c3115bfef31f392be5a55b02ae6a98176d6940 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 29 Mar 2024 18:39:34 -0700 Subject: [PATCH] fullproject support --- docs/src/test-api/class-fullproject.md | 93 +++++++++++++++++ utils/doclint/generateFullConfigDoc.js | 138 +++++++++++++++---------- 2 files changed, 179 insertions(+), 52 deletions(-) create mode 100644 docs/src/test-api/class-fullproject.md diff --git a/docs/src/test-api/class-fullproject.md b/docs/src/test-api/class-fullproject.md new file mode 100644 index 0000000000..4e9b0ac86b --- /dev/null +++ b/docs/src/test-api/class-fullproject.md @@ -0,0 +1,93 @@ +# class: FullProject +* since: v1.10 +* langs: js + +## property: FullProject.dependencies +* since: v1.31 +- type: ?<[Array]<[string]>> + +See [`property: TestProject.dependencies`]. + +## property: FullProject.grep +* since: v1.10 +- type: ?<[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grep`]. + +## property: FullProject.grepInvert +* since: v1.10 +- type: ?<[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grepInvert`]. + +## property: FullProject.metadata +* since: v1.10 +- type: ?<[Metadata]> + +See [`property: TestProject.metadata`]. + +## property: FullProject.name +* since: v1.10 +- type: ?<[string]> + +See [`property: TestProject.name`]. + +## property: FullProject.snapshotDir +* since: v1.10 +- type: ?<[string]> + +See [`property: TestProject.snapshotDir`]. + +## property: FullProject.outputDir +* since: v1.10 +- type: ?<[string]> + +See [`property: TestProject.outputDir`]. + +## property: FullProject.repeatEach +* since: v1.10 +- type: ?<[int]> + +See [`property: TestProject.repeatEach`]. + +## property: FullProject.retries +* since: v1.10 +- type: ?<[int]> + +See [`property: TestProject.retries`]. + +## property: FullProject.teardown +* since: v1.34 +- type: ?<[string]> + +See [`property: TestProject.teardown`]. + +## property: FullProject.testDir +* since: v1.10 +- type: ?<[string]> + +See [`property: TestProject.testDir`]. + +## property: FullProject.testIgnore +* since: v1.10 +- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testIgnore`]. + +## property: FullProject.testMatch +* since: v1.10 +- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testMatch`]. + +## property: FullProject.timeout +* since: v1.10 +- type: ?<[int]> + +See [`property: TestProject.timeout`]. + +## property: FullProject.use +* since: v1.10 +- type: <[Fixtures]> + +See [`property: TestProject.use`]. diff --git a/utils/doclint/generateFullConfigDoc.js b/utils/doclint/generateFullConfigDoc.js index ebb2939308..8c00f7f8a2 100644 --- a/utils/doclint/generateFullConfigDoc.js +++ b/utils/doclint/generateFullConfigDoc.js @@ -19,34 +19,20 @@ const path = require('path'); const fs = require('fs'); const PROJECT_DIR = path.join(__dirname, '..', '..'); -const md = require('../markdown'); -const allowList = [ - 'forbidOnly', - 'fullyParallel', - 'globalSetup', - 'globalTeardown', - 'globalTimeout', - 'grep', - 'grepInvert', - 'maxFailures', - 'metadata', - 'version', - 'preserveOutput', - 'projects', - 'reporter', - 'reportSlowTests', - 'rootDir', - 'quiet', - 'shard', - 'updateSnapshots', - 'workers', - 'webServer', - 'configFile', -]; -const allowedNames = new Set(allowList); +function generateFullConfigClass(fromClassName, toClassName, allowList) { + const allowedNames = new Set(allowList); -const content = fs.readFileSync(path.join(PROJECT_DIR, 'docs/src/test-api/class-testconfig.md')).toString(); + const content = fs.readFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${fromClassName.toLowerCase()}.md`)).toString(); + let sections = content.split('\n## '); + sections = filterAllowedSections(sections, allowedNames); + if (allowedNames.size) + console.log(`Undocumented properties for ${fromClassName}:\n ${[...allowedNames].join('\n ')}`); + sections = changeClassName(sections, fromClassName, toClassName); + sections = replacePropertyDescriptions(sections, fromClassName); + const fullconfig = sections.join('\n## '); + fs.writeFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${toClassName.toLowerCase()}.md`), fullconfig); +} function propertyNameFromSection(section) { section = section.split('\n')[0]; @@ -56,32 +42,80 @@ function propertyNameFromSection(section) { return match[1]; } -let sections = content.split('\n## '); -sections = sections.filter(section => { - section = section.split('\n')[0]; - const name = propertyNameFromSection(section); - if (!name) - return true; - return allowedNames.has(name); -}); +function filterAllowedSections(sections, allowedNames) { + return sections.filter(section => { + section = section.split('\n')[0]; + const name = propertyNameFromSection(section); + if (!name) + return true; + return allowedNames.delete(name); + }); +} -// Change class name to FullConfig. -sections = sections.map(section => { - const lines = section.split('\n'); - lines[0] = lines[0].replace('TestConfig', 'FullConfig'); - return lines.join('\n'); -}); +function changeClassName(sections, from, to) { + return sections.map(section => { + const lines = section.split('\n'); + lines[0] = lines[0].replace(from, to); + return lines.join('\n'); + }); +} -// Replace description. -sections = sections.map(section => { - const parts = section.split('\n\n'); - section = parts[0]; - const name = propertyNameFromSection(section); - console.log(name) - if (!name) - return `${section}\n`; - return `${section}\n\nSee [\`property: TestConfig.${name}\`].\n`; -}); +function replacePropertyDescriptions(sections, configClassName) { + return sections.map(section => { + const parts = section.split('\n\n'); + section = parts[0]; + const name = propertyNameFromSection(section); + if (!name) + return `${section}\n`; + return `${section}\n\nSee [\`property: ${configClassName}.${name}\`].\n`; + }); +} -const fullconfig = sections.join('\n## '); -fs.writeFileSync(path.join(PROJECT_DIR, 'docs/src/test-api/class-fullconfig.md'), fullconfig); \ No newline at end of file +function generateFullConfig() { + generateFullConfigClass('TestConfig', 'FullConfig', [ + 'forbidOnly', + 'fullyParallel', + 'globalSetup', + 'globalTeardown', + 'globalTimeout', + 'grep', + 'grepInvert', + 'maxFailures', + 'metadata', + 'version', + 'preserveOutput', + 'projects', + 'reporter', + 'reportSlowTests', + 'rootDir', + 'quiet', + 'shard', + 'updateSnapshots', + 'workers', + 'webServer', + 'configFile', + ]); +} + +function generateFullProject() { + generateFullConfigClass('TestProject', 'FullProject', [ + 'grep', + 'grepInvert', + 'metadata', + 'name', + 'dependencies', + 'snapshotDir', + 'outputDir', + 'repeatEach', + 'retries', + 'teardown', + 'testDir', + 'testIgnore', + 'testMatch', + 'timeout', + 'use', + ]); +} + +generateFullConfig(); +generateFullProject();