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}`); + } + } +});