mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 15:05:55 +08:00
chore(tests): migrate to dayjs for generating timestamp
This commit is contained in:
parent
09344cfb44
commit
baba0c389c
@ -3,62 +3,63 @@ import getStep, { DefaultStepSize } from 'lib/getStep';
|
|||||||
|
|
||||||
describe('lib/getStep', () => {
|
describe('lib/getStep', () => {
|
||||||
test('should return default step when the given range is less than 1 day', () => {
|
test('should return default step when the given range is less than 1 day', () => {
|
||||||
const start = new Date('2022-01-01T00:00:00.000Z').getTime();
|
const start = dayjs();
|
||||||
const end = new Date('2022-01-01T12:00:00.000Z').getTime();
|
const end = start.add(1, 'hour');
|
||||||
|
const startUnix = start.valueOf();
|
||||||
|
const endUnix = end.valueOf();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start / 1e3,
|
start: startUnix / 1e3,
|
||||||
end: end / 1e3,
|
end: endUnix / 1e3,
|
||||||
inputFormat: 's',
|
inputFormat: 's',
|
||||||
}),
|
}),
|
||||||
).toEqual(DefaultStepSize);
|
).toEqual(DefaultStepSize);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start,
|
start: startUnix,
|
||||||
end: end,
|
end: endUnix,
|
||||||
inputFormat: 'ms',
|
inputFormat: 'ms',
|
||||||
}),
|
}),
|
||||||
).toEqual(DefaultStepSize);
|
).toEqual(DefaultStepSize);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start * 1e6,
|
start: startUnix * 1e6,
|
||||||
end: end * 1e6,
|
end: endUnix * 1e6,
|
||||||
inputFormat: 'ns',
|
inputFormat: 'ns',
|
||||||
}),
|
}),
|
||||||
).toEqual(DefaultStepSize);
|
).toEqual(DefaultStepSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return relevant step when the given range is greater than 1 day', () => {
|
test('should return relevant step when the given range is greater than 1 day', () => {
|
||||||
const startISOString = '2022-01-01T00:00:00.000Z';
|
const start = dayjs();
|
||||||
const endISOString = '2022-01-10T00:00:00.000Z';
|
const end = start.add(1, 'Day').add(1, 'Second');
|
||||||
const start = new Date(startISOString).getTime();
|
const startUnix = start.valueOf();
|
||||||
const end = new Date(endISOString).getTime();
|
const endUnix = end.valueOf();
|
||||||
|
|
||||||
const expectedStepSize =
|
const expectedStepSize = end.diff(start, 'days') * DefaultStepSize;
|
||||||
dayjs(endISOString).diff(dayjs(startISOString), 'days') * DefaultStepSize;
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start / 1e3,
|
start: startUnix / 1e3,
|
||||||
end: end / 1e3,
|
end: endUnix / 1e3,
|
||||||
inputFormat: 's',
|
inputFormat: 's',
|
||||||
}),
|
}),
|
||||||
).toEqual(expectedStepSize);
|
).toEqual(expectedStepSize);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start,
|
start: startUnix,
|
||||||
end: end,
|
end: endUnix,
|
||||||
inputFormat: 'ms',
|
inputFormat: 'ms',
|
||||||
}),
|
}),
|
||||||
).toEqual(expectedStepSize);
|
).toEqual(expectedStepSize);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getStep({
|
getStep({
|
||||||
start: start * 1e6,
|
start: startUnix * 1e6,
|
||||||
end: end * 1e6,
|
end: endUnix * 1e6,
|
||||||
inputFormat: 'ns',
|
inputFormat: 'ns',
|
||||||
}),
|
}),
|
||||||
).toEqual(expectedStepSize);
|
).toEqual(expectedStepSize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user