0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-promises-file-handle-readLines.mjs
Livia Medeiros 74e0ca3f49
test: use tmpdir.resolve() in fs tests
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>
2023-08-15 13:45:14 +00:00

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();
}