Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed Nov 30, 2024
1 parent eb219ac commit cb8b24a
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
audit = false
omit-lockfile-registry-resolved = true
fund = false
workspaces = true
3 changes: 1 addition & 2 deletions lib/routes/index.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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: [
Expand Down
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
6 changes: 1 addition & 5 deletions packages/rss-libs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
"!lib/routes/**/*.js",
"!lib/customize/**/*.js"
],
"bail": true,
"testEnvironment": "node",
"moduleNameMapper": {
"@/(.*)": "<rootDir>/lib/$1"
}
"testEnvironment": "node"
}
}
6 changes: 3 additions & 3 deletions packages/rss-libs/test/middleware/access-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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("/");
Expand Down Expand Up @@ -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("/");
Expand Down
6 changes: 3 additions & 3 deletions packages/rss-libs/test/middleware/anti-hotlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/middleware/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/middleware/header.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/middleware/onerror.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.SENTRY = "https://[email protected]/1";

const supertest = require("supertest");
const server = require("../../index");
const server = require("../../../../lib/index");
const request = supertest(server);

afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/middleware/parameter.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/middleware/template.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/rss-libs/test/router.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit cb8b24a

Please sign in to comment.