Skip to content

Commit

Permalink
Issue-425 - Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo committed May 21, 2024
1 parent 8bad6cf commit 875a0bd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/sitemap-stream.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createReadStream } from 'fs';
import { tmpdir } from 'os';
import { resolve } from 'path';
import { Readable } from 'stream';
import { EmptyStream } from '../lib/errors';
import {
SitemapStream,
closetag,
streamToPromise,
} from '../lib/sitemap-stream';
import { createReadStream } from 'fs';
import { resolve } from 'path';

const minimumns =
'<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
Expand Down Expand Up @@ -103,4 +105,24 @@ describe('sitemap stream', () => {
)
).rejects.toThrow('ENOENT');
});

it('streamToPromise throws EmptyStream error on empty stream', async () => {
const emptyStream = new Readable();
emptyStream.push(null); // This makes the stream "empty"

await expect(streamToPromise(emptyStream)).rejects.toThrow(EmptyStream);
});

it('streamToPromise returns concatenated data', async () => {
const stream = new Readable();
stream.push('Hello');
stream.push(' ');
stream.push('World');
stream.push('!');
stream.push(null); // Close the stream

await expect(streamToPromise(stream)).resolves.toEqual(
Buffer.from('Hello World!', 'utf-8')
);
});
});

0 comments on commit 875a0bd

Please sign in to comment.