test: common-config

This commit is contained in:
DIYgod
2024-02-25 00:55:51 +08:00
parent 31140d0b59
commit 1a8160a224
4 changed files with 14 additions and 22 deletions
@@ -1,11 +1,11 @@
/* eslint-disable unicorn/consistent-function-scoping */
const configUtils = require('../../lib/utils/common-config');
const nock = require('nock');
import { describe, expect, it } from '@jest/globals';
import configUtils, { transElemText, replaceParams, getProp } from '@/utils/common-config';
import nock from 'nock';
describe('index', () => {
it('transElemText', () => {
const $ = () => 'RSSHub';
expect(configUtils.transElemText($, '$()')).toBe('RSSHub');
expect(transElemText($, '$()')).toBe('RSSHub');
});
it('replaceParams', () => {
@@ -16,7 +16,7 @@ describe('index', () => {
},
title: '%title%',
};
expect(configUtils.replaceParams(data, data.title, $)).toBe('RSSHub');
expect(replaceParams(data, data.title, $)).toBe('RSSHub');
});
it('getProp', () => {
@@ -24,8 +24,8 @@ describe('index', () => {
const data = {
title: 'RSSHub',
};
expect(configUtils.getProp(data, ['title'], $)).toBe('RSSHub');
expect(configUtils.getProp(data, 'title', $)).toBe('RSSHub');
expect(getProp(data, ['title'], $)).toBe('RSSHub');
expect(getProp(data, 'title', $)).toBe('RSSHub');
});
it('all', () => {
@@ -36,7 +36,7 @@ describe('index', () => {
},
title: '%title%',
};
expect(configUtils.getProp(data, ['title'], $)).toBe('RSSHub');
expect(getProp(data, ['title'], $)).toBe('RSSHub');
});
it('buildData', async () => {
@@ -1,12 +1,6 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const iconv = require('iconv-lite');
// eslint-disable-next-line no-unused-vars
const date = require('@/utils/date');
// eslint-disable-next-line no-unused-vars
const { parseDate } = require('@/utils/parse-date');
// eslint-disable-next-line no-unused-vars
const timezone = require('@/utils/timezone');
import cheerio from 'cheerio';
import got from '@/utils/got';
import iconv from 'iconv-lite';
function transElemText($, prop) {
const regex = /\$\((.*)\)/g;
@@ -76,7 +70,5 @@ async function buildData(data) {
};
}
module.exports = buildData;
module.exports.transElemText = transElemText;
module.exports.replaceParams = replaceParams;
module.exports.getProp = getProp;
export default buildData;
export { transElemText, replaceParams, getProp };
+1 -1
View File
@@ -1,7 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { decodeCFEmail } = require('@/utils/cf-email');
const { decodeCFEmail } = require('./cf-email');
module.exports = async (ctx) => {
const id = ctx.params.id;