test: config
This commit is contained in:
parent
33ec0fbbb4
commit
04647e122b
|
|
@ -254,6 +254,8 @@ export type Config = {
|
|||
twitter: {
|
||||
oauthTokens?: string[];
|
||||
oauthTokenSecrets?: string[];
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
weibo: {
|
||||
app_key?: string;
|
||||
|
|
@ -288,7 +290,7 @@ export type Config = {
|
|||
};
|
||||
};
|
||||
|
||||
let _value: Config | undefined;
|
||||
const value: Config | Record<string, any> = {};
|
||||
|
||||
const TRUE_UA = 'RSSHub/1.0 (+http://github.com/DIYgod/RSSHub; like FeedFetcher-Google)';
|
||||
|
||||
|
|
@ -328,7 +330,7 @@ const calculateValue = () => {
|
|||
}
|
||||
}
|
||||
|
||||
_value = {
|
||||
const _value = {
|
||||
// app config
|
||||
disallowRobot: envs.DISALLOW_ROBOT !== '0' && envs.DISALLOW_ROBOT !== 'false',
|
||||
enableCluster: envs.ENABLE_CLUSTER,
|
||||
|
|
@ -627,6 +629,10 @@ const calculateValue = () => {
|
|||
cookie: envs.ZODGAME_COOKIE,
|
||||
},
|
||||
};
|
||||
|
||||
for (const name in _value) {
|
||||
value[name] = _value[name];
|
||||
}
|
||||
};
|
||||
calculateValue();
|
||||
|
||||
|
|
@ -645,7 +651,8 @@ if (envs.REMOTE_CONFIG) {
|
|||
});
|
||||
}
|
||||
|
||||
export const config: Config = _value!;
|
||||
// @ts-expect-error value is set
|
||||
export const config: Config = value;
|
||||
|
||||
export const setConfig = (env: Partial<Config>) => {
|
||||
envs = Object.assign(process.env, env);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
const nock = require('nock');
|
||||
import { describe, expect, it, afterEach, jest } from '@jest/globals';
|
||||
import nock from 'nock';
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
describe('config', () => {
|
||||
it('bilibilib cookie', () => {
|
||||
it('bilibilib cookie', async () => {
|
||||
process.env.BILIBILI_COOKIE_12 = 'cookie1';
|
||||
process.env.BILIBILI_COOKIE_34 = 'cookie2';
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.bilibili.cookies).toMatchObject({
|
||||
12: 'cookie1',
|
||||
34: 'cookie2',
|
||||
|
|
@ -19,11 +20,11 @@ describe('config', () => {
|
|||
delete process.env.BILIBILI_COOKIE_34;
|
||||
});
|
||||
|
||||
it('email config', () => {
|
||||
it('email config', async () => {
|
||||
process.env['EMAIL_CONFIG_xx.qq.com'] = 'token1';
|
||||
process.env['EMAIL_CONFIG_oo.qq.com'] = 'token2';
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.email.config).toMatchObject({
|
||||
'xx.qq.com': 'token1',
|
||||
'oo.qq.com': 'token2',
|
||||
|
|
@ -33,11 +34,11 @@ describe('config', () => {
|
|||
delete process.env['EMAIL_CONFIG_oo.qq.com'];
|
||||
});
|
||||
|
||||
it('discuz cookie', () => {
|
||||
it('discuz cookie', async () => {
|
||||
process.env.DISCUZ_COOKIE_12 = 'cookie1';
|
||||
process.env.DISCUZ_COOKIE_34 = 'cookie2';
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.discuz.cookies).toMatchObject({
|
||||
12: 'cookie1',
|
||||
34: 'cookie2',
|
||||
|
|
@ -47,11 +48,11 @@ describe('config', () => {
|
|||
delete process.env.DISCUZ_COOKIE_34;
|
||||
});
|
||||
|
||||
it('medium cookie', () => {
|
||||
it('medium cookie', async () => {
|
||||
process.env.MEDIUM_COOKIE_12 = 'cookie1';
|
||||
process.env.MEDIUM_COOKIE_34 = 'cookie2';
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.medium.cookies).toMatchObject({
|
||||
12: 'cookie1',
|
||||
34: 'cookie2',
|
||||
|
|
@ -61,11 +62,11 @@ describe('config', () => {
|
|||
delete process.env.MEDIUM_COOKIE_34;
|
||||
});
|
||||
|
||||
it('discourse config', () => {
|
||||
it('discourse config', async () => {
|
||||
process.env.DISCOURSE_CONFIG_12 = JSON.stringify({ a: 1 });
|
||||
process.env.DISCOURSE_CONFIG_34 = JSON.stringify({ b: 2 });
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.discourse.config).toMatchObject({
|
||||
12: { a: 1 },
|
||||
34: { b: 2 },
|
||||
|
|
@ -75,17 +76,17 @@ describe('config', () => {
|
|||
delete process.env.DISCOURSE_CONFIG_34;
|
||||
});
|
||||
|
||||
it('no random ua', () => {
|
||||
process.env.NO_RANDOM_UA = true;
|
||||
it('no random ua', async () => {
|
||||
process.env.NO_RANDOM_UA = '1';
|
||||
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/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', () => {
|
||||
const config = require('../lib/config').value;
|
||||
it('random ua', async () => {
|
||||
const { config } = await import('../lib/config');
|
||||
expect(config.ua).not.toBe('RSSHub/1.0 (+http://github.com/DIYgod/RSSHub; like FeedFetcher-Google)');
|
||||
});
|
||||
|
||||
|
|
@ -97,9 +98,8 @@ describe('config', () => {
|
|||
.reply(200, {
|
||||
UA: 'test',
|
||||
});
|
||||
let config = require('../lib/config').value;
|
||||
const { config } = await import('../lib/config');
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
config = require('../lib/config').value;
|
||||
expect(config.ua).toBe('test');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue