test: improve test-fs-null-bytes
* use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions * remove console.error PR-URL: https://github.com/nodejs/node/pull/10521 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
7f69972cf0
commit
6830849b2e
@ -4,16 +4,15 @@ const assert = require('assert');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
function check(async, sync) {
|
function check(async, sync) {
|
||||||
var expected = /Path must be a string without null bytes/;
|
const expected = /Path must be a string without null bytes/;
|
||||||
var argsSync = Array.prototype.slice.call(arguments, 2);
|
const argsSync = Array.prototype.slice.call(arguments, 2);
|
||||||
var argsAsync = argsSync.concat(function(er) {
|
const argsAsync = argsSync.concat((er) => {
|
||||||
assert(er && er.message.match(expected));
|
assert(er && er.message.match(expected));
|
||||||
assert.equal(er.code, 'ENOENT');
|
assert.strictEqual(er.code, 'ENOENT');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sync)
|
if (sync)
|
||||||
assert.throws(function() {
|
assert.throws(() => {
|
||||||
console.error(sync.name, argsSync);
|
|
||||||
sync.apply(null, argsSync);
|
sync.apply(null, argsSync);
|
||||||
}, expected);
|
}, expected);
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar');
|
|||||||
|
|
||||||
// an 'error' for exists means that it doesn't exist.
|
// an 'error' for exists means that it doesn't exist.
|
||||||
// one of many reasons why this file is the absolute worst.
|
// one of many reasons why this file is the absolute worst.
|
||||||
fs.exists('foo\u0000bar', function(exists) {
|
fs.exists('foo\u0000bar', common.mustCall((exists) => {
|
||||||
assert(!exists);
|
assert(!exists);
|
||||||
});
|
}));
|
||||||
assert(!fs.existsSync('foo\u0000bar'));
|
assert(!fs.existsSync('foo\u0000bar'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user