diff --git a/.eslintrc.json b/.eslintrc.json index 16ddfe359..cc67ae087 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -116,7 +116,8 @@ "yml/quotes": ["error", { "prefer": "single" }], "@typescript-eslint/no-var-requires": 0, "@typescript-eslint/no-explicit-any": 0, - "n/no-missing-import": 0 + "n/no-missing-import": 0, + "n/no-unpublished-import": 0 }, "overrides": [ { diff --git a/test/app.ts b/lib/app.test.ts similarity index 90% rename from test/app.ts rename to lib/app.test.ts index 9c04db336..095e69de4 100644 --- a/test/app.ts +++ b/lib/app.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals'; -import app from '../lib/app'; +import app from './app'; describe('index', () => { it('serve index', async () => { diff --git a/test/config.ts b/lib/config.test.ts similarity index 85% rename from test/config.ts rename to lib/config.test.ts index b3c82aaba..76b0eacc0 100644 --- a/test/config.ts +++ b/lib/config.test.ts @@ -10,7 +10,7 @@ describe('config', () => { process.env.BILIBILI_COOKIE_12 = 'cookie1'; process.env.BILIBILI_COOKIE_34 = 'cookie2'; - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.bilibili.cookies).toMatchObject({ 12: 'cookie1', 34: 'cookie2', @@ -24,7 +24,7 @@ describe('config', () => { process.env['EMAIL_CONFIG_xx.qq.com'] = 'token1'; process.env['EMAIL_CONFIG_oo.qq.com'] = 'token2'; - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.email.config).toMatchObject({ 'xx.qq.com': 'token1', 'oo.qq.com': 'token2', @@ -38,7 +38,7 @@ describe('config', () => { process.env.DISCUZ_COOKIE_12 = 'cookie1'; process.env.DISCUZ_COOKIE_34 = 'cookie2'; - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.discuz.cookies).toMatchObject({ 12: 'cookie1', 34: 'cookie2', @@ -52,7 +52,7 @@ describe('config', () => { process.env.MEDIUM_COOKIE_12 = 'cookie1'; process.env.MEDIUM_COOKIE_34 = 'cookie2'; - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.medium.cookies).toMatchObject({ 12: 'cookie1', 34: 'cookie2', @@ -66,7 +66,7 @@ describe('config', () => { process.env.DISCOURSE_CONFIG_12 = JSON.stringify({ a: 1 }); process.env.DISCOURSE_CONFIG_34 = JSON.stringify({ b: 2 }); - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.discourse.config).toMatchObject({ 12: { a: 1 }, 34: { b: 2 }, @@ -79,14 +79,14 @@ describe('config', () => { it('no random ua', async () => { process.env.NO_RANDOM_UA = '1'; - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.ua).toBe('RSSHub/1.0 (+http://github.com/DIYgod/RSSHub; like FeedFetcher-Google)'); delete process.env.NO_RANDOM_UA; }); it('random ua', async () => { - const { config } = await import('../lib/config'); + const { config } = await import('./config'); expect(config.ua).not.toBe('RSSHub/1.0 (+http://github.com/DIYgod/RSSHub; like FeedFetcher-Google)'); }); @@ -98,7 +98,7 @@ describe('config', () => { .reply(200, { UA: 'test', }); - const { config } = await import('../lib/config'); + const { config } = await import('./config'); await new Promise((resolve) => setTimeout(resolve, 100)); expect(config.ua).toBe('test'); }); diff --git a/test/router.ts b/lib/router.test.ts similarity index 97% rename from test/router.ts rename to lib/router.test.ts index 62f5de168..944aab0b2 100644 --- a/test/router.ts +++ b/lib/router.test.ts @@ -2,10 +2,10 @@ import { describe, expect, it, afterAll, jest } from '@jest/globals'; process.env.SOCKET = 'socket'; jest.mock('request-promise-native'); -import app from '../lib/app'; +import app from './app'; import Parser from 'rss-parser'; const parser = new Parser(); -import { config } from '../lib/config'; +import { config } from './config'; afterAll(() => { delete process.env.SOCKET; diff --git a/test/utils/puppeteer.ts b/lib/utils/puppeteer.test.ts similarity index 86% rename from test/utils/puppeteer.ts rename to lib/utils/puppeteer.test.ts index f1bed0590..951de0a7c 100644 --- a/test/utils/puppeteer.ts +++ b/lib/utils/puppeteer.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, jest, afterEach } from '@jest/globals'; -import wait from '../../lib/utils/wait'; +import wait from './wait'; import { type Browser } from 'puppeteer'; let browser: Browser | null = null; @@ -23,7 +23,7 @@ afterEach(() => { describe('puppeteer', () => { it('puppeteer run', async () => { - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); const startTime = Date.now(); const page = await browser.newPage(); @@ -45,7 +45,7 @@ describe('puppeteer', () => { if (!process.env.GITHUB_ACTIONS) { it('puppeteer without stealth', async () => { - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer({ stealth: false }); const page = await browser.newPage(); await page.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle0' }); @@ -58,7 +58,7 @@ describe('puppeteer', () => { }, 15000); it('puppeteer with stealth', async () => { - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer({ stealth: true }); const page = await browser.newPage(); await page.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle0' }); @@ -73,7 +73,7 @@ describe('puppeteer', () => { it('puppeteer accept http proxy uri w/ auth', async () => { process.env.PROXY_URI = 'http://user:pass@rsshub.proxy:2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); // trailing slash will cause net::ERR_NO_SUPPORTED_PROXIES, prohibit it @@ -83,7 +83,7 @@ describe('puppeteer', () => { it('puppeteer reject https proxy uri w/ auth', async () => { process.env.PROXY_URI = 'https://user:pass@rsshub.proxy:2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => arg.includes('--proxy-server'))).toBe(false); @@ -92,7 +92,7 @@ describe('puppeteer', () => { it('puppeteer reject socks proxy uri w/ auth', async () => { process.env.PROXY_URI = 'socks5://user:pass@rsshub.proxy:2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => arg.includes('--proxy-server'))).toBe(false); @@ -103,7 +103,7 @@ describe('puppeteer', () => { process.env.PROXY_HOST = 'rsshub.proxy'; process.env.PROXY_PORT = '2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => /^--proxy-server=http:\/\/rsshub.proxy:2333$/.test(arg))).toBe(true); @@ -114,7 +114,7 @@ describe('puppeteer', () => { process.env.PROXY_HOST = 'rsshub.proxy'; process.env.PROXY_PORT = '2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => /^--proxy-server=https:\/\/rsshub.proxy:2333$/.test(arg))).toBe(true); @@ -125,7 +125,7 @@ describe('puppeteer', () => { process.env.PROXY_HOST = 'rsshub.proxy'; process.env.PROXY_PORT = '2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => /^--proxy-server=socks4:\/\/rsshub.proxy:2333$/.test(arg))).toBe(true); @@ -136,7 +136,7 @@ describe('puppeteer', () => { process.env.PROXY_HOST = 'rsshub.proxy'; process.env.PROXY_PORT = '2333'; - const { default: puppeteer } = await import('../../lib/utils/puppeteer'); + const { default: puppeteer } = await import('./puppeteer'); browser = await puppeteer(); expect(browser.process()?.spawnargs.some((arg) => /^--proxy-server=socks5:\/\/rsshub.proxy:2333$/.test(arg))).toBe(true); diff --git a/package.json b/package.json index 5c764dba1..e865d231e 100644 --- a/package.json +++ b/package.json @@ -68,11 +68,10 @@ }, "testEnvironment": "node", "testMatch": [ - "**/test/**/*.ts" + "**/lib/**/*.test.ts" ], "testPathIgnorePatterns": [ - "/node_modules/", - "/lib/" + "/node_modules/" ] }, "jest-junit": {