mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Track binary size of resources when possible
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'jest-rdf';
|
||||
import { DataFactory } from 'n3';
|
||||
import { parseQuads, serializeQuads, uniqueQuads } from '../../../src/util/QuadUtil';
|
||||
import { parseQuads, serializeQuads, termToInt, uniqueQuads } from '../../../src/util/QuadUtil';
|
||||
import { guardedStreamFrom, readableToString } from '../../../src/util/StreamUtil';
|
||||
const { literal, namedNode, quad } = DataFactory;
|
||||
|
||||
@@ -50,4 +50,15 @@ describe('QuadUtil', (): void => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#termToInt', (): void => {
|
||||
it('returns undefined if the input is undefined.', async(): Promise<void> => {
|
||||
expect(termToInt()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('converts the term to a number.', async(): Promise<void> => {
|
||||
expect(termToInt(namedNode('5'))).toBe(5);
|
||||
expect(termToInt(namedNode('0xF'), 16)).toBe(15);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { SliceStream } from '../../../src/util/SliceStream';
|
||||
import { readableToString } from '../../../src/util/StreamUtil';
|
||||
|
||||
describe('A SliceStream', (): void => {
|
||||
it('does not support suffix slicing.', async(): Promise<void> => {
|
||||
it('does not support suffix slicing if the size is unknown.', async(): Promise<void> => {
|
||||
expect((): unknown => new SliceStream(Readable.from('0123456789'), { start: -5 }))
|
||||
.toThrow(RangeNotSatisfiedHttpError);
|
||||
});
|
||||
@@ -16,6 +16,11 @@ describe('A SliceStream', (): void => {
|
||||
.toThrow(RangeNotSatisfiedHttpError);
|
||||
});
|
||||
|
||||
it('requires the end to be less than the size.', async(): Promise<void> => {
|
||||
expect((): unknown => new SliceStream(Readable.from('0123456789'), { start: 5, end: 6, size: 6 }))
|
||||
.toThrow(RangeNotSatisfiedHttpError);
|
||||
});
|
||||
|
||||
it('can slice binary streams.', async(): Promise<void> => {
|
||||
await expect(readableToString(new SliceStream(Readable.from('0123456789', { objectMode: false }),
|
||||
{ start: 3, end: 7, objectMode: false }))).resolves.toBe('34567');
|
||||
@@ -25,6 +30,9 @@ describe('A SliceStream', (): void => {
|
||||
|
||||
await expect(readableToString(new SliceStream(Readable.from('0123456789', { objectMode: false }),
|
||||
{ start: 3, end: 20, objectMode: false }))).resolves.toBe('3456789');
|
||||
|
||||
await expect(readableToString(new SliceStream(Readable.from('0123456789', { objectMode: false }),
|
||||
{ start: -3, size: 10, objectMode: false }))).resolves.toBe('789');
|
||||
});
|
||||
|
||||
it('can slice object streams.', async(): Promise<void> => {
|
||||
@@ -37,5 +45,8 @@ describe('A SliceStream', (): void => {
|
||||
|
||||
await expect(readableToString(new SliceStream(Readable.from(arr, { objectMode: true }),
|
||||
{ start: 3, end: 20, objectMode: true }))).resolves.toBe('3456789');
|
||||
|
||||
await expect(readableToString(new SliceStream(Readable.from(arr, { objectMode: true }),
|
||||
{ start: -3, size: 10, objectMode: true }))).resolves.toBe('789');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user