Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore(tests): migrate to dayjs for generating timestamp

Pranshu Chittorababa0c389cc2
diff --git a/frontend/src/lib/__tests__/getStep.test.ts b/frontend/src/lib/__tests__/getStep.test.ts
index 1939f14957..638c21cf4e 100644
--- a/frontend/src/lib/__tests__/getStep.test.ts
+++ b/frontend/src/lib/__tests__/getStep.test.ts
@@ -3,62 +3,63 @@ import getStep, { DefaultStepSize } from 'lib/getStep';
describe('lib/getStep', () => {
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 end = new Date('2022-01-01T12:00:00.000Z').getTime();
+ const start = dayjs();
+ const end = start.add(1, 'hour');
+ const startUnix = start.valueOf();
+ const endUnix = end.valueOf();
expect(
getStep({
- start: start / 1e3,
- end: end / 1e3,
+ start: startUnix / 1e3,
+ end: endUnix / 1e3,
inputFormat: 's',
}),
).toEqual(DefaultStepSize);
expect(
getStep({
- start: start,
- end: end,
+ start: startUnix,
+ end: endUnix,
inputFormat: 'ms',
}),
).toEqual(DefaultStepSize);
expect(
getStep({
- start: start * 1e6,
- end: end * 1e6,
+ start: startUnix * 1e6,
+ end: endUnix * 1e6,
inputFormat: 'ns',
}),
).toEqual(DefaultStepSize);
});
test('should return relevant step when the given range is greater than 1 day', () => {
- const startISOString = '2022-01-01T00:00:00.000Z';
- const endISOString = '2022-01-10T00:00:00.000Z';
- const start = new Date(startISOString).getTime();
- const end = new Date(endISOString).getTime();
+ const start = dayjs();
+ const end = start.add(1, 'Day').add(1, 'Second');
+ const startUnix = start.valueOf();
+ const endUnix = end.valueOf();
- const expectedStepSize =
- dayjs(endISOString).diff(dayjs(startISOString), 'days') * DefaultStepSize;
+ const expectedStepSize = end.diff(start, 'days') * DefaultStepSize;
expect(
getStep({
- start: start / 1e3,
- end: end / 1e3,
+ start: startUnix / 1e3,
+ end: endUnix / 1e3,
inputFormat: 's',
}),
).toEqual(expectedStepSize);
expect(
getStep({
- start: start,
- end: end,
+ start: startUnix,
+ end: endUnix,
inputFormat: 'ms',
}),
).toEqual(expectedStepSize);
expect(
getStep({
- start: start * 1e6,
- end: end * 1e6,
+ start: startUnix * 1e6,
+ end: endUnix * 1e6,
inputFormat: 'ns',
}),
).toEqual(expectedStepSize);