mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
74e0ca3f49
PR-URL: https://github.com/nodejs/node/pull/49125 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
40 lines
698 B
JavaScript
40 lines
698 B
JavaScript
import '../common/index.mjs';
|
|
import tmpdir from '../common/tmpdir.js';
|
|
|
|
import assert from 'node:assert';
|
|
import { open, writeFile } from 'node:fs/promises';
|
|
|
|
tmpdir.refresh();
|
|
|
|
const filePath = tmpdir.resolve('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();
|
|
}
|