Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve the code in test-fs-null-bytes #10521

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions test/parallel/test-fs-null-bytes.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

function check(async, sync) {
var expected = /Path must be a string without null bytes/;
var argsSync = Array.prototype.slice.call(arguments, 2);
var argsAsync = argsSync.concat(function(er) {
const expected = /Path must be a string without null bytes/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we use /^Error: Path must be a string without null bytes$/?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpinca , removed the unnecessary common.mustCall, but this one is asserting against the error message and the error message is exactly that one: https://github.com/nodejs/node/blob/master/lib/fs.js#L118

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, other tests use the full message with boundaries, ^$, and I would like to be consistent here.

Copy link
Member Author

@edsadr edsadr Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpinca this test is using that variable twice to validate the error, one of these is an assert.throws if I set the boundaries that one will fail, I could use 2 different vars to test the error... but... not sure if worth it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edsadr you are right, I missed that other assertion. I think it's fine to keep it as is then. Sorry for the confusion.

const argsSync = Array.prototype.slice.call(arguments, 2);
const argsAsync = argsSync.concat((er) => {
assert(er && er.message.match(expected));
assert.equal(er.code, 'ENOENT');
assert.strictEqual(er.code, 'ENOENT');
});

if (sync)
assert.throws(function() {
console.error(sync.name, argsSync);
assert.throws(() => {
sync.apply(null, argsSync);
}, expected);

Expand Down Expand Up @@ -51,7 +50,7 @@ check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar');

// an 'error' for exists means that it doesn't exist.
// 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(!fs.existsSync('foo\u0000bar'));