Skip to content

Commit f0b1e05

Browse files
committed
Add FsFile stream() slice test
1 parent 8baa8ce commit f0b1e05

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/tests/src/switch.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,25 @@ test('`Switch.file()` read json', async () => {
263263

264264
test('`Switch.file()` read stream', async () => {
265265
const file = Switch.file('romfs:/file.txt');
266-
const stream = file.stream({ chunkSize: 3 });
267266
const chunks: string[] = [];
268267
const decoder = new TextDecoder();
269-
for await (const chunk of stream) {
268+
for await (const chunk of file.stream({ chunkSize: 3 })) {
270269
chunks.push(decoder.decode(chunk));
271270
}
272271
assert.equal(chunks, ['thi', 's i', 's a', ' te', 'xt ', 'fil', 'e\n']);
273272
});
274273

274+
test('`Switch.file()` read stream with slice', async () => {
275+
const file = Switch.file('romfs:/file.txt').slice(1, 11);
276+
const chunks: string[] = [];
277+
const decoder = new TextDecoder();
278+
for await (const chunk of file.stream({ chunkSize: 3 })) {
279+
chunks.push(decoder.decode(chunk));
280+
}
281+
assert.equal(chunks, ['his', ' is', ' a ', 't']);
282+
assert.equal(chunks.join('').length, 10);
283+
});
284+
275285
test('`Switch.file()` read stream throws on ENOENT', async () => {
276286
let err: Error | undefined;
277287
const file = Switch.file('romfs:/does_not_exist');

0 commit comments

Comments
 (0)