Browse Source

Merge branch 'feature/e2e-frontend-mobile' into cfclub (R416: frontend-mobile live E2E 工具链守卫 + 规范跑法)

E2E Test Bot 2 hours ago
parent
commit
1c4894c5af
3 changed files with 57 additions and 2 deletions
  1. 17 0
      tests/AGENTS.md
  2. 3 0
      tests/package.json
  3. 37 2
      tests/playwright.config.live.js

+ 17 - 0
tests/AGENTS.md

@@ -98,6 +98,23 @@ npx playwright test tests/e2e/mini-games-playwright.spec.js
 # 目前前端测试无法直接运行,需要先配置
 # 目前前端测试无法直接运行,需要先配置
 ```
 ```
 
 
+## Live E2E(frontend-mobile / admin-desktop,R416 规范跑法)
+
+打已部署站点的只读 UI E2E(`e2e-live/*.spec.js` + `playwright.config.live.js`,无 globalSetup、不写业务数据):
+
+```bash
+# 唯一规范跑法:cwd 必须是 tests/(保证 CLI 与 spec 用同一份 @playwright/test)
+cd tests
+npx playwright test -c playwright.config.live.js --project=frontend-mobile   # 或 npm run test:e2e:live:frontend
+npx playwright test -c playwright.config.live.js --project=admin-desktop    # 或 npm run test:e2e:live:admin
+```
+
+- **禁止从仓库根直接 `npx playwright ...`**:根 `package.json`(1.63.0)与 `tests/`(1.61.1)各有一份
+  `@playwright/test` 物理副本,双副本下 `test.describe()` 无法注册 → 假红 `No tests found`
+  (历轮「test.describe 工具链信号」,如 R429 189 节点)。`playwright.config.live.js` 内已加
+  **R416 工具链守卫**:加载配置时自检双副本,命中即 fail-fast 并打印正确跑法,不再出加密报错。
+- R416 实测(2026-11-27,本机,默认 LIVE_BASE_URL=cfc.iwintrue.com):frontend-mobile **6/6 全绿**(50.3s,EXIT=0)。
+
 ## NOTES
 ## NOTES
 
 
 - 测试文件存在但基础设施不完整
 - 测试文件存在但基础设施不完整

+ 3 - 0
tests/package.json

@@ -8,6 +8,9 @@
     "test:e2e": "playwright test",
     "test:e2e": "playwright test",
     "test:e2e:headed": "playwright test --headed",
     "test:e2e:headed": "playwright test --headed",
     "test:e2e:debug": "playwright test --debug",
     "test:e2e:debug": "playwright test --debug",
+    "test:e2e:live": "playwright test -c playwright.config.live.js",
+    "test:e2e:live:frontend": "playwright test e2e-live/frontend-live.spec.js -c playwright.config.live.js --project=frontend-mobile",
+    "test:e2e:live:admin": "playwright test e2e-live/admin-live.spec.js -c playwright.config.live.js --project=admin-desktop",
     "test:flow": "playwright test tests/e2e/*-flow.spec.js",
     "test:flow": "playwright test tests/e2e/*-flow.spec.js",
     "test:all": "npm run test:e2e && npm run test:integration"
     "test:all": "npm run test:e2e && npm run test:integration"
   },
   },

+ 37 - 2
tests/playwright.config.live.js

@@ -9,13 +9,48 @@
  *   - 两个 project 按 spec 分流:admin 走桌面视口,frontend(小程序 H5)走移动视口。
  *   - 两个 project 按 spec 分流:admin 走桌面视口,frontend(小程序 H5)走移动视口。
  *
  *
  * 运行(单节点、串行):
  * 运行(单节点、串行):
- *   npx playwright test -c playwright.config.live.js --project=admin-desktop
- *   npx playwright test -c playwright.config.live.js --project=frontend-mobile
+ *   **cwd 必须是 tests/ 目录**(或走 tests/package.json 的 npm scripts):
+ *   cd tests && npx playwright test -c playwright.config.live.js --project=admin-desktop
+ *   cd tests && npx playwright test -c playwright.config.live.js --project=frontend-mobile
+ *   cd tests && npm run test:e2e:live:frontend
+ *
+ * ⚠️ 工具链双副本(R416 工具链守卫):
+ *   仓库根 D:/cfc/node_modules 自带 @playwright/test(1.63.0,根 package.json),
+ *   与 tests/node_modules(1.61.1)是两份物理副本。从仓库根直接 `npx playwright ...`
+ *   时 CLI 用根副本、spec 的 require('@playwright/test') 落到 tests 副本,两套模块
+ *   状态不共享 → 顶层 test.describe() 抛 "did not expect test.describe() to be called
+ *   here"、runner 报 "No tests found"(即历轮报告里的「test.describe 工具链信号」,
+ *   如 R429 189 节点)。本配置加载时会自检双副本,命中即 fail-fast 并给出正确跑法。
  */
  */
 var path = require('path');
 var path = require('path');
 
 
 var LIVE_BASE = process.env.LIVE_BASE_URL || 'http://cfc.iwintrue.com';
 var LIVE_BASE = process.env.LIVE_BASE_URL || 'http://cfc.iwintrue.com';
 
 
+// ---------------------------------------------------------------------------
+// R416 · @playwright/test 双副本自检(工具链守卫)
+// 比对「进程 cwd 向上解析到的副本」与「本配置(tests/)解析到的副本」,
+// 不一致即说明 CLI 与 spec 各拿一份 @playwright/test → test.describe() 无法
+// 注册、假红 "No tests found"。fail-fast 并给出可执行的正确跑法。
+// ---------------------------------------------------------------------------
+(function assertSinglePlaywrightCopy() {
+  var testsCopy = require.resolve('@playwright/test'); // 配置侧 → tests/node_modules
+  var cwdCopy = testsCopy;
+  try {
+    cwdCopy = require.resolve('@playwright/test', { paths: [process.cwd()] });
+  } catch (e) {
+    // cwd 向上解析不到(如根未装 node_modules)→ 视为单副本,放行
+  }
+  if (path.resolve(cwdCopy) !== path.resolve(testsCopy)) {
+    throw new Error(
+      '[R416 工具链守卫] 检测到 @playwright/test 双物理副本:CLI(cwd=' + process.cwd() + ')→' + cwdCopy +
+      ',tests/→' + testsCopy +
+      '\n  两副本各自持有模块状态,spec 的 test.describe() 无法注册,runner 会假红 "No tests found"。' +
+      '\n  正确跑法:cd tests && npx playwright test -c playwright.config.live.js --project=frontend-mobile' +
+      '\n  或 npm run test:e2e:live:frontend(tests/ 下执行)'
+    );
+  }
+})();
+
 module.exports = {
 module.exports = {
   testDir: path.join(__dirname, 'e2e-live'),
   testDir: path.join(__dirname, 'e2e-live'),
   timeout: 150000,
   timeout: 150000,