工程化:增加package.json、Prettier与ESLint配置,修复测试连接未关闭导致挂起

- 新账系统/package.json:仅开发依赖(prettier、eslint、@eslint/js、globals),运行时仍零依赖
- Prettier 只处理 .js/.mjs/.cjs/.css;ESLint 扁平配置区分后端、浏览器脚本、测试与 e2e
- scripts/gen-browser-globals.js 生成浏览器脚本间共享的全局变量清单
- 测试 after 钩子关闭服务前先 closeAllConnections(),避免未读完的响应让 server.close() 永久等待
- 4 处读取源码文本的测试断言改为不依赖空白写法(格式化前后均通过),断言含义不变

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
黄健铭andClaude Opus 5.5 committed 2026-12-04 08:55:46 -08:00
1 parent 91479fd13f
commit 3743d687e7
59 files changed
+2625 -57

No files matched your search

@@ -77,7 +77,7 @@ test('售后HTTP预览和批次列表要求登录及成员权限,写入保留C
const directory=fs.mkdtempSync(path.join(os.tmpdir(),'maimai-order-after-sale-http-')),l=new Ledger(path.join(directory,'ledger.sqlite'));
createUser(l,'麦麦','owner','synthetic-owner-password','owner');createUser(l,'娜娜','assistant','synthetic-assistant-password','assistant');createUser(l,'小昊','assistant','synthetic-assistant2-password','assistant2');
const app=createApp({mode:'trial',port:0,dataDir:directory,ledger:l,feishuConfig:{enabled:false}});await new Promise(resolve=>app.server.listen(0,'127.0.0.1',resolve));
t.after(async()=>{await new Promise(resolve=>app.server.close(resolve));l.close();fs.rmSync(directory,{recursive:true,force:true});});
t.after(async()=>{await new Promise(resolve=>{app.server.closeAllConnections();app.server.close(resolve);});l.close();fs.rmSync(directory,{recursive:true,force:true});});
const base='http://127.0.0.1:'+app.server.address().port,cookies={};
const call=(who,route,body,key=randomUUID(),extra={})=>fetch(base+route,{method:body===undefined?'GET':'POST',headers:{...(cookies[who]?{Cookie:cookies[who]}:{}),...(body===undefined?{}:{'Content-Type':'application/json','X-Requested-With':'maimai-ledger',Origin:base,...(key?{'Idempotency-Key':key}:{})}),...extra},...(body===undefined?{}:{body:JSON.stringify(body)})});
for(const [who,name,password] of [['owner','麦麦','synthetic-owner-password'],['assistant','娜娜','synthetic-assistant-password'],['assistant2','小昊','synthetic-assistant2-password']]){const login=await call(who,'/api/login',{name,password});assert.equal(login.status,200);cookies[who]=login.headers.get('set-cookie').split(';')[0];}