Skip to content

Commit d265bd1

Browse files
committed
ci: debug
1 parent ec64fc8 commit d265bd1

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

test/date.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ test('.formatDate', () => {
2222
expect(formatDate('2020-01-01 00:00:00', 'yyyy-M-d')).toBe('2020-1-1');
2323
expect(formatDate('2020-12-12 00:00:00', 'YYYY-M-D')).toBe('2020-12-12');
2424
expect(formatDate('2020-01-01 00:00:00')).toBe('2020-01-01 00:00:00');
25-
// expect(formatDate(1587953430135)).toBe('2020-04-27 10:10:30');
26-
27-
// expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss SSS')).toBe('2020-11-07 12:12:25 684');
28-
// expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss SS')).toBe('2020-11-07 12:12:25 684');
29-
// expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss S')).toBe('2020-11-07 12:12:25 684');
30-
// expect(formatDate(1604722345068, 'YYYY-MM-DD HH:mm:ss SS')).toBe('2020-11-07 12:12:25 68');
31-
// expect(formatDate(1604722345006, 'YYYY-MM-DD HH:mm:ss S')).toBe('2020-11-07 12:12:25 6');
32-
// expect(formatDate(1699771222238, 'YYYY/MM/DD HH:mm:ss ww')).toBe('2023/11/12 14:40:22 周日');
25+
// 因有时区问题,仅在中国境内执行
26+
if (Intl.DateTimeFormat().resolvedOptions().timeZone === 'Asia/Shanghai') {
27+
expect(formatDate(1587953430135)).toBe('2020-04-27 10:10:30');
28+
29+
expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss SSS')).toBe('2020-11-07 12:12:25 684');
30+
expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss SS')).toBe('2020-11-07 12:12:25 684');
31+
expect(formatDate(1604722345684, 'YYYY-MM-DD HH:mm:ss S')).toBe('2020-11-07 12:12:25 684');
32+
expect(formatDate(1604722345068, 'YYYY-MM-DD HH:mm:ss SS')).toBe('2020-11-07 12:12:25 68');
33+
expect(formatDate(1604722345006, 'YYYY-MM-DD HH:mm:ss S')).toBe('2020-11-07 12:12:25 6');
34+
expect(formatDate(1699771222238, 'YYYY/MM/DD HH:mm:ss ww')).toBe('2023/11/12 14:40:22 周日');
35+
}
3336

3437
expect(formatDate(new Date('2020-01-01 00:00:00'), 'YYYY-M-D')).toBe('2020-1-1');
3538
});

test/qs.test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@ test('qsParse', () => {
99
expect(qsParse('a=1&a=2&b=1')).toEqual({ a: ['1', '2'], b: '1' });
1010
expect(qsParse('a=1&a=2&a=3&a=4')).toEqual({ a: ['1', '2', '3', '4'] });
1111
});
12+
// 因有时区问题,仅在中国境内执行
13+
if (Intl.DateTimeFormat().resolvedOptions().timeZone === 'Asia/Shanghai') {
14+
test('qsStringify 默认 replacer', () => {
15+
const i = new Date(2020, 0, 1, 0, 0, 0, 0);
16+
const query = { a: 1, b: [2, 3], c: '4', d: undefined, e: null, f: true, g: false, i };
17+
const string = 'a=1&b=2&b=3&c=4&f=true&g=false&i=2019-12-31T16%3A00%3A00.000Z';
18+
expect(qsStringify(query)).toBe(string);
19+
});
1220

13-
test('qsStringify 默认 replacer', () => {
14-
const i = new Date(2020, 0, 1, 0, 0, 0, 0);
15-
const query = { a: 1, b: [2, 3], c: '4', d: undefined, e: null, f: true, g: false, i };
16-
const string = 'a=1&b=2&b=3&c=4&f=true&g=false&i=2019-12-31T16%3A00%3A00.000Z';
17-
expect(qsStringify(query)).toBe(string);
18-
});
19-
20-
test('qsStringify 复写 replacer', () => {
21-
const replacer: Replacer = value => {
22-
if (isString(value)) return `string-${value}`;
23-
if (isNumber(value)) return `number-${value}`;
24-
if (isBoolean(value)) return `boolean-${value ? 'true' : 'false'}`;
25-
if (isUndefined(value)) return 'undefined';
26-
if (isNull(value)) return 'null';
27-
if (isDate(value)) return 'date-' + formatDate(new Date(value), 'YYYY-MM-DD HH:mm:ss');
28-
return null;
29-
};
30-
const i = new Date(2020, 0, 1, 0, 0, 0, 0);
31-
const query = { a: 1, b: [2, 3], c: '4', d: undefined, e: null, f: true, g: false, i };
32-
const string =
33-
'a=number-1&b=number-2&b=number-3&c=string-4&d=undefined&e=null&' +
34-
'f=boolean-true&g=boolean-false&i=date-2020-01-01+00%3A00%3A00';
35-
expect(qsStringify(query, replacer)).toBe(string);
36-
});
21+
test('qsStringify 复写 replacer', () => {
22+
const replacer: Replacer = value => {
23+
if (isString(value)) return `string-${value}`;
24+
if (isNumber(value)) return `number-${value}`;
25+
if (isBoolean(value)) return `boolean-${value ? 'true' : 'false'}`;
26+
if (isUndefined(value)) return 'undefined';
27+
if (isNull(value)) return 'null';
28+
if (isDate(value)) return 'date-' + formatDate(new Date(value), 'YYYY-MM-DD HH:mm:ss');
29+
return null;
30+
};
31+
const i = new Date(2020, 0, 1, 0, 0, 0, 0);
32+
const query = { a: 1, b: [2, 3], c: '4', d: undefined, e: null, f: true, g: false, i };
33+
const string =
34+
'a=number-1&b=number-2&b=number-3&c=string-4&d=undefined&e=null&' +
35+
'f=boolean-true&g=boolean-false&i=date-2020-01-01+00%3A00%3A00';
36+
expect(qsStringify(query, replacer)).toBe(string);
37+
});
38+
}

0 commit comments

Comments
 (0)