test: move test files to lib

This commit is contained in:
DIYgod 2024-02-21 19:46:18 +08:00
parent c713674c35
commit 0d606a06c2
No known key found for this signature in database
6 changed files with 26 additions and 26 deletions

View File

@ -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": [
{

View File

@ -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 () => {

View File

@ -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');
});

View File

@ -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;

View File

@ -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);

View File

@ -68,11 +68,10 @@
},
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.ts"
"**/lib/**/*.test.ts"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/lib/"
"/node_modules/"
]
},
"jest-junit": {