Skip to content

Commit

Permalink
fixup! fs: add FileHandle.prototype.readLines
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Apr 3, 2022
1 parent 7ec3eda commit 60a2fc0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/parallel/test-fs-promises-file-handle-readLines.mjs
@@ -0,0 +1,40 @@
import '../common/index.mjs';
import tmpdir from '../common/tmpdir.js';

import assert from 'node:assert';
import { open, writeFile } from 'node:fs/promises';
import path from 'node:path';

tmpdir.refresh();

const filePath = path.join(tmpdir.path, 'file.txt');

await writeFile(filePath, '1\n\n2\n');

let file;
try {
file = await open(filePath);

let i = 0;
for await (const line of file.readLines()) {
switch (i++) {
case 0:
assert.strictEqual(line, '1');
break;

case 1:
assert.strictEqual(line, '');
break;

case 2:
assert.strictEqual(line, '2');
break;

default:
assert.fail();
break;
}
}
} finally {
await file?.close();
}

0 comments on commit 60a2fc0

Please sign in to comment.