From cb8b24ae86b3cc50d50718d116e90b82ca958796 Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 30 Nov 2024 10:28:35 +0800 Subject: [PATCH] fix: test --- .npmrc | 1 + lib/routes/index.js | 3 +-- package.json | 20 +++++++++++++++++++ packages/rss-libs/package.json | 6 +----- .../test/middleware/access-control.js | 6 +++--- .../rss-libs/test/middleware/anti-hotlink.js | 6 +++--- packages/rss-libs/test/middleware/debug.js | 2 +- packages/rss-libs/test/middleware/header.js | 2 +- packages/rss-libs/test/middleware/onerror.js | 2 +- .../rss-libs/test/middleware/parameter.js | 2 +- packages/rss-libs/test/middleware/template.js | 2 +- packages/rss-libs/test/router.js | 2 +- 12 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.npmrc b/.npmrc index cc15a2b86fc7fb..4d68220d81f798 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,4 @@ audit = false omit-lockfile-registry-resolved = true fund = false +workspaces = true diff --git a/lib/routes/index.js b/lib/routes/index.js index 4276740bc50992..0e8094ce6e2a8c 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -1,6 +1,5 @@ const config = require("rss-libs/config").value; const art = require("art-template"); -const path = require("path"); const v8 = require("v8"); const os = require("os"); @@ -69,7 +68,7 @@ module.exports = async (ctx) => { const { disallowRobot } = config; const { total_heap_size } = v8.getHeapStatistics(); - ctx.body = art(path.resolve(__dirname, "../views/welcome.art"), { + ctx.body = art(require.resolve("rss-libs/views/welcome.art"), { showDebug, disallowRobot, debug: [ diff --git a/package.json b/package.json index 8c0a9710563d47..d9d8a2e8c3bdd6 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,26 @@ "overrides": { "uglify-js": "^3.17.4" }, + "jest": { + "testTimeout": 45000, + "testMatch": [ + "**/test/**/*.js" + ], + "testPathIgnorePatterns": [ + "/node_modules/", + "/lib/" + ], + "coverageReporters": [ + "text-summary", + "lcov" + ], + "collectCoverageFrom": [ + "lib/**/*.js", + "!lib/routes/**/*.js", + "!lib/customize/**/*.js" + ], + "testEnvironment": "node" + }, "workspaces": [ "packages/rss-libs" ] diff --git a/packages/rss-libs/package.json b/packages/rss-libs/package.json index 255497c93e5971..d27533e96d65e3 100644 --- a/packages/rss-libs/package.json +++ b/packages/rss-libs/package.json @@ -26,10 +26,6 @@ "!lib/routes/**/*.js", "!lib/customize/**/*.js" ], - "bail": true, - "testEnvironment": "node", - "moduleNameMapper": { - "@/(.*)": "/lib/$1" - } + "testEnvironment": "node" } } diff --git a/packages/rss-libs/test/middleware/access-control.js b/packages/rss-libs/test/middleware/access-control.js index ec2a33d7b6321c..1195f0ed2deb4e 100644 --- a/packages/rss-libs/test/middleware/access-control.js +++ b/packages/rss-libs/test/middleware/access-control.js @@ -21,7 +21,7 @@ describe("access-control", () => { const code = md5("/test/2" + key); process.env.BLACKLIST = "/test/1,233.233.233.233"; process.env.ACCESS_KEY = key; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response11 = await request.get("/test/1"); @@ -75,7 +75,7 @@ describe("access-control", () => { const code = md5("/test/2" + key); process.env.WHITELIST = "/test/1,233.233.233.233"; process.env.ACCESS_KEY = key; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response01 = await request.get("/"); @@ -130,7 +130,7 @@ describe("access-control", () => { const key = "1L0veRSSHub"; const code = md5("/test/2" + key); process.env.ACCESS_KEY = key; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response01 = await request.get("/"); diff --git a/packages/rss-libs/test/middleware/anti-hotlink.js b/packages/rss-libs/test/middleware/anti-hotlink.js index 0e14ead814e766..efc275349f7fb5 100644 --- a/packages/rss-libs/test/middleware/anti-hotlink.js +++ b/packages/rss-libs/test/middleware/anti-hotlink.js @@ -16,7 +16,7 @@ afterEach(() => { describe("anti-hotlink", () => { it("template", async () => { process.env.HOTLINK_TEMPLATE = "https://i3.wp.com/${host}${pathname}"; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response = await request.get("/test/complicated"); @@ -26,7 +26,7 @@ describe("anti-hotlink", () => { }); it("url", async () => { process.env.HOTLINK_TEMPLATE = "${protocol}//${host}${pathname}"; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response = await request.get("/test/complicated"); @@ -36,7 +36,7 @@ describe("anti-hotlink", () => { }); it("no-template", async () => { process.env.HOTLINK_TEMPLATE = ""; - server = require("../../index"); + server = require("../../../../lib/index"); const request = supertest(server); const response = await request.get("/test/complicated"); diff --git a/packages/rss-libs/test/middleware/debug.js b/packages/rss-libs/test/middleware/debug.js index 5a59b6deb9f9ad..f723e11f15dce3 100644 --- a/packages/rss-libs/test/middleware/debug.js +++ b/packages/rss-libs/test/middleware/debug.js @@ -2,7 +2,7 @@ process.env.NODE_NAME = "mock"; const supertest = require("supertest"); -const server = require("../../index"); +const server = require("../../../../lib/index"); const request = supertest(server); const cheerio = require("cheerio"); diff --git a/packages/rss-libs/test/middleware/header.js b/packages/rss-libs/test/middleware/header.js index 406ef5e93f6a35..816f890c029397 100644 --- a/packages/rss-libs/test/middleware/header.js +++ b/packages/rss-libs/test/middleware/header.js @@ -1,7 +1,7 @@ process.env.NODE_NAME = "mock"; const supertest = require("supertest"); -const server = require("../../index"); +const server = require("../../../../lib/index"); const request = supertest(server); const config = require("../../config").value; let etag; diff --git a/packages/rss-libs/test/middleware/onerror.js b/packages/rss-libs/test/middleware/onerror.js index 014b7171116b6a..de190b7dc5a191 100644 --- a/packages/rss-libs/test/middleware/onerror.js +++ b/packages/rss-libs/test/middleware/onerror.js @@ -1,7 +1,7 @@ process.env.SENTRY = "https://mock@mock.com/1"; const supertest = require("supertest"); -const server = require("../../index"); +const server = require("../../../../lib/index"); const request = supertest(server); afterAll(() => { diff --git a/packages/rss-libs/test/middleware/parameter.js b/packages/rss-libs/test/middleware/parameter.js index 2cee5363c90acf..5855d729259e4d 100644 --- a/packages/rss-libs/test/middleware/parameter.js +++ b/packages/rss-libs/test/middleware/parameter.js @@ -1,5 +1,5 @@ const supertest = require("supertest"); -const server = require("../../index"); +const server = require("../../../../lib/index"); const request = supertest(server); const Parser = require("rss-parser"); const parser = new Parser(); diff --git a/packages/rss-libs/test/middleware/template.js b/packages/rss-libs/test/middleware/template.js index bc15244ed017a9..5d6c724a68b347 100644 --- a/packages/rss-libs/test/middleware/template.js +++ b/packages/rss-libs/test/middleware/template.js @@ -1,5 +1,5 @@ const supertest = require("supertest"); -const server = require("../../index"); +const server = require("../../../../lib/index"); const request = supertest(server); const Parser = require("rss-parser"); const parser = new Parser(); diff --git a/packages/rss-libs/test/router.js b/packages/rss-libs/test/router.js index a328c3b6bbd40e..27bf982c8f796c 100644 --- a/packages/rss-libs/test/router.js +++ b/packages/rss-libs/test/router.js @@ -1,7 +1,7 @@ process.env.SOCKET = "socket"; const supertest = require("supertest"); -const server = require("../index"); +const server = require("../../../lib/index"); const request = supertest(server); const Parser = require("rss-parser"); const parser = new Parser();