Skip to content

Commit 05be623

Browse files
committed
test: refactor test-fs-buffer
* Remove unneeded temp dir cleanup * Add check for error in `.close()` callback * Improve error reporting On that last bullet point, the previous version of the test reported errors like this: ``` AssertionError: [ '.empty-repl-history-file', '.node_repl_history', 'GH-1899-output.js', 'GH-892-request.js', 'a.js', 'a1.js', 'agen deepStrictEqual [ '.empty-repl-history-file', '.node_repl_history', 'GH-1899-output.js', 'GH-892-request.js', 'a.js', 'a1.js', 'agen ``` Now, they look like this: ``` AssertionError: expected *, got ! by hex decoding 2a ``` PR-URL: #11232 Reviewed-By: James M Snell <[email protected]>
1 parent 595df9f commit 05be623

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/parallel/test-fs-buffer.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ assert.doesNotThrow(() => {
1818
fs.open(buf, 'w+', common.mustCall((err, fd) => {
1919
assert.ifError(err);
2020
assert(fd);
21-
fs.close(fd, common.mustCall(() => {
22-
fs.unlinkSync(buf);
21+
fs.close(fd, common.mustCall((err) => {
22+
assert.ifError(err);
2323
}));
2424
}));
2525
});
@@ -29,13 +29,17 @@ assert.throws(() => {
2929
}, /path must be a string or Buffer/);
3030

3131
const dir = Buffer.from(common.fixturesDir);
32-
fs.readdir(dir, 'hex', common.mustCall((err, list) => {
32+
fs.readdir(dir, 'hex', common.mustCall((err, hexList) => {
3333
assert.ifError(err);
34-
list = list.map((i) => {
35-
return Buffer.from(i, 'hex').toString();
36-
});
37-
fs.readdir(dir, common.mustCall((err, list2) => {
34+
fs.readdir(dir, common.mustCall((err, stringList) => {
3835
assert.ifError(err);
39-
assert.deepStrictEqual(list, list2);
36+
stringList.forEach((val, idx) => {
37+
const fromHexList = Buffer.from(hexList[idx], 'hex').toString();
38+
assert.strictEqual(
39+
fromHexList,
40+
val,
41+
`expected ${val}, got ${fromHexList} by hex decoding ${hexList[idx]}`
42+
);
43+
});
4044
}));
4145
}));

0 commit comments

Comments
 (0)