React 18 and Vite (#4510)
This commit is contained in:
parent
1bb1b13f6d
commit
21613fa602
244 changed files with 4547 additions and 8933 deletions
|
@ -1,17 +1,19 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { bytesToString, ip, mbToBytes } from '@/lib/formatters';
|
||||
|
||||
describe('@/lib/formatters.ts', function () {
|
||||
describe('mbToBytes()', function () {
|
||||
it('should convert from MB to Bytes', function () {
|
||||
expect(mbToBytes(1)).toBe(1_048_576);
|
||||
expect(mbToBytes(0)).toBe(0);
|
||||
expect(mbToBytes(0.1)).toBe(104_857);
|
||||
expect(mbToBytes(0.001)).toBe(1_048);
|
||||
expect(mbToBytes(1024)).toBe(1_073_741_824);
|
||||
describe('@/lib/formatters.ts', () => {
|
||||
describe('mbToBytes()', () => {
|
||||
it('should convert from MB to Bytes', () => {
|
||||
expect(mbToBytes(1)).equals(1_048_576);
|
||||
expect(mbToBytes(0)).equals(0);
|
||||
expect(mbToBytes(0.1)).equals(104_857);
|
||||
expect(mbToBytes(0.001)).equals(1_048);
|
||||
expect(mbToBytes(1024)).equals(1_073_741_824);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bytesToString()', function () {
|
||||
describe('bytesToString()', () => {
|
||||
it.each([
|
||||
[0, '0 Bytes'],
|
||||
[0.5, '0 Bytes'],
|
||||
|
@ -38,24 +40,24 @@ describe('@/lib/formatters.ts', function () {
|
|||
[1_000_000_000_000, '931.32 GiB'],
|
||||
[1_099_511_627_776, '1 TiB'],
|
||||
])('should format %d bytes as "%s"', function (input, output) {
|
||||
expect(bytesToString(input)).toBe(output);
|
||||
expect(bytesToString(input)).equals(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ip()', function () {
|
||||
it('should format an IPv4 address', function () {
|
||||
expect(ip('127.0.0.1')).toBe('127.0.0.1');
|
||||
describe('ip()', () => {
|
||||
it('should format an IPv4 address', () => {
|
||||
expect(ip('127.0.0.1')).equals('127.0.0.1');
|
||||
});
|
||||
|
||||
it('should format an IPv6 address', function () {
|
||||
expect(ip(':::1')).toBe('[:::1]');
|
||||
expect(ip('2001:db8::')).toBe('[2001:db8::]');
|
||||
it('should format an IPv6 address', () => {
|
||||
expect(ip(':::1')).equals('[:::1]');
|
||||
expect(ip('2001:db8::')).equals('[2001:db8::]');
|
||||
});
|
||||
|
||||
it('should handle random inputs', function () {
|
||||
expect(ip('1')).toBe('1');
|
||||
expect(ip('foobar')).toBe('foobar');
|
||||
expect(ip('127.0.0.1:25565')).toBe('[127.0.0.1:25565]');
|
||||
it('should handle random inputs', () => {
|
||||
expect(ip('1')).equals('1');
|
||||
expect(ip('foobar')).equals('foobar');
|
||||
expect(ip('127.0.0.1:25565')).equals('[127.0.0.1:25565]');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { hexToRgba } from '@/lib/helpers';
|
||||
|
||||
describe('@/lib/helpers.ts', function () {
|
||||
describe('hexToRgba()', function () {
|
||||
it('should return the expected rgba', function () {
|
||||
expect(hexToRgba('#ffffff')).toBe('rgba(255, 255, 255, 1)');
|
||||
expect(hexToRgba('#00aabb')).toBe('rgba(0, 170, 187, 1)');
|
||||
expect(hexToRgba('#efefef')).toBe('rgba(239, 239, 239, 1)');
|
||||
describe('@/lib/helpers.ts', () => {
|
||||
describe('hexToRgba()', () => {
|
||||
it('should return the expected rgba', () => {
|
||||
expect(hexToRgba('#ffffff')).equals('rgba(255, 255, 255, 1)');
|
||||
expect(hexToRgba('#00aabb')).equals('rgba(0, 170, 187, 1)');
|
||||
expect(hexToRgba('#efefef')).equals('rgba(239, 239, 239, 1)');
|
||||
});
|
||||
|
||||
it('should ignore case', function () {
|
||||
expect(hexToRgba('#FF00A3')).toBe('rgba(255, 0, 163, 1)');
|
||||
it('should ignore case', () => {
|
||||
expect(hexToRgba('#FF00A3')).equals('rgba(255, 0, 163, 1)');
|
||||
});
|
||||
|
||||
it('should allow alpha channel changes', function () {
|
||||
expect(hexToRgba('#ece5a8', 0.5)).toBe('rgba(236, 229, 168, 0.5)');
|
||||
expect(hexToRgba('#ece5a8', 0.1)).toBe('rgba(236, 229, 168, 0.1)');
|
||||
expect(hexToRgba('#000000', 0)).toBe('rgba(0, 0, 0, 0)');
|
||||
it('should allow alpha channel changes', () => {
|
||||
expect(hexToRgba('#ece5a8', 0.5)).equals('rgba(236, 229, 168, 0.5)');
|
||||
expect(hexToRgba('#ece5a8', 0.1)).equals('rgba(236, 229, 168, 0.1)');
|
||||
expect(hexToRgba('#000000', 0)).equals('rgba(0, 0, 0, 0)');
|
||||
});
|
||||
|
||||
it('should handle invalid strings', function () {
|
||||
expect(hexToRgba('')).toBe('');
|
||||
expect(hexToRgba('foobar')).toBe('foobar');
|
||||
expect(hexToRgba('#fff')).toBe('#fff');
|
||||
expect(hexToRgba('#')).toBe('#');
|
||||
expect(hexToRgba('#fffffy')).toBe('#fffffy');
|
||||
it('should handle invalid strings', () => {
|
||||
expect(hexToRgba('')).equals('');
|
||||
expect(hexToRgba('foobar')).equals('foobar');
|
||||
expect(hexToRgba('#fff')).equals('#fff');
|
||||
expect(hexToRgba('#')).equals('#');
|
||||
expect(hexToRgba('#fffffy')).equals('#fffffy');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ function hexToRgba(hex: string, alpha = 1): string {
|
|||
}
|
||||
|
||||
// noinspection RegExpSimplifiable
|
||||
const [r, g, b] = hex.match(/[a-fA-F0-9]{2}/g)!.map((v) => parseInt(v, 16));
|
||||
const [r, g, b] = hex.match(/[a-fA-F0-9]{2}/g)!.map(v => parseInt(v, 16));
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { isObject } from '@/lib/objects';
|
||||
|
||||
describe('@/lib/objects.ts', function () {
|
||||
describe('isObject()', function () {
|
||||
it('should return true for objects', function () {
|
||||
expect(isObject({})).toBe(true);
|
||||
expect(isObject({ foo: 123 })).toBe(true);
|
||||
expect(isObject(Object.freeze({}))).toBe(true);
|
||||
describe('@/lib/objects.ts', () => {
|
||||
describe('isObject()', () => {
|
||||
it('should return true for objects', () => {
|
||||
expect(isObject({})).equals(true);
|
||||
expect(isObject({ foo: 123 })).equals(true);
|
||||
expect(isObject(Object.freeze({}))).equals(true);
|
||||
});
|
||||
|
||||
it('should return false for null', function () {
|
||||
expect(isObject(null)).toBe(false);
|
||||
it('should return false for null', () => {
|
||||
expect(isObject(null)).equals(false);
|
||||
});
|
||||
|
||||
it.each([undefined, 123, 'foobar', () => ({}), Function, String(123), isObject, () => null, [], [1, 2, 3]])(
|
||||
'should return false for %p',
|
||||
function (value) {
|
||||
expect(isObject(value)).toBe(false);
|
||||
}
|
||||
value => {
|
||||
expect(isObject(value)).equals(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { capitalize } from '@/lib/strings';
|
||||
|
||||
describe('@/lib/strings.ts', function () {
|
||||
describe('capitalize()', function () {
|
||||
it('should capitalize a string', function () {
|
||||
expect(capitalize('foo bar')).toBe('Foo bar');
|
||||
expect(capitalize('FOOBAR')).toBe('Foobar');
|
||||
describe('@/lib/strings.ts', () => {
|
||||
describe('capitalize()', () => {
|
||||
it('should capitalize a string', () => {
|
||||
expect(capitalize('foo bar')).equals('Foo bar');
|
||||
expect(capitalize('FOOBAR')).equals('Foobar');
|
||||
});
|
||||
|
||||
it('should handle empty strings', function () {
|
||||
expect(capitalize('')).toBe('');
|
||||
it('should handle empty strings', () => {
|
||||
expect(capitalize('')).equals('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue