mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-28 03:28:35 +08:00
refactor: avoid promise overhead (#8028)
This commit is contained in:
@@ -2,12 +2,12 @@ const configUtils = require('../../lib/utils/common-config');
|
||||
const nock = require('nock');
|
||||
|
||||
describe('index', () => {
|
||||
it('transElemText', async () => {
|
||||
it('transElemText', () => {
|
||||
const $ = () => 'RSSHub';
|
||||
expect(configUtils.transElemText($, '$()')).toBe('RSSHub');
|
||||
});
|
||||
|
||||
it('replaceParams', async () => {
|
||||
it('replaceParams', () => {
|
||||
const $ = () => 'RSSHub';
|
||||
const data = {
|
||||
params: {
|
||||
@@ -18,7 +18,7 @@ describe('index', () => {
|
||||
expect(configUtils.replaceParams(data, data.title, $)).toBe('RSSHub');
|
||||
});
|
||||
|
||||
it('getProp', async () => {
|
||||
it('getProp', () => {
|
||||
const $ = () => 'RSSHub';
|
||||
const data = {
|
||||
title: 'RSSHub',
|
||||
@@ -27,7 +27,7 @@ describe('index', () => {
|
||||
expect(configUtils.getProp(data, 'title', $)).toBe('RSSHub');
|
||||
});
|
||||
|
||||
it('all', async () => {
|
||||
it('all', () => {
|
||||
const $ = () => 'RSSHub';
|
||||
const data = {
|
||||
params: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const utils = require('../../lib/utils/common-utils');
|
||||
|
||||
describe('common-utils', () => {
|
||||
it('toTitleCase', async () => {
|
||||
it('toTitleCase', () => {
|
||||
expect(utils.toTitleCase('RSSHub IS AS aweSOme aS henry')).toBe('Rsshub Is As Awesome As Henry');
|
||||
});
|
||||
});
|
||||
|
||||
+24
-24
@@ -6,102 +6,102 @@ describe('date', () => {
|
||||
|
||||
const date = new Date();
|
||||
|
||||
it('m分钟前', async () => {
|
||||
it('m分钟前', () => {
|
||||
expect(+new Date(parseDate('10分钟前'))).toBe(+date - 10 * 60 * 1000);
|
||||
});
|
||||
|
||||
it('H小时前', async () => {
|
||||
it('H小时前', () => {
|
||||
expect(+new Date(parseDate('10小时前'))).toBe(+date - 10 * 60 * 60 * 1000);
|
||||
});
|
||||
|
||||
it('D天前', async () => {
|
||||
it('D天前', () => {
|
||||
expect(+new Date(parseDate('10天前'))).toBe(+date - 10 * 24 * 60 * 60 * 1000);
|
||||
});
|
||||
|
||||
it('M月前', async () => {
|
||||
it('M月前', () => {
|
||||
expect(+new Date(parseDate('1月前'))).toBe(+date - 1 * 31 * 24 * 60 * 60 * 1000);
|
||||
});
|
||||
|
||||
it('Y年前', async () => {
|
||||
it('Y年前', () => {
|
||||
expect(+new Date(parseDate('1年前'))).toBe(+date - 1 * 365 * 24 * 60 * 60 * 1000);
|
||||
});
|
||||
|
||||
it('今天 H:m', async () => {
|
||||
it('今天 H:m', () => {
|
||||
expect(+new Date(parseDate('今天 08:00'))).toBe(+new Date('2019-1-1 08:00'));
|
||||
});
|
||||
|
||||
it('昨天 H:m', async () => {
|
||||
it('昨天 H:m', () => {
|
||||
expect(+new Date(parseDate('昨天 20:00'))).toBe(+new Date('2018-12-31 20:00'));
|
||||
});
|
||||
|
||||
it('前天 H:m', async () => {
|
||||
it('前天 H:m', () => {
|
||||
expect(+new Date(parseDate('前天 20:00'))).toBe(+new Date('2018-12-30 20:00'));
|
||||
});
|
||||
|
||||
it('Y年M月D日H时', async () => {
|
||||
it('Y年M月D日H时', () => {
|
||||
expect(+new Date(parseDate('2018年4月2日1时'))).toBe(+new Date('2018-4-2 01:00'));
|
||||
});
|
||||
|
||||
it('Y年M月D日', async () => {
|
||||
it('Y年M月D日', () => {
|
||||
expect(+new Date(parseDate('2018年4月2日'))).toBe(+new Date('2018-4-2 00:00'));
|
||||
});
|
||||
|
||||
it('Y-M-D H:m', async () => {
|
||||
it('Y-M-D H:m', () => {
|
||||
expect(+new Date(parseDate('2018-4-2 02:03'))).toBe(+new Date('2018-4-2 02:03'));
|
||||
});
|
||||
|
||||
it('M-D H:m', async () => {
|
||||
it('M-D H:m', () => {
|
||||
expect(+new Date(parseDate('2-3 02:03'))).toBe(+new Date('2019-2-3 02:03'));
|
||||
});
|
||||
|
||||
it('Y/M/D H:m:s', async () => {
|
||||
it('Y/M/D H:m:s', () => {
|
||||
expect(+new Date(parseDate('2018/4/2 02:03:04'))).toBe(+new Date('2018-4-2 02:03:04'));
|
||||
});
|
||||
|
||||
it('Y/M/D H:m', async () => {
|
||||
it('Y/M/D H:m', () => {
|
||||
expect(+new Date(parseDate('2018/4/2 02:03'))).toBe(+new Date('2018-4-2 02:03'));
|
||||
});
|
||||
|
||||
it('M/D H:m', async () => {
|
||||
it('M/D H:m', () => {
|
||||
expect(+new Date(parseDate('2/3 02:03'))).toBe(+new Date('2019-2-3 02:03'));
|
||||
});
|
||||
|
||||
it('M月D日 H:m', async () => {
|
||||
it('M月D日 H:m', () => {
|
||||
expect(+new Date(parseDate('2月3日 02:03'))).toBe(+new Date('2019-2-3 02:03'));
|
||||
});
|
||||
|
||||
it('M月D日', async () => {
|
||||
it('M月D日', () => {
|
||||
expect(+new Date(parseDate('2月3日'))).toBe(+new Date('2019-2-3 00:00'));
|
||||
});
|
||||
|
||||
it('M月D号', async () => {
|
||||
it('M月D号', () => {
|
||||
expect(+new Date(parseDate('2月3号'))).toBe(+new Date('2019-2-3 00:00'));
|
||||
});
|
||||
|
||||
it('M/D', async () => {
|
||||
it('M/D', () => {
|
||||
expect(+new Date(parseDate('2/3'))).toBe(+new Date('2019-2-3 00:00'));
|
||||
});
|
||||
|
||||
it('Y-M-D', async () => {
|
||||
it('Y-M-D', () => {
|
||||
expect(+new Date(parseDate('2018-4-2'))).toBe(+new Date('2018-4-2'));
|
||||
});
|
||||
|
||||
it('M-D', async () => {
|
||||
it('M-D', () => {
|
||||
expect(+new Date(parseDate('4-2'))).toBe(+new Date('2019-4-2'));
|
||||
});
|
||||
|
||||
it('H:m', async () => {
|
||||
it('H:m', () => {
|
||||
expect(+new Date(parseDate('4:2'))).toBe(+new Date('2019-1-1 04:02'));
|
||||
});
|
||||
|
||||
it('刚刚', async () => {
|
||||
it('刚刚', () => {
|
||||
const result = +new Date(parseDate('刚刚'));
|
||||
const now = +new Date();
|
||||
expect(result - now).toBeLessThan(10);
|
||||
expect(result - now).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('Invalid', async () => {
|
||||
it('Invalid', () => {
|
||||
expect(parseDate('RSSHub')).toBe('RSSHub');
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
const md5 = require('../../lib/utils/md5');
|
||||
|
||||
describe('md5', () => {
|
||||
it('md5 RSSHub', async () => {
|
||||
it('md5 RSSHub', () => {
|
||||
expect(md5('RSSHub')).toBe('3187d745ec5983413e4f0dce3900d92d');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user