Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/test/components/TrackBandwidth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('TrackBandwidth', function () {
screen.getByText('Transfer speed for this sample:')
).toBeInTheDocument();
expect(screen.getByText(/speed/).nextSibling).toHaveTextContent(
'4.66GB\u2069 per second'
'5.00GB\u2069 per second'
);

expect(
Expand All @@ -176,14 +176,14 @@ describe('TrackBandwidth', function () {
screen.getByText('Data transferred up to this time:')
).toBeInTheDocument();
expect(screen.getByText(/transferred up to/).nextSibling).toHaveTextContent(
/6.86MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
/7.19MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
);

expect(
screen.getByText('Data transferred in the visible range:')
).toBeInTheDocument();
expect(screen.getByText(/visible range/).nextSibling).toHaveTextContent(
/7.97MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
/8.35MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
);
});

Expand Down Expand Up @@ -224,13 +224,13 @@ describe('TrackBandwidth', function () {
moveMouseAtCounter(3, 0);
// Note: Fluent adds isolation characters \u2068 and \u2069 around variables.
expect(screen.getByText(/speed/).nextSibling).toHaveTextContent(
'95.4MB\u2069 per second'
'100MB\u2069 per second'
);
expect(screen.getByText(/visible range:/).nextSibling).toHaveTextContent(
/7.97MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
/8.35MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/
);
expect(
screen.getByText(/current selection:/).nextSibling
).toHaveTextContent(/4.77MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/);
).toHaveTextContent(/5.00MB\u2069 \(\u2068\d+(\.\d+)?\u2069 g CO₂e\)/);
});
});
22 changes: 11 additions & 11 deletions src/test/components/__snapshots__/TooltipMarker.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ exports[`TooltipMarker renders properly network markers where content type is bl
Requested bytes
:
</div>
45.9KB
47.0KB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -538,7 +538,7 @@ exports[`TooltipMarker renders properly network markers where content type is mi
Requested bytes
:
</div>
45.9KB
47.0KB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -744,7 +744,7 @@ exports[`TooltipMarker renders properly network markers with a preconnect part 2
Requested bytes
:
</div>
45.9KB
47.0KB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -1014,7 +1014,7 @@ exports[`TooltipMarker renders properly network markers with a preconnect part c
Requested bytes
:
</div>
45.9KB
47.0KB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -1210,7 +1210,7 @@ exports[`TooltipMarker renders properly normal network markers 1`] = `
Requested bytes
:
</div>
45.9KB
47.0KB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -3216,14 +3216,14 @@ exports[`TooltipMarker renders tooltips for various markers: GCMajor-16.5 1`] =
GC heap size (pre - post)
:
</div>
46.1MB - 36.3MB
48.4MB - 38.1MB
<div
class="tooltipLabel"
>
Malloc heap size (pre - post)
:
</div>
23.1MB - 12.1MB
24.2MB - 12.7MB
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -3362,7 +3362,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
Bytes tenured
:
</div>
1.30MB / 1.97MB (66%)
1.37MB / 2.06MB (66%)
<div
class="tooltipLabel"
>
Expand All @@ -3376,7 +3376,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
Bytes used
:
</div>
1.97MB / 16.0MB (12%)
2.06MB / 16.8MB (12%)
<div
class="tooltipLabel"
>
Expand All @@ -3397,7 +3397,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCMinor-15.5 1`] =
Tenured allocation rate
:
</div>
181MB/s
190MB/s
<div
class="tooltipLabel"
>
Expand Down Expand Up @@ -3501,7 +3501,7 @@ exports[`TooltipMarker renders tooltips for various markers: GCSlice-17.5 1`] =
Trigger (amt/trig)
:
</div>
266MB / 245MB
279MB / 257MB
<div
class="tooltipLabel"
>
Expand Down
77 changes: 45 additions & 32 deletions src/test/unit/format-numbers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ describe('formatGigaBytes', () => {
});

it('returns large values without fractional digits by default', () => {
expect(formatGigaBytes(1234567890123)).toBe('1,150GB');
expect(formatGigaBytes(1234567890123)).toBe('1,235GB');
});

it('returns values with 2 fractional digits by default', () => {
expect(formatGigaBytes(1234567890)).toBe('1.15GB');
expect(formatGigaBytes(1234567890)).toBe('1.23GB');
});

it('can return values with byte precision', () => {
expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe('1GB 153MB 384KB 722B');
expect(formatGigaBytes(1234567890, 3, 2, 1)).toBe('1GB 234MB 567KB 890B');
});

it('can return values with kilobyte precision', () => {
expect(formatGigaBytes(1234567890, 3, 2, 1024)).toBe('1GB 153MB 385KB');
expect(formatGigaBytes(1234567890, 3, 2, 1000)).toBe('1GB 234MB 568KB');
});

it('can return values with megabyte precision', () => {
expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 2)).toBe('1GB 153MB');
expect(formatGigaBytes(1234567890, 3, 2, 1000 ** 2)).toBe('1GB 235MB');
});

it('can return values with gigabyte precision', () => {
expect(formatGigaBytes(1234567890, 3, 2, 1024 ** 3)).toBe('1GB');
expect(formatGigaBytes(1234567890, 3, 2, 1000 ** 3)).toBe('1GB');
});
});

Expand All @@ -58,23 +58,23 @@ describe('formatMegaBytes', () => {
});

it('returns large values without fractional digits by default', () => {
expect(formatMegaBytes(1234567890)).toBe('1,177MB');
expect(formatMegaBytes(1234567890)).toBe('1,235MB');
});

it('returns values with 2 fractional digits by default', () => {
expect(formatMegaBytes(1234567)).toBe('1.18MB');
expect(formatMegaBytes(1234567)).toBe('1.23MB');
});

it('can return values with byte precision', () => {
expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1MB 181KB 647B');
expect(formatMegaBytes(1234567, 3, 2, 1)).toBe('1MB 234KB 567B');
});

it('can return values with kilobyte precision', () => {
expect(formatMegaBytes(1234567, 3, 2, 1024)).toBe('1MB 182KB');
expect(formatMegaBytes(1234567, 3, 2, 1000)).toBe('1MB 235KB');
});

it('can return values with megabyte precision', () => {
expect(formatMegaBytes(1234567, 3, 2, 1024 ** 2)).toBe('1MB');
expect(formatMegaBytes(1234567, 3, 2, 1000 ** 2)).toBe('1MB');
});
});

Expand All @@ -84,19 +84,19 @@ describe('formatKiloBytes', () => {
});

it('returns large values without fractional digits by default', () => {
expect(formatKiloBytes(1234567)).toBe('1,206KB');
expect(formatKiloBytes(1234567)).toBe('1,235KB');
});

it('returns values with 2 fractional digits by default', () => {
expect(formatKiloBytes(1234)).toBe('1.21KB');
expect(formatKiloBytes(1234)).toBe('1.23KB');
});

it('can return values with byte precision', () => {
expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1KB 210B');
expect(formatKiloBytes(1234, 3, 2, 1)).toBe('1KB 234B');
});

it('can return values with kilobyte precision', () => {
expect(formatKiloBytes(1234, 3, 2, 1024)).toBe('1KB');
expect(formatKiloBytes(1234, 3, 2, 1000)).toBe('1KB');
});
});

Expand All @@ -110,40 +110,53 @@ describe('formatBytes', () => {
});

it('can return values with the kilobyte unit', () => {
expect(formatBytes(12345)).toBe('12.1KB');
expect(formatBytes(12345)).toBe('12.3KB');
});

it('can return values with the megabyte unit', () => {
expect(formatBytes(1234567)).toBe('1.18MB');
expect(formatBytes(1234567)).toBe('1.23MB');
});

it('can return values with the gigabyte unit', () => {
expect(formatBytes(1234567890)).toBe('1.15GB');
expect(formatBytes(1234567890)).toBe('1.23GB');
});

it('can return values with byte precision', () => {
expect(formatBytes(12345, 3, 2, 1)).toBe('12KB 57B');
expect(formatBytes(12345, 3, 2, 1)).toBe('12KB 345B');
});

it('can return values with kilobyte precision', () => {
expect(formatBytes(12345, 3, 2, 1024)).toBe('12KB');
expect(formatBytes(12345, 3, 2, 1000)).toBe('12KB');
});
});

describe('findRoundBytesValueGreaterOrEqualTo', () => {
const expectedValues = [0, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000];

it('rounds small bytes values using base 10 round value', () => {
const expectedValues = [
// minValue, expected
// minValue <= 1000
[0, 0],
[3, 5],
[63, 100],
[511, 1000],
[1000, 2000],

// 1000 < minValue <= 1000^4
[2047, 4000],
[9999, 16000],
[123456, 128000],
[999999, 1000000],
[1_234_567, 2_000_000],
[1_234_567_891, 2_000_000_000],

// minValue > 1000^4
[1_234_567_891_234, 2_000_000_000_000],
[1_234_567_891_234_567, 2_000_000_000_000_000],
];

it('correctly rounds bytes values using base 10 round value', () => {
for (let i = 0; i < expectedValues.length; ++i) {
expect(findRoundBytesValueGreaterOrEqualTo(2 ** i - 1)).toBe(
expectedValues[i]
);
}
});

it('rounds large bytes values using base 2 round value', () => {
for (let i = expectedValues.length; i < 40; ++i) {
expect(findRoundBytesValueGreaterOrEqualTo(2 ** i - 1)).toBe(2 ** i);
const [input, expected] = expectedValues[i];
expect(findRoundBytesValueGreaterOrEqualTo(input)).toBe(expected);
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/test/unit/marker-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ describe('marker schema formatting', function () {
"bytes - 0B",
"bytes - 10B",
"bytes - 12B",
"bytes - 121KB",
"bytes - 118MB",
"bytes - 115GB",
"bytes - 123KB",
"bytes - 123MB",
"bytes - 123GB",
"bytes - 0.000B",
"integer - 0",
"integer - 10",
Expand Down
14 changes: 7 additions & 7 deletions src/utils/format-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function formatGigaBytes(
maxFractionalDigits: number = 2,
precision: number = Infinity
): string {
const bytesPerGigabyte = 1024 ** 3;
const bytesPerGigabyte = 1000 ** 3;
if (precision === Infinity) {
return (
formatNumber(
Expand Down Expand Up @@ -210,7 +210,7 @@ export function formatMegaBytes(
maxFractionalDigits: number = 2,
precision: number = Infinity
): string {
const bytesPerMegabyte = 1024 ** 2;
const bytesPerMegabyte = 1000 ** 2;
if (precision === Infinity) {
return (
formatNumber(
Expand Down Expand Up @@ -240,7 +240,7 @@ export function formatKiloBytes(
maxFractionalDigits: number = 2,
precision: number = Infinity
): string {
const bytesPerKilobyte = 1024;
const bytesPerKilobyte = 1000;
if (precision === Infinity) {
return (
formatNumber(
Expand Down Expand Up @@ -274,14 +274,14 @@ export function formatBytes(
// Use singles up to 10,000. I think 9,360B looks nicer than 9.36KB.
// We use "0" for significantDigits because bytes will always be integers.
return formatNumber(bytes, 0) + 'B';
} else if (bytes < 1024 ** 2) {
} else if (bytes < 1000 ** 2) {
return formatKiloBytes(
bytes,
significantDigits,
maxFractionalDigits,
precision
);
} else if (bytes < 1024 ** 3) {
} else if (bytes < 1000 ** 3) {
return formatMegaBytes(
bytes,
significantDigits,
Expand Down Expand Up @@ -542,10 +542,10 @@ function _findRoundValueGreaterOrEqualTo(minValue: number): number {

export function findRoundBytesValueGreaterOrEqualTo(minValue: number): number {
// Special case KB, MB, GB.
if (minValue > 1024 && minValue <= 1024 ** 4) {
if (minValue > 1000 && minValue <= 1000 ** 4) {
for (const power of [1, 2, 3]) {
for (const value of [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) {
const number = value * 1024 ** power;
const number = value * 1000 ** power;
if (minValue <= number) {
return number;
}
Expand Down