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: adding mustCall in test-fs-readfile-empty.js #27455

Closed
wants to merge 6 commits 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
17 changes: 8 additions & 9 deletions test/parallel/test-fs-readfile-empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
Copy link
Member

Choose a reason for hiding this comment

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

The common module should be required in tests before any other module: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#lines-1-3

I’m a little surprised that the linter didn’t pick this up.

Copy link
Member

Choose a reason for hiding this comment

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

Me too... 🤔


// Trivial test of fs.readFile on an empty file.

const assert = require('assert');
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const fixtures = require('../common/fixtures');

const fn = fixtures.path('empty.txt');

fs.readFile(fn, function(err, data) {
fs.readFile(fn, common.mustCall((err, data) => {
assert.ok(data);
});
}));

fs.readFile(fn, 'utf8', function(err, data) {
fs.readFile(fn, 'utf8', common.mustCall((err, data) => {
assert.strictEqual(data, '');
});
}));

fs.readFile(fn, { encoding: 'utf8' }, function(err, data) {
fs.readFile(fn, { encoding: 'utf8' }, common.mustCall((err, data) => {
assert.strictEqual(data, '');
});
}));

assert.ok(fs.readFileSync(fn));
assert.strictEqual(fs.readFileSync(fn, 'utf8'), '');