From 91d53ffec0224eb8e6f2c2204b3a8352e511e8c9 Mon Sep 17 00:00:00 2001 From: hopechen067 <59017045+hopechen067@users.noreply.github.com> Date: Fri, 2 Oct 2026 02:44:12 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=96=E9=93=BE?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E8=BD=AC=E4=B9=89=E9=94=99=E8=AF=AF=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=B8=BB=E8=BF=9B=E7=A8=8B=E6=97=A0=E6=B3=95=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=EF=BC=8C=E5=8A=A0=E6=BA=90=E6=96=87=E4=BB=B6=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E6=A3=80=E6=9F=A5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/main/main.js | 2 +- test/syntax.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/syntax.test.js diff --git a/src/main/main.js b/src/main/main.js index 41d51cc..2d53394 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -54,7 +54,7 @@ function warn(message) { // 页面里的外链(如"申请 Key")一律交给系统浏览器,不在应用内开窗口 function guardNavigation(win) { win.webContents.setWindowOpenHandler(({ url }) => { - if (/^https?:///i.test(url)) shell.openExternal(url); + if (/^https?:\/\//i.test(url)) shell.openExternal(url); return { action: 'deny' }; }); win.webContents.on('will-navigate', (event) => event.preventDefault()); diff --git a/test/syntax.test.js b/test/syntax.test.js new file mode 100644 index 0000000..be26b6a --- /dev/null +++ b/test/syntax.test.js @@ -0,0 +1,28 @@ +'use strict'; + +// 主进程依赖 Electron,单元测试 require 不到;至少保证每个源文件都能被解析。 +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('fs'); +const path = require('path'); +const { execFileSync } = require('child_process'); + +function jsFiles(dir) { + return fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => { + const p = path.join(dir, e.name); + if (e.isDirectory()) return jsFiles(p); + return e.name.endsWith('.js') ? [p] : []; + }); +} + +test('src 下所有 JS 文件语法正确', () => { + const files = jsFiles(path.join(__dirname, '..', 'src')); + assert.ok(files.length > 10); + for (const f of files) { + try { + execFileSync(process.execPath, ['--check', f], { stdio: 'pipe' }); + } catch (err) { + assert.fail(`${path.relative(process.cwd(), f)}\n${err.stderr}`); + } + } +});