mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-29 01:53:47 +08:00
feat: pkg
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@
|
||||
"unicorn/new-for-builtins": 0,
|
||||
"unicorn/no-array-callback-reference": 0,
|
||||
"unicorn/no-array-reduce": 1,
|
||||
"unicorn/no-await-expression-member": 1,
|
||||
"unicorn/no-await-expression-member": 0,
|
||||
"unicorn/no-empty-file": 1,
|
||||
"unicorn/no-hex-escape": 1,
|
||||
"unicorn/no-null": 0,
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
const config = require('./config');
|
||||
let app;
|
||||
|
||||
module.exports = {
|
||||
init: (conf) => {
|
||||
config.set(
|
||||
Object.assign(
|
||||
{
|
||||
IS_PACKAGE: true,
|
||||
},
|
||||
conf
|
||||
)
|
||||
);
|
||||
app = require('./app');
|
||||
},
|
||||
request: (path) =>
|
||||
new Promise((resolve, reject) => {
|
||||
app.callback()(
|
||||
{
|
||||
url: path,
|
||||
method: 'GET',
|
||||
headers: {},
|
||||
socket: {},
|
||||
},
|
||||
{
|
||||
setHeader: () => {},
|
||||
removeHeader: () => {},
|
||||
end: (data) => {
|
||||
data = JSON.parse(data);
|
||||
if (data.error) {
|
||||
reject(data.error.message);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
}),
|
||||
};
|
||||
@@ -1,19 +1,19 @@
|
||||
jest.mock('request-promise-native');
|
||||
const RSSHub = require('../lib/pkg');
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { init, request } from './pkg';
|
||||
|
||||
describe('pkg', () => {
|
||||
it('config', () => {
|
||||
RSSHub.init({
|
||||
it('config', async () => {
|
||||
await init({
|
||||
UA: 'mock',
|
||||
});
|
||||
const config = require('../lib/config').value;
|
||||
const { config } = await import('./config');
|
||||
expect(config.ua).toBe('mock');
|
||||
});
|
||||
|
||||
it('request', (done) => {
|
||||
RSSHub.request('/test/1').then((data) => {
|
||||
request('/test/1').then((data) => {
|
||||
expect(data).toMatchObject({
|
||||
atomlink: 'http:///test/1',
|
||||
atomlink: 'http://localhost/test/1',
|
||||
title: 'Test 1',
|
||||
itunes_author: null,
|
||||
link: 'https://github.com/DIYgod/RSSHub',
|
||||
@@ -61,7 +61,7 @@ describe('pkg', () => {
|
||||
});
|
||||
|
||||
it('error', (done) => {
|
||||
RSSHub.request('/test/error')
|
||||
request('/test/error')
|
||||
.then(() => {
|
||||
done();
|
||||
})
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { setConfig } from '@/config';
|
||||
import { Hono } from 'hono';
|
||||
|
||||
let app: Hono;
|
||||
|
||||
export const init = async (conf) => {
|
||||
setConfig(
|
||||
Object.assign(
|
||||
{
|
||||
IS_PACKAGE: true,
|
||||
},
|
||||
conf
|
||||
)
|
||||
);
|
||||
app = (await import('@/app')).default;
|
||||
};
|
||||
|
||||
export const request = async (path) => {
|
||||
const res = await app.request(path);
|
||||
return res.json();
|
||||
};
|
||||
Reference in New Issue
Block a user