From 3f8ae81a1474232b94ffee74399f08d06c4be283 Mon Sep 17 00:00:00 2001 From: lofyer Date: Wed, 5 Aug 2026 20:01:33 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E9=9B=86=E6=88=90=E5=A4=B9=E5=85=B7?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=90=86=E6=94=B9=E4=B8=BA=E8=AF=BB=20HTTPS?= =?UTF-8?q?=5FPROXY=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=86=99=E6=AD=BB=E6=9C=AC?= =?UTF-8?q?=E6=9C=BA=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_test/electron/ai-scope.integration.js | 4 +++- src/_test/electron/annotation.integration.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/_test/electron/ai-scope.integration.js b/src/_test/electron/ai-scope.integration.js index 9306553..c7c5c35 100644 --- a/src/_test/electron/ai-scope.integration.js +++ b/src/_test/electron/ai-scope.integration.js @@ -75,8 +75,10 @@ app.whenReady().then(async () => { fs.mkdirSync(path.dirname(epubPath), { recursive: true }); if (!fs.existsSync(epubPath)) { const { fetch: uf, ProxyAgent } = require('undici'); + // 代理只在设了 HTTPS_PROXY 时用,写死本机代理会让 CI 直接 ECONNREFUSED + const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || ''; const r = await uf('https://www.gutenberg.org/ebooks/11.epub.noimages', { - dispatcher: new ProxyAgent({ uri: 'http://127.0.0.1:7890', connectTimeout: 30000 }) + dispatcher: proxy ? new ProxyAgent({ uri: proxy, connectTimeout: 30000 }) : undefined }); fs.writeFileSync(epubPath, Buffer.from(await r.arrayBuffer())); } diff --git a/src/_test/electron/annotation.integration.js b/src/_test/electron/annotation.integration.js index a0d810b..574476f 100644 --- a/src/_test/electron/annotation.integration.js +++ b/src/_test/electron/annotation.integration.js @@ -18,12 +18,15 @@ async function wait(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } +// 代理只在设了 HTTPS_PROXY 时用。写死本机代理会让没有代理的环境(CI) +// 直接 ECONNREFUSED,取不到夹具。 async function ensurePdf() { if (fs.existsSync(PDF_CACHE)) return; fs.mkdirSync(path.dirname(PDF_CACHE), { recursive: true }); const { fetch, ProxyAgent } = require('undici'); + const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || ''; const response = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', { - dispatcher: new ProxyAgent({ uri: 'http://127.0.0.1:7890', connectTimeout: 30000 }) + dispatcher: proxy ? new ProxyAgent({ uri: proxy, connectTimeout: 30000 }) : undefined }); if (!response.ok) throw new Error(`PDF 下载失败:${response.status}`); fs.writeFileSync(PDF_CACHE, Buffer.from(await response.arrayBuffer()));