Skip to content

Commit

Permalink
♻️ Remove unused outer describe blocks from tests
Browse files Browse the repository at this point in the history
The practice of wrapping each test file in an outer describe block is
not necessary since vitest displays the test file in test results.

This commit removes all outer describe blocks that are not used for any
other purpose than to group tests in the test results.
  • Loading branch information
ralfstx committed Dec 15, 2024
1 parent a1fddc7 commit e3f72ac
Show file tree
Hide file tree
Showing 21 changed files with 2,014 additions and 2,066 deletions.
32 changes: 15 additions & 17 deletions src/api/make-pdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ import { describe, expect, it } from 'vitest';

import { makePdf } from './make-pdf.ts';

describe('make-pdf', () => {
describe('makePdf', () => {
it('creates data that starts with a PDF 1.7 header', async () => {
const pdf = await makePdf({ content: [{}] });
describe('makePdf', () => {
it('creates data that starts with a PDF 1.7 header', async () => {
const pdf = await makePdf({ content: [{}] });

const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/^%PDF-1.7\n/);
});
const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/^%PDF-1.7\n/);
});

it('creates data that ends with a single newline', async () => {
const pdf = await makePdf({ content: [{}] });
it('creates data that ends with a single newline', async () => {
const pdf = await makePdf({ content: [{}] });

const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/[^\n]\n$/);
});
const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/[^\n]\n$/);
});

it('includes a trailer ID in the document', async () => {
const pdf = await makePdf({ content: [{}] });
it('includes a trailer ID in the document', async () => {
const pdf = await makePdf({ content: [{}] });

const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/\/ID \[ <[0-9A-F]{64}> <[0-9A-F]{64}> \]/);
});
const string = Buffer.from(pdf.buffer).toString();
expect(string).toMatch(/\/ID \[ <[0-9A-F]{64}> <[0-9A-F]{64}> \]/);
});
});
50 changes: 22 additions & 28 deletions src/api/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
import crypto from 'node:crypto';

import { describe, expect, it } from 'vitest';

import { span } from './text.ts';

global.crypto ??= (crypto as any).webcrypto;
describe('span', () => {
it('creates text span with given string', () => {
const sp = span('foo');

describe('test', () => {
describe('span', () => {
it('creates text span with given string', () => {
const sp = span('foo');
expect(sp).toEqual({ text: 'foo' });
});

expect(sp).toEqual({ text: 'foo' });
});
it('creates text span with given string and props', () => {
const sp = span('foo', { fontStyle: 'italic' });

it('creates text span with given string and props', () => {
const sp = span('foo', { fontStyle: 'italic' });
expect(sp).toEqual({ text: 'foo', fontStyle: 'italic' });
});

expect(sp).toEqual({ text: 'foo', fontStyle: 'italic' });
});
it('creates text span with given array and props', () => {
const sp = span(['foo', span('bar', { fontStyle: 'italic' })], { fontSize: 8 });

it('creates text span with given array and props', () => {
const sp = span(['foo', span('bar', { fontStyle: 'italic' })], { fontSize: 8 });
expect(sp).toEqual({ text: ['foo', { text: 'bar', fontStyle: 'italic' }], fontSize: 8 });
});

expect(sp).toEqual({ text: ['foo', { text: 'bar', fontStyle: 'italic' }], fontSize: 8 });
});
it('extracts a single array element in text', () => {
const sp = span(['foo'], { fontStyle: 'italic' });

it('extracts a single array element in text', () => {
const sp = span(['foo'], { fontStyle: 'italic' });
expect(sp).toEqual({ text: 'foo', fontStyle: 'italic' });
});

expect(sp).toEqual({ text: 'foo', fontStyle: 'italic' });
it('merges a single text span in text, inner span takes precedence', () => {
const sp = span(span('foo', { fontWeight: 'bold' }), {
fontStyle: 'italic',
fontWeight: 'normal',
});

it('merges a single text span in text, inner span takes precedence', () => {
const sp = span(span('foo', { fontWeight: 'bold' }), {
fontStyle: 'italic',
fontWeight: 'normal',
});

expect(sp).toEqual({ text: 'foo', fontWeight: 'bold', fontStyle: 'italic' });
});
expect(sp).toEqual({ text: 'foo', fontWeight: 'bold', fontStyle: 'italic' });
});
});
66 changes: 32 additions & 34 deletions src/binary-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@ import { describe, expect, it } from 'vitest';

import { parseBinaryData } from './binary-data.ts';

describe('binary-data', () => {
const data = Uint8Array.of(1, 183, 0);

describe('parseBinaryData', () => {
it('returns original Uint8Array', () => {
expect(parseBinaryData(data)).toBe(data);
});

it('returns Uint8Array for ArrayBuffer', () => {
expect(parseBinaryData(data.buffer)).toEqual(data);
});

it('returns Uint8Array for base64-encoded string', () => {
expect(parseBinaryData('Abc=`')).toEqual(data);
});

it('returns Uint8Array for data URL', () => {
expect(parseBinaryData('data:image/jpeg;base64,Abc=`')).toEqual(data);
});

it('throws for arrays', () => {
expect(() => parseBinaryData([1, 2, 3])).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: [1, 2, 3]',
);
});

it('throws for other types', () => {
expect(() => parseBinaryData(23)).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: 23',
);
expect(() => parseBinaryData(null)).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: null',
);
});
const data = Uint8Array.of(1, 183, 0);

describe('parseBinaryData', () => {
it('returns original Uint8Array', () => {
expect(parseBinaryData(data)).toBe(data);
});

it('returns Uint8Array for ArrayBuffer', () => {
expect(parseBinaryData(data.buffer)).toEqual(data);
});

it('returns Uint8Array for base64-encoded string', () => {
expect(parseBinaryData('Abc=`')).toEqual(data);
});

it('returns Uint8Array for data URL', () => {
expect(parseBinaryData('data:image/jpeg;base64,Abc=`')).toEqual(data);
});

it('throws for arrays', () => {
expect(() => parseBinaryData([1, 2, 3])).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: [1, 2, 3]',
);
});

it('throws for other types', () => {
expect(() => parseBinaryData(23)).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: 23',
);
expect(() => parseBinaryData(null)).toThrowError(
'Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: null',
);
});
});
Loading

0 comments on commit e3f72ac

Please sign in to comment.