lantern-harness 0.1.43 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +1 -1
- package/builtin/session/lh-nav-groups.mjs +18 -4
- package/dist/500.html +61 -5
- package/dist/_astro/Base.Bkt1lrgu.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.Chv7r8_9.js → Base.astro_astro_type_script_index_0_lang.UKTVQqk7.js} +1 -1
- package/dist/_astro/{CaseExecBoard.DUMjSunb.js → CaseExecBoard.DICluCbK.js} +1 -1
- package/dist/_astro/{CaseGenerateApp.DtuOyQuv.js → CaseGenerateApp.Be3h5XPG.js} +1 -1
- package/dist/_astro/{CasesLibrary.B9o_jvXb.js → CasesLibrary.Buys7Cy-.js} +3 -3
- package/dist/_astro/ChatApp.D3BheKci.js +227 -0
- package/dist/_astro/ConfirmDialog.DrrPf1MB.js +1 -0
- package/dist/_astro/{DashboardBoard.DEvgMoqo.js → DashboardBoard.Qvf8o4v1.js} +1 -1
- package/dist/_astro/{DocsFileBrowser.D66pN9rp.js → DocsFileBrowser.DwKBffbM.js} +1 -1
- package/dist/_astro/{DocsPager.ceBEecmd.js → DocsPager.Duf4I68E.js} +1 -1
- package/dist/_astro/{DrawerField.CWpOf3L_.js → DrawerField.BH3p4Q4D.js} +1 -1
- package/dist/_astro/{KnowledgeLibrary.DYqE2mRi.js → KnowledgeLibrary.MDpMqeOd.js} +1 -1
- package/dist/_astro/{LifeKrTasksBoard.B7UiEutA.js → LifeKrTasksBoard.DsvW_S66.js} +1 -1
- package/dist/_astro/{LifeKrTodosBoard.VL7HdhNY.js → LifeKrTodosBoard.D2KTqvg1.js} +1 -1
- package/dist/_astro/{LifeObjectivesBoard.lLBPOHEZ.js → LifeObjectivesBoard.B0cDK934.js} +1 -1
- package/dist/_astro/{LifePlanTypeSelect.CdKQmlEK.js → LifePlanTypeSelect.BELDvMWU.js} +1 -1
- package/dist/_astro/{LifeReviewsBoard.AjO4SbsR.js → LifeReviewsBoard.BPXeVpg1.js} +1 -1
- package/dist/_astro/{LifeShared.CtdsQI43.js → LifeShared.tnT7aQON.js} +1 -1
- package/dist/_astro/{LifeStagesBoard.Dl-kTZ6K.js → LifeStagesBoard.CZftLR9K.js} +1 -1
- package/dist/_astro/{LifeYearCycleSelect.BILJOKXK.js → LifeYearCycleSelect.Bw2eRbSm.js} +1 -1
- package/dist/_astro/{LifeYearPlansBoard.BzJmi7Hw.js → LifeYearPlansBoard.DB-RJFEl.js} +1 -1
- package/dist/_astro/{MultiSelectDropdown.y8JMbCxO.js → MultiSelectDropdown.CBC7aNOv.js} +1 -1
- package/dist/_astro/NavLibraries.DdQYsZbe.js +1 -0
- package/dist/_astro/OverflowHint.CHZeFfUj.js +1 -0
- package/dist/_astro/{PluginsPage.D2OrUGY3.js → PluginsPage.C1JnInH4.js} +1 -1
- package/dist/_astro/PluginsPage.C3eEwy3K.js +1 -0
- package/dist/_astro/{PmBugsBoard.BynUocbE.js → PmBugsBoard.CGpXUTPu.js} +1 -1
- package/dist/_astro/{PmIterationsBoard.CvFblvfX.js → PmIterationsBoard.BaKiFIam.js} +1 -1
- package/dist/_astro/{PmProjectDetail.Dlm6flwk.js → PmProjectDetail.DneFVBpy.js} +1 -1
- package/dist/_astro/{PmProjectsBoard.B5vaWuax.js → PmProjectsBoard.BxoMF9gK.js} +1 -1
- package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +1 -0
- package/dist/_astro/{PmRequirementsBoard.piRWjiYA.js → PmRequirementsBoard.DsK6RF7Q.js} +1 -1
- package/dist/_astro/PmShared.BK8kWRSV.js +1 -0
- package/dist/_astro/{PromptMountDialog.DYojFMok.js → PromptMountDialog.mrTx3U5T.js} +1 -1
- package/dist/_astro/PromptsLibrary.B_SUf47p.js +1 -0
- package/dist/_astro/{ReportsPage.B-xhGVEU.js → ReportsPage.B9lGg1_s.js} +1 -1
- package/dist/_astro/{ReqAnalysisBoard.B3sAOuAq.js → ReqAnalysisBoard.CIZKnCQH.js} +1 -1
- package/dist/_astro/{RequirementsLibrary.BGys7DeN.js → RequirementsLibrary.cJc-bnGQ.js} +1 -1
- package/dist/_astro/{SearchableSelect.DFZBUFIs.js → SearchableSelect.SyLRS-Jj.js} +1 -1
- package/dist/_astro/SelectDropdown.T3CKHaLt.js +1 -0
- package/dist/_astro/{SettingsDialog.CEyjZuxq.js → SettingsDialog.DYdtCvLc.js} +1 -1
- package/dist/_astro/{SpaceSwitcher.DJqvw5Lw.js → SpaceSwitcher.C47_S1g9.js} +1 -1
- package/dist/_astro/{TableFieldConfig.D0v9S2g3.js → TableFieldConfig.C7O-mL-p.js} +1 -1
- package/dist/_astro/{TasksBoard.DZ9LLl_c.js → TasksBoard.BUEg2BYk.js} +1 -1
- package/dist/_astro/{TemplatesLibrary.iyj_kFMO.js → TemplatesLibrary.BLVIphXO.js} +1 -1
- package/dist/_astro/{TestReportsLibrary.B6pf0d7W.js → TestReportsLibrary.DVq30Jae.js} +1 -1
- package/dist/_astro/{TestStatsBoard.DS_2bqWI.js → TestStatsBoard.-5BWQ6bI.js} +1 -1
- package/dist/_astro/{TodosBoard.CYAVDD1W.js → TodosBoard.DI_lTp2e.js} +1 -1
- package/dist/_astro/UiAutoBoard.ChFdgv7s.js +2 -0
- package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +19 -0
- package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +1 -0
- package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +3 -0
- package/dist/_astro/app-config.DkyjuL-S.js +1 -0
- package/dist/_astro/app-version.Cy-5oZO2.js +1 -0
- package/dist/_astro/{bash-tools.CfNj2sh0.js → bash-tools.D9HCzC_7.js} +1 -1
- package/dist/_astro/{case-gen-run.nrr97yK3.js → case-gen-run.BklG1H8k.js} +1 -1
- package/dist/_astro/{case-types.B51yDRdf.js → case-types.DlFkbZJN.js} +1 -1
- package/dist/_astro/composer-draft.llpvz3MW.js +1 -0
- package/dist/_astro/composer-task.DRi5tAJs.js +5 -0
- package/dist/_astro/{hydrate-cache.CoD1FB3T.js → hydrate-cache.B15Nrpq0.js} +1 -1
- package/dist/_astro/i18n.D_aOCHSN.js +7 -0
- package/dist/_astro/{open-docs-in-session.DJtuI1C4.js → open-docs-in-session.CRiZT022.js} +1 -1
- package/dist/_astro/plugins.BRvXWHLe.js +1 -0
- package/dist/_astro/prompts-meta.BUGutlsk.js +2 -0
- package/dist/_astro/{req-analysis.qmyv5cBw.js → req-analysis.B12_MGMQ.js} +1 -1
- package/dist/_astro/{settings.CYERib3l.js → settings.38J2uD5M.js} +2 -2
- package/dist/_astro/{spaces-client.DvIgFink.js → spaces-client.DV04tRyD.js} +1 -1
- package/dist/_astro/{story-review.2UUlN3p-.js → story-review.D2W5tEOY.js} +1 -1
- package/dist/_astro/{test-reports.DPQ-FMsQ.js → test-reports.CuIjlEyK.js} +1 -1
- package/dist/_astro/ui-auto-prompt.H9_yhau9.js +9 -0
- package/dist/_astro/ui-auto.DMv940x4.js +1 -0
- package/dist/_astro/{view-prefs.GnvelRDj.js → view-prefs.DhdLZjGh.js} +1 -1
- package/dist/case-exec/index.html +62 -6
- package/dist/cases/generate/index.html +62 -6
- package/dist/cases/library/index.html +62 -6
- package/dist/dashboard/index.html +62 -6
- package/dist/docs/changelog/index.html +138 -50
- package/dist/docs/install/index.html +61 -5
- package/dist/docs/manual/index.html +129 -21
- package/dist/knowledge/index.html +62 -6
- package/dist/life/kr-tasks/index.html +62 -6
- package/dist/life/kr-todos/index.html +62 -6
- package/dist/life/objectives/index.html +62 -6
- package/dist/life/reviews/index.html +62 -6
- package/dist/life/stages/index.html +62 -6
- package/dist/life/year-plans/index.html +62 -6
- package/dist/plugins/index.html +62 -6
- package/dist/pm/bugs/index.html +62 -6
- package/dist/pm/iterations/index.html +62 -6
- package/dist/pm/projects/detail/index.html +62 -6
- package/dist/pm/projects/index.html +62 -6
- package/dist/pm/requirements/index.html +62 -6
- package/dist/prompts/index.html +62 -6
- package/dist/reports/index.html +62 -6
- package/dist/requirement-analysis/index.html +62 -6
- package/dist/requirements/index.html +62 -6
- package/dist/tasks/index.html +62 -6
- package/dist/templates/index.html +62 -6
- package/dist/test-automation/index.html +63 -7
- package/dist/test-automation/projects/index.html +980 -0
- package/dist/test-reports/index.html +62 -6
- package/dist/test-stats/index.html +62 -6
- package/dist/todos/index.html +62 -6
- package/dist/workbench/index.html +62 -6
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +1 -1
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +107 -63
- package/lh-plugins/lh-uiauto.mjs +2502 -51
- package/lh-plugins/plugin-prompts.mjs +62 -2
- package/lh-plugins/storage-domain.mjs +17 -4
- package/lh-plugins/uiauto-adapters/playwright.mjs +29 -14
- package/lh-plugins/uiauto-adapters/tasks.mjs +8 -2
- package/lh-plugins/uiauto-env.mjs +669 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +4 -5
- package/lh-plugins/uiauto-explorer/emit-files.mjs +32 -9
- package/lh-plugins/uiauto-explorer/emit-ts.mjs +13 -2
- package/lh-plugins/uiauto-explorer/ir.mjs +20 -0
- package/lh-plugins/uiauto-explorer/sessions.mjs +36 -0
- package/lh-plugins/uiauto-node.mjs +327 -0
- package/lh-plugins/uiauto-pm.mjs +178 -0
- package/lh-plugins/uiauto-prompt.mjs +228 -18
- package/lh-plugins/uiauto-report.mjs +16 -0
- package/lh-plugins/uiauto-scaffold/audit.mjs +356 -0
- package/lh-plugins/uiauto-scaffold/index.mjs +25 -0
- package/lh-plugins/uiauto-scaffold/library.mjs +508 -0
- package/lh-plugins/uiauto-scaffold/manifest.mjs +83 -0
- package/lh-plugins/uiauto-scaffold/render.mjs +133 -0
- package/lh-plugins/uiauto-scaffold/templates/playwright-ts.json +225 -0
- package/lh-plugins/uiauto-scaffold/templates/playwright-ts.mjs +46 -0
- package/package.json +1 -1
- package/dist/_astro/Base.BnVp5Mf8.css +0 -1
- package/dist/_astro/ChatApp.CKPGFibd.js +0 -227
- package/dist/_astro/ConfirmDialog.D5qXeML0.js +0 -1
- package/dist/_astro/NavLibraries.BnaL-km5.js +0 -1
- package/dist/_astro/OverflowHint.pvo2Xc8R.js +0 -1
- package/dist/_astro/PluginsPage.CMW4hEFr.js +0 -1
- package/dist/_astro/PmRequirementsBoard.B8KTeso8.js +0 -1
- package/dist/_astro/PmShared.86HEsdd_.js +0 -1
- package/dist/_astro/PromptsLibrary.GpNbBTj1.js +0 -1
- package/dist/_astro/SelectDropdown.Dmk5n225.js +0 -1
- package/dist/_astro/SlideOverDrawer.C1IVOc_8.js +0 -1
- package/dist/_astro/UiAutoBoard.DSsiMfx2.js +0 -9
- package/dist/_astro/app-config.DwpFFa5D.js +0 -1
- package/dist/_astro/app-version.Dabxyva-.js +0 -1
- package/dist/_astro/composer-task.DJmluzPT.js +0 -5
- package/dist/_astro/i18n.vo2aElR9.js +0 -7
- package/dist/_astro/plugins.BmKRnp4a.js +0 -1
- package/dist/_astro/prompts-meta.bF2q5SUy.js +0 -2
- package/dist/_astro/ui-auto-prompt.COBTt5Gd.js +0 -4
- package/dist/_astro/ui-auto.BmC9JJ_X.js +0 -1
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* - page object 按 goto 的 URL 分段:/login → LoginPage,/ → HomePage。
|
|
10
10
|
* - 定位器文本是中文时方法名退化到角色名(clickButton),重名再加序号。
|
|
11
11
|
*/
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
12
14
|
import { emitCode } from './emit.mjs';
|
|
13
15
|
import { locatorCode as tsLocator, valueCode as tsValue } from './emit-ts.mjs';
|
|
14
16
|
import { locatorCode as pyLocator, valueCode as pyValue } from './emit-python.mjs';
|
|
15
|
-
import { normalizeIr, pythonFunctionName, slugify } from './ir.mjs';
|
|
17
|
+
import { DEFAULT_TEST_TAG, normalizeIr, normalizeTag, pythonFunctionName, slugify } from './ir.mjs';
|
|
16
18
|
|
|
17
19
|
const q = (value) => JSON.stringify(String(value ?? ''));
|
|
18
20
|
|
|
@@ -173,8 +175,10 @@ export function renderTsPage(page) {
|
|
|
173
175
|
return lines.join('\n');
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
/** spec 里与 page object 无关的步骤:导航 / 等待 / 截图 / URL 断言 */
|
|
177
|
-
|
|
178
|
+
/** spec 里与 page object 无关的步骤:导航 / 等待 / 截图 / URL 断言 */ function specStepLine(
|
|
179
|
+
step,
|
|
180
|
+
index,
|
|
181
|
+
) {
|
|
178
182
|
switch (step.action) {
|
|
179
183
|
case 'expectUrl':
|
|
180
184
|
return ` await expect(page).toHaveURL(${tsValue(step.url ?? '/')});`;
|
|
@@ -208,8 +212,10 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
208
212
|
}
|
|
209
213
|
lines.push(' */');
|
|
210
214
|
lines.push("import { test, expect } from '@playwright/test';");
|
|
215
|
+
// 页面对象可能在根级 pages/(企业级骨架)或 tests/pages/(老布局),import 按实际相对位置算
|
|
216
|
+
const pagesImport = options.pagesImport || './pages';
|
|
211
217
|
for (const page of pages) {
|
|
212
|
-
lines.push(`import { ${page.name} } from '
|
|
218
|
+
lines.push(`import { ${page.name} } from '${pagesImport}/${page.name}';`);
|
|
213
219
|
}
|
|
214
220
|
if (ir.storageState && options.fixturePath) {
|
|
215
221
|
lines.push(`import { STORAGE_STATE } from '${options.fixtureImport}';`);
|
|
@@ -227,7 +233,9 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
227
233
|
}
|
|
228
234
|
|
|
229
235
|
lines.push(`test.describe(${q(title)}, () => {`);
|
|
230
|
-
lines.push(
|
|
236
|
+
lines.push(
|
|
237
|
+
` test(${q(title)}, { tag: [${q(normalizeTag(ir.tag) || normalizeTag(options.tag) || DEFAULT_TEST_TAG)}] }, async ({ page }) => {`,
|
|
238
|
+
);
|
|
231
239
|
if (ir.baseURL) lines.push(` // baseURL: ${ir.baseURL}`);
|
|
232
240
|
for (const page of pages) {
|
|
233
241
|
lines.push(` const ${varName(page.name)} = new ${page.name}(page);`);
|
|
@@ -427,6 +435,16 @@ function normalizeDir(value, fallback) {
|
|
|
427
435
|
return raw || fallback;
|
|
428
436
|
}
|
|
429
437
|
|
|
438
|
+
/**
|
|
439
|
+
* `from` 目录里 import `to` 目录时该写的前缀:
|
|
440
|
+
* tests → tests/pages 得 './pages';tests → pages 得 '../pages';同一层得 '.'。
|
|
441
|
+
*/
|
|
442
|
+
function relativeImport(from, to) {
|
|
443
|
+
const rel = path.posix.relative(normalizeDir(from, '.'), normalizeDir(to, '.'));
|
|
444
|
+
if (!rel) return '.';
|
|
445
|
+
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
446
|
+
}
|
|
447
|
+
|
|
430
448
|
/**
|
|
431
449
|
* 生成一组待写入文件。
|
|
432
450
|
*
|
|
@@ -437,6 +455,9 @@ export function emitFiles(rawIr, target, options = {}) {
|
|
|
437
455
|
const ir = normalizeIr(rawIr, { target });
|
|
438
456
|
const language = target === 'python' || ir.target === 'python' ? 'python' : 'ts';
|
|
439
457
|
const testDir = normalizeDir(options.testDir, 'tests');
|
|
458
|
+
// 页面对象 / fixture 的落点:企业级骨架在根级,老项目在 testDir 下
|
|
459
|
+
const pagesDir = normalizeDir(options.pagesDir, `${testDir}/pages`);
|
|
460
|
+
const fixturesDir = normalizeDir(options.fixturesDir, `${testDir}/fixtures`);
|
|
440
461
|
const single = emitCode(ir, language);
|
|
441
462
|
const pages = splitPages(ir);
|
|
442
463
|
const files = [];
|
|
@@ -450,28 +471,30 @@ export function emitFiles(rawIr, target, options = {}) {
|
|
|
450
471
|
});
|
|
451
472
|
for (const page of pages) {
|
|
452
473
|
files.push({
|
|
453
|
-
path: `${
|
|
474
|
+
path: `${pagesDir}/${snake(page.name).replace(/_page$/, '')}_page.py`,
|
|
454
475
|
content: renderPyPage(page),
|
|
455
476
|
language: 'python',
|
|
456
477
|
role: 'page',
|
|
457
478
|
});
|
|
458
479
|
}
|
|
459
480
|
} else {
|
|
460
|
-
const fixturePath = `${
|
|
461
|
-
const fixtureImport =
|
|
481
|
+
const fixturePath = `${fixturesDir}/auth-state.ts`;
|
|
482
|
+
const fixtureImport = `${relativeImport(testDir, fixturesDir)}/auth-state`;
|
|
462
483
|
const useFixture = Boolean(ir.storageState) && options.fixture !== false;
|
|
463
484
|
files.push({
|
|
464
485
|
path: `${testDir}/${single.filename}`,
|
|
465
486
|
content: renderTsSpec(ir, pages, {
|
|
466
487
|
fixturePath: useFixture ? fixturePath : '',
|
|
467
488
|
fixtureImport,
|
|
489
|
+
pagesImport: relativeImport(testDir, pagesDir),
|
|
490
|
+
tag: options.tag,
|
|
468
491
|
}),
|
|
469
492
|
language: 'ts',
|
|
470
493
|
role: 'spec',
|
|
471
494
|
});
|
|
472
495
|
for (const page of pages) {
|
|
473
496
|
files.push({
|
|
474
|
-
path: `${
|
|
497
|
+
path: `${pagesDir}/${page.name}.ts`,
|
|
475
498
|
content: renderTsPage(page),
|
|
476
499
|
language: 'ts',
|
|
477
500
|
role: 'page',
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* IR → Playwright Test(TypeScript)
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_TEST_TAG,
|
|
6
|
+
normalizeTag,
|
|
7
|
+
pythonFunctionName,
|
|
8
|
+
slugify,
|
|
9
|
+
splitEnvValue,
|
|
10
|
+
} from './ir.mjs';
|
|
5
11
|
|
|
6
12
|
const q = (value) => JSON.stringify(String(value ?? ''));
|
|
7
13
|
|
|
@@ -77,6 +83,11 @@ function stepCode(step, index) {
|
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
|
|
86
|
+
/** `test('标题', { tag: ['@smoke'] }, async ({ page }) => {` —— 标签驱动 --grep,不靠文件名 */
|
|
87
|
+
function testSignature(title, tag) {
|
|
88
|
+
return `test(${q(title)}, { tag: [${q(tag)}] }, async ({ page }) => {`;
|
|
89
|
+
}
|
|
90
|
+
|
|
80
91
|
/** 生成 TS 脚本;`ir` 需先过 normalizeIr */
|
|
81
92
|
export function renderTs(ir) {
|
|
82
93
|
const title = ir.title || 'AI 生成用例';
|
|
@@ -101,7 +112,7 @@ export function renderTs(ir) {
|
|
|
101
112
|
lines.push('');
|
|
102
113
|
}
|
|
103
114
|
lines.push(`test.describe(${q(title)}, () => {`);
|
|
104
|
-
lines.push(`
|
|
115
|
+
lines.push(` ${testSignature(title, normalizeTag(ir.tag) || DEFAULT_TEST_TAG)}`);
|
|
105
116
|
if (ir.baseURL) lines.push(` // baseURL: ${ir.baseURL}`);
|
|
106
117
|
for (let index = 0; index < ir.steps.length; index += 1) {
|
|
107
118
|
const step = ir.steps[index];
|
|
@@ -23,6 +23,24 @@ export const STEP_ACTIONS = [
|
|
|
23
23
|
|
|
24
24
|
const LOCATOR_ACTIONS = new Set(['click', 'fill', 'select', 'press', 'hover', 'expect']);
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* 分级标签:与骨架的 `@smoke` / `@regression` / `@edge` 一致。
|
|
28
|
+
* 平台用例优先级在出码前映射到这里(P0 → @smoke、P1 → @regression、P2/P3 → @edge)。
|
|
29
|
+
*/
|
|
30
|
+
export const TEST_TAGS = ['@smoke', '@regression', '@edge'];
|
|
31
|
+
/** 没指定标签时的缺省级别:回归是覆盖面最广的一档 */
|
|
32
|
+
export const DEFAULT_TEST_TAG = '@regression';
|
|
33
|
+
|
|
34
|
+
/** 归一化标签:允许写 `smoke` / `@smoke`,其它值一律丢掉(不让模型写出跑不到的标签) */
|
|
35
|
+
export function normalizeTag(raw) {
|
|
36
|
+
const value = String(raw ?? '')
|
|
37
|
+
.trim()
|
|
38
|
+
.toLowerCase();
|
|
39
|
+
if (!value) return '';
|
|
40
|
+
const tag = value.startsWith('@') ? value : `@${value}`;
|
|
41
|
+
return TEST_TAGS.includes(tag) ? tag : '';
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
/** 需要定位器的动作里,没给 locator 的直接丢掉,避免生成必崩的脚本 */
|
|
27
45
|
export function normalizeIr(raw, fallback = {}) {
|
|
28
46
|
const source = raw && typeof raw === 'object' ? raw : {};
|
|
@@ -53,6 +71,8 @@ export function normalizeIr(raw, fallback = {}) {
|
|
|
53
71
|
target: (source.target ?? fallback.target) === 'python' ? 'python' : 'ts',
|
|
54
72
|
baseURL: String(source.baseURL ?? fallback.baseURL ?? ''),
|
|
55
73
|
storageState: String(source.storageState ?? fallback.storageState ?? ''),
|
|
74
|
+
// 分级标签:为空表示用缺省级别(出码时补 @regression)
|
|
75
|
+
tag: normalizeTag(source.tag ?? fallback.tag),
|
|
56
76
|
source: String(source.source ?? fallback.source ?? '').slice(0, 2000),
|
|
57
77
|
steps: normalized,
|
|
58
78
|
};
|
|
@@ -633,6 +633,42 @@ export function findPlaywrightConfig(projectDir) {
|
|
|
633
633
|
return '';
|
|
634
634
|
}
|
|
635
635
|
|
|
636
|
+
/**
|
|
637
|
+
* 出码落点:页面对象 / fixture 该写到哪、spec 里 import 该写什么。
|
|
638
|
+
*
|
|
639
|
+
* 企业级骨架把 `pages/` `fixtures/` 放在项目根,老项目还在 `tests/pages/`。
|
|
640
|
+
* 只看目录存在与否,不猜:
|
|
641
|
+
* - 根上有 `pages/` → 新布局(根级)
|
|
642
|
+
* - 否则回退 `tests/pages`(老布局,保持原样不动)
|
|
643
|
+
* 两边都不存在时按新布局建——生成的骨架一定是根级。
|
|
644
|
+
*
|
|
645
|
+
* @param {string} projectDir 项目根
|
|
646
|
+
* @param {string} [testDir] 已知的 testDir;不传就自己读 playwright 配置
|
|
647
|
+
* @returns {{ testDir: string, pagesDir: string, fixturesDir: string, rootPages: boolean }}
|
|
648
|
+
*/
|
|
649
|
+
export function detectEmitLayout(projectDir, testDir = '') {
|
|
650
|
+
const dir = String(testDir || '').replace(/^\.?\//, '') || detectPlaywrightTestDir(projectDir);
|
|
651
|
+
const isDir = (rel) => {
|
|
652
|
+
try {
|
|
653
|
+
return fs.statSync(path.join(projectDir, rel)).isDirectory();
|
|
654
|
+
} catch {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
// 根级 pages/ 是企业在用的口径;老项目只有 tests/pages
|
|
659
|
+
const rootPages = isDir('pages');
|
|
660
|
+
const legacyPages = isDir(`${dir}/pages`);
|
|
661
|
+
const rootFixtures = isDir('fixtures');
|
|
662
|
+
const legacyFixtures = isDir(`${dir}/fixtures`);
|
|
663
|
+
const newLayout = rootPages || !legacyPages;
|
|
664
|
+
return {
|
|
665
|
+
testDir: dir,
|
|
666
|
+
pagesDir: newLayout ? 'pages' : `${dir}/pages`,
|
|
667
|
+
fixturesDir: rootFixtures || !legacyFixtures ? 'fixtures' : `${dir}/fixtures`,
|
|
668
|
+
rootPages: newLayout,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
636
672
|
/**
|
|
637
673
|
* 草稿放在项目的 `projects[].testMatch` 之外时,Playwright 会直接「No tests found」。
|
|
638
674
|
* 所以试跑 / 调试用一份独立配置:继承用户配置(webServer / expect / retries 等),
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node 版本:读项目约定的版本(`.nvmrc` / `package.json` 的 engines),
|
|
3
|
+
* 再扫本机 nvm / fnm / volta 里已装好的版本。
|
|
4
|
+
*
|
|
5
|
+
* 只做两件事:把「项目要哪个 Node」查出来、把跑用例时的 PATH 指到那个 Node 的 bin。
|
|
6
|
+
* 不去改用户 shell 的版本——`nvm use` 是 shell 函数,子进程里切了也不影响用户的终端;
|
|
7
|
+
* 想在本机终端手动切,面板给出可复制的命令即可。
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
import { findExecutable } from './uiauto-pm.mjs';
|
|
14
|
+
|
|
15
|
+
const VERSION_RE = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/i;
|
|
16
|
+
|
|
17
|
+
/** `22` / `v22.23.0` / `22.23.0-linux-x64` → `[22, 23, 0]`;认不出返回 null */
|
|
18
|
+
export function parseNodeVersion(raw) {
|
|
19
|
+
const matched = VERSION_RE.exec(String(raw ?? '').trim());
|
|
20
|
+
if (!matched) return null;
|
|
21
|
+
return [Number(matched[1]), Number(matched[2] ?? 0), Number(matched[3] ?? 0)];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function compareVersion(a, b) {
|
|
25
|
+
for (let i = 0; i < 3; i += 1) {
|
|
26
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 版本是否满足要求。支持 `.nvmrc` 里常见的写法:
|
|
33
|
+
* 精确 `22.23.0`、前缀 `22` / `22.23`、范围 `>=20 <23`、`^22.23.0`、`~22.23.0`、`lts/*`。
|
|
34
|
+
*/
|
|
35
|
+
export function satisfiesNode(version, requirement) {
|
|
36
|
+
const target = parseNodeVersion(version);
|
|
37
|
+
if (!target) return false;
|
|
38
|
+
const req = String(requirement ?? '').trim();
|
|
39
|
+
if (!req || req === '*' || /^(node|lts|lts\/\*|lts-\*|latest)$/i.test(req)) return true;
|
|
40
|
+
// 空格分隔的多段(`>=20 <23`)逐段都要满足
|
|
41
|
+
const parts = req.split(/\s+/).filter(Boolean);
|
|
42
|
+
if (parts.length > 1) return parts.every((part) => satisfiesNode(version, part));
|
|
43
|
+
|
|
44
|
+
const matched = /^(>=|<=|>|<|=|\^|~)?\s*(.+)$/.exec(req);
|
|
45
|
+
if (!matched) return false;
|
|
46
|
+
const operator = matched[1] ?? '';
|
|
47
|
+
const raw = matched[2].trim();
|
|
48
|
+
const wanted = parseNodeVersion(raw);
|
|
49
|
+
if (!wanted) return false;
|
|
50
|
+
|
|
51
|
+
switch (operator) {
|
|
52
|
+
case '>=':
|
|
53
|
+
return compareVersion(target, wanted) >= 0;
|
|
54
|
+
case '<=':
|
|
55
|
+
return compareVersion(target, wanted) <= 0;
|
|
56
|
+
case '>':
|
|
57
|
+
return compareVersion(target, wanted) > 0;
|
|
58
|
+
case '<':
|
|
59
|
+
return compareVersion(target, wanted) < 0;
|
|
60
|
+
case '=':
|
|
61
|
+
return compareVersion(target, wanted) === 0;
|
|
62
|
+
case '^': {
|
|
63
|
+
// ^22.23.0 → >=22.23.0 <23.0.0
|
|
64
|
+
const upper = wanted[0] === 0 ? [0, wanted[1] + 1, 0] : [wanted[0] + 1, 0, 0];
|
|
65
|
+
return compareVersion(target, wanted) >= 0 && compareVersion(target, upper) < 0;
|
|
66
|
+
}
|
|
67
|
+
case '~': {
|
|
68
|
+
// ~22.23.0 → >=22.23.0 <22.24.0
|
|
69
|
+
const upper = [wanted[0], wanted[1] + 1, 0];
|
|
70
|
+
return compareVersion(target, wanted) >= 0 && compareVersion(target, upper) < 0;
|
|
71
|
+
}
|
|
72
|
+
default: {
|
|
73
|
+
// 没写运算符:精确 / 前缀匹配(`22` 只比 major,`22.23` 比到 minor)
|
|
74
|
+
const digits = String(raw)
|
|
75
|
+
.replace(/^v/i, '')
|
|
76
|
+
.split('.')
|
|
77
|
+
.filter((part) => part !== '');
|
|
78
|
+
if (digits.length >= 3) return compareVersion(target, wanted) === 0;
|
|
79
|
+
return digits.every((part, index) => target[index] === wanted[index]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 读目录下已装的版本;读不到就当没装 */
|
|
85
|
+
function safeList(dir) {
|
|
86
|
+
try {
|
|
87
|
+
return fs.readdirSync(dir);
|
|
88
|
+
} catch {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 本机各版本管理器里装好的 Node。
|
|
95
|
+
* 返回 `[{ manager, version, binDir }]`,`binDir` 含 `node` 可执行文件。
|
|
96
|
+
*/
|
|
97
|
+
export function listNodeInstallations() {
|
|
98
|
+
const home = os.homedir();
|
|
99
|
+
const out = [];
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
|
|
102
|
+
const add = (manager, versionsDir, binRel) => {
|
|
103
|
+
for (const name of safeList(versionsDir)) {
|
|
104
|
+
const parsed = parseNodeVersion(name);
|
|
105
|
+
if (!parsed) continue;
|
|
106
|
+
const base = path.join(versionsDir, name);
|
|
107
|
+
// nvm 是 `v22.23.0/bin`;fnm 是 `v22.23.0/installation/bin`;Windows 上可执行文件直接在版本目录
|
|
108
|
+
const candidates = [path.join(base, binRel), base].filter(Boolean);
|
|
109
|
+
const binDir = candidates.find((dir) => {
|
|
110
|
+
try {
|
|
111
|
+
return fs.existsSync(path.join(dir, process.platform === 'win32' ? 'node.exe' : 'node'));
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (!binDir) continue;
|
|
117
|
+
const key = `${binDir}`;
|
|
118
|
+
if (seen.has(key)) continue;
|
|
119
|
+
seen.add(key);
|
|
120
|
+
out.push({ manager, version: parsed.join('.'), binDir });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const nvmRoots = [process.env.NVM_DIR, path.join(home, '.nvm')].filter(Boolean);
|
|
125
|
+
for (const root of nvmRoots) add('nvm', path.join(root, 'versions', 'node'), 'bin');
|
|
126
|
+
|
|
127
|
+
const fnmRoots =
|
|
128
|
+
process.platform === 'darwin'
|
|
129
|
+
? [path.join(home, 'Library', 'Application Support', 'fnm')]
|
|
130
|
+
: process.platform === 'win32'
|
|
131
|
+
? [path.join(process.env.APPDATA ?? '', 'fnm')]
|
|
132
|
+
: [path.join(home, '.local', 'share', 'fnm')];
|
|
133
|
+
for (const root of fnmRoots) {
|
|
134
|
+
if (!root) continue;
|
|
135
|
+
add('fnm', path.join(root, 'node-versions'), path.join('installation', 'bin'));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
add('volta', path.join(home, '.volta', 'tools', 'image', 'node'), 'bin');
|
|
139
|
+
|
|
140
|
+
return out.sort((a, b) => {
|
|
141
|
+
const left = parseNodeVersion(a.version);
|
|
142
|
+
const right = parseNodeVersion(b.version);
|
|
143
|
+
return compareVersion(right, left);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 项目声明的 Node:`.nvmrc` 优先,其次 `.node-version`(fnm / asdf 也认这个),最后 engines */
|
|
148
|
+
export function readNodeRequirement(dir) {
|
|
149
|
+
const root = path.resolve(dir);
|
|
150
|
+
const readFirstLine = (name) => {
|
|
151
|
+
try {
|
|
152
|
+
const first = fs.readFileSync(path.join(root, name), 'utf8').split(/\r?\n/)[0] ?? '';
|
|
153
|
+
return first.trim().replace(/^v/i, '');
|
|
154
|
+
} catch {
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const nvmrc = readFirstLine('.nvmrc');
|
|
159
|
+
const nodeVersion = nvmrc ? '' : readFirstLine('.node-version');
|
|
160
|
+
let engines = '';
|
|
161
|
+
try {
|
|
162
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
163
|
+
engines = String(pkg?.engines?.node ?? '').trim();
|
|
164
|
+
} catch {
|
|
165
|
+
engines = '';
|
|
166
|
+
}
|
|
167
|
+
return { nvmrc, nodeVersion, engines, required: nvmrc || nodeVersion || engines };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 面板用的状态:项目要哪个版本、本机跑的是哪个、哪个已装版本能满足。
|
|
172
|
+
* `matched` 就是跑用例时会用的那个 Node(bin 目录)。
|
|
173
|
+
*/
|
|
174
|
+
export function nodeStatus(dir) {
|
|
175
|
+
const requirement = readNodeRequirement(dir);
|
|
176
|
+
const running = process.versions.node;
|
|
177
|
+
const installations = listNodeInstallations();
|
|
178
|
+
const match = requirement.required
|
|
179
|
+
? (installations.find((item) => satisfiesNode(item.version, requirement.required)) ?? null)
|
|
180
|
+
: null;
|
|
181
|
+
return {
|
|
182
|
+
...requirement,
|
|
183
|
+
running,
|
|
184
|
+
runningSatisfies: requirement.required ? satisfiesNode(running, requirement.required) : true,
|
|
185
|
+
matched: match,
|
|
186
|
+
installations,
|
|
187
|
+
// 装过版本的版本管理器(拿它决定面板上的手动切换命令该怎么写)
|
|
188
|
+
managers: [...new Set(installations.map((item) => item.manager))],
|
|
189
|
+
// 本机装了哪些能装 Node 的版本管理器(nvm / fnm / volta);没装任何版本时 managers 是空的,
|
|
190
|
+
// 但它决定了「能不能一键装」——两者不是一回事,别混着判断
|
|
191
|
+
installers: nodeInstallers().map((item) => item.manager),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** 跑用例时的 PATH 前缀:项目要求的版本装了,就用它,别用面板启动时那个 Node */
|
|
196
|
+
export function projectNodeBinDir(dir) {
|
|
197
|
+
try {
|
|
198
|
+
return nodeStatus(dir).matched?.binDir ?? '';
|
|
199
|
+
} catch {
|
|
200
|
+
return '';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** 给 spawn 的 env 挂上项目 Node(只改 PATH,不动用户其它变量) */
|
|
205
|
+
export function withProjectNode(env, dir) {
|
|
206
|
+
if (!dir) return env;
|
|
207
|
+
const binDir = projectNodeBinDir(dir);
|
|
208
|
+
if (!binDir) return env;
|
|
209
|
+
const current = env.PATH ?? env.Path ?? '';
|
|
210
|
+
const sep = process.platform === 'win32' ? ';' : ':';
|
|
211
|
+
const parts = current ? current.split(sep) : [];
|
|
212
|
+
if (parts[0] === binDir) return env;
|
|
213
|
+
return {
|
|
214
|
+
...env,
|
|
215
|
+
PATH: [binDir, ...parts.filter((part) => part && part !== binDir)].join(sep),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* ────────────────────── 安装缺失版本 ────────────────────── */
|
|
220
|
+
|
|
221
|
+
/** 安装时只接受具体版本(`22` / `22.23.0`):范围没法直接装,得先让人选具体版本 */
|
|
222
|
+
export function concreteNodeVersion(raw) {
|
|
223
|
+
const text = String(raw ?? '')
|
|
224
|
+
.trim()
|
|
225
|
+
.replace(/^[v^~=\s]+/i, '');
|
|
226
|
+
if (!/^\d+(\.\d+){0,2}$/.test(text)) return '';
|
|
227
|
+
return text;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function firstExisting(files) {
|
|
231
|
+
for (const file of files) {
|
|
232
|
+
if (!file) continue;
|
|
233
|
+
try {
|
|
234
|
+
if (fs.existsSync(file)) return file;
|
|
235
|
+
} catch {
|
|
236
|
+
// 没权限就当没有
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 本机装了哪个版本管理器(能装 Node 的那些)。
|
|
244
|
+
* nvm 是 shell 函数而不是可执行文件,只能靠 `nvm.sh` 判断,执行时要在 bash 里 source。
|
|
245
|
+
*/
|
|
246
|
+
export function nodeInstallers(options = {}) {
|
|
247
|
+
const home = options.home ?? os.homedir();
|
|
248
|
+
const env = options.env ?? process.env;
|
|
249
|
+
const found = [];
|
|
250
|
+
|
|
251
|
+
const nvmSh = firstExisting([
|
|
252
|
+
env.NVM_DIR ? path.join(env.NVM_DIR, 'nvm.sh') : '',
|
|
253
|
+
path.join(home, '.nvm', 'nvm.sh'),
|
|
254
|
+
]);
|
|
255
|
+
if (nvmSh) found.push({ manager: 'nvm', kind: 'nvm', nvmSh });
|
|
256
|
+
|
|
257
|
+
const fnm = findExecutable('fnm', { env });
|
|
258
|
+
if (fnm) found.push({ manager: 'fnm', kind: 'bin', bin: fnm });
|
|
259
|
+
|
|
260
|
+
const volta = findExecutable('volta', { env });
|
|
261
|
+
if (volta) found.push({ manager: 'volta', kind: 'bin', bin: volta });
|
|
262
|
+
|
|
263
|
+
return found;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 装一个 Node 版本要执行的命令。
|
|
268
|
+
*
|
|
269
|
+
* 多个管理器都装了时按 nvm → fnm → volta 选:nvm 装出来的版本归 nvm 管,
|
|
270
|
+
* 面板扫描(`listNodeInstallations`)默认也先去 nvm 目录找,装完就能立刻用上。
|
|
271
|
+
*
|
|
272
|
+
* @returns {{ manager: string, command: string, file: string, args: string[] } | { error: string }}
|
|
273
|
+
*/
|
|
274
|
+
export function nodeInstallPlan(version, options = {}) {
|
|
275
|
+
const target = concreteNodeVersion(version);
|
|
276
|
+
if (!target) {
|
|
277
|
+
return { error: '安装需要具体版本号(例如 22.23.0),范围写法请先选定一个版本' };
|
|
278
|
+
}
|
|
279
|
+
const [installer] = nodeInstallers(options);
|
|
280
|
+
if (!installer) {
|
|
281
|
+
return { error: '本机没有 nvm / fnm / volta,先装其中一个版本管理器,或手动安装该 Node 版本' };
|
|
282
|
+
}
|
|
283
|
+
if (installer.kind === 'nvm') {
|
|
284
|
+
// nvm 是函数:必须进 bash 里 source 之后再调用
|
|
285
|
+
return {
|
|
286
|
+
manager: 'nvm',
|
|
287
|
+
command: `nvm install ${target}`,
|
|
288
|
+
file: process.platform === 'win32' ? 'bash.exe' : '/bin/bash',
|
|
289
|
+
args: ['-c', `source "${installer.nvmSh}" && nvm install ${target}`],
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (installer.manager === 'volta') {
|
|
293
|
+
return {
|
|
294
|
+
manager: 'volta',
|
|
295
|
+
command: `volta install node@${target}`,
|
|
296
|
+
file: installer.bin,
|
|
297
|
+
args: ['install', `node@${target}`],
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
manager: 'fnm',
|
|
302
|
+
command: `fnm install ${target}`,
|
|
303
|
+
file: installer.bin,
|
|
304
|
+
args: ['install', target],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** 写 `.nvmrc`:只接受具体版本号(`22` / `22.23.0`),空串表示删掉这个文件 */
|
|
309
|
+
export function writeNvmrc(dir, version) {
|
|
310
|
+
const raw = String(version ?? '')
|
|
311
|
+
.trim()
|
|
312
|
+
.replace(/^v/i, '');
|
|
313
|
+
const file = path.join(path.resolve(dir), '.nvmrc');
|
|
314
|
+
if (!raw) {
|
|
315
|
+
try {
|
|
316
|
+
fs.unlinkSync(file);
|
|
317
|
+
} catch {
|
|
318
|
+
// 本来就没有
|
|
319
|
+
}
|
|
320
|
+
return { version: '', file };
|
|
321
|
+
}
|
|
322
|
+
if (!/^\d+(\.\d+){0,2}$/.test(raw)) {
|
|
323
|
+
throw new Error('Node 版本只能是 22 或 22.23.0 这种写法');
|
|
324
|
+
}
|
|
325
|
+
fs.writeFileSync(file, `${raw}\n`, 'utf8');
|
|
326
|
+
return { version: raw, file };
|
|
327
|
+
}
|