mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 15:41:42 +00:00

Comparing any value to any non-RegExp literal or undefined using strictEqual (or notStrictEqual) passes if and only if deepStrictEqual (or notDeepStrictEqual, respectively) passes. Unnecessarily using deep comparisons adds confusion. This patch adds an ESLint rule that forbids the use of deepStrictEqual and notDeepStrictEqual when the expected value (i.e., the second argument) is a non-RegExp literal or undefined. For reference, an ESTree literal is defined as follows. extend interface Literal <: Expression { type: "Literal"; value: string | boolean | null | number | RegExp | bigint; } The value `undefined` is an `Identifier` with `name: 'undefined'`. PR-URL: https://github.com/nodejs/node/pull/40634 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Voltrex <mohammadkeyvanzade94@gmail.com>
51 lines
2.0 KiB
JavaScript
51 lines
2.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs').promises;
|
|
const tmpdir = require('../common/tmpdir');
|
|
const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف';
|
|
let cnt = 0;
|
|
|
|
function getFileName() {
|
|
return path.join(tmpdir.path, `writev_promises_${++cnt}.txt`);
|
|
}
|
|
|
|
tmpdir.refresh();
|
|
|
|
(async () => {
|
|
{
|
|
const filename = getFileName();
|
|
const handle = await fs.open(filename, 'w');
|
|
const buffer = Buffer.from(expected);
|
|
const bufferArr = [buffer, buffer];
|
|
const expectedLength = bufferArr.length * buffer.byteLength;
|
|
let { bytesWritten, buffers } = await handle.writev([Buffer.from('')],
|
|
null);
|
|
assert.strictEqual(bytesWritten, 0);
|
|
assert.deepStrictEqual(buffers, [Buffer.from('')]);
|
|
({ bytesWritten, buffers } = await handle.writev(bufferArr, null));
|
|
assert.deepStrictEqual(bytesWritten, expectedLength);
|
|
assert.deepStrictEqual(buffers, bufferArr);
|
|
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
|
|
handle.close();
|
|
}
|
|
|
|
// fs.promises.writev() with an array of buffers without position.
|
|
{
|
|
const filename = getFileName();
|
|
const handle = await fs.open(filename, 'w');
|
|
const buffer = Buffer.from(expected);
|
|
const bufferArr = [buffer, buffer, buffer];
|
|
const expectedLength = bufferArr.length * buffer.byteLength;
|
|
let { bytesWritten, buffers } = await handle.writev([Buffer.from('')]);
|
|
assert.strictEqual(bytesWritten, 0);
|
|
assert.deepStrictEqual(buffers, [Buffer.from('')]);
|
|
({ bytesWritten, buffers } = await handle.writev(bufferArr));
|
|
assert.deepStrictEqual(bytesWritten, expectedLength);
|
|
assert.deepStrictEqual(buffers, bufferArr);
|
|
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
|
|
handle.close();
|
|
}
|
|
})().then(common.mustCall());
|