Skip to content

Commit

Permalink
test: refactor test-fs-stat
Browse files Browse the repository at this point in the history
* add `use strict'
* change checks that `this` is mapped to `global` in sloppy mode to
  checks that `this` is `undefined`
* modify arguments to assertions to match docs (actual first, expected
  second)
* add blank line below `common` declaration per test writing guide
* use `assert.ifError()` as appropriate

PR-URL: nodejs#14645
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
Trott committed Aug 10, 2017
1 parent 0eb7268 commit c6126b1
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

/* eslint-disable strict */
'use strict';
const common = require('../common');

const assert = require('assert');
const fs = require('fs');

fs.stat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
assert.strictEqual(this, global);
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, undefined);
}));

fs.stat('.', common.mustCall(function(err, stats) {
Expand All @@ -38,22 +42,31 @@ fs.stat('.', common.mustCall(function(err, stats) {
fs.lstat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
assert.strictEqual(this, global);
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, undefined);
}));

// fstat
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
assert.ok(!err);
assert.ifError(err);
assert.ok(fd);

fs.fstat(fd, common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
fs.close(fd, assert.ifError);
assert.strictEqual(this, global);
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, undefined);
}));

assert.strictEqual(this, global);
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, null);
}));

// fstatSync
Expand All @@ -72,13 +85,13 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {

fs.stat(__filename, common.mustCall(function(err, s) {
assert.ifError(err);
assert.strictEqual(false, s.isDirectory());
assert.strictEqual(true, s.isFile());
assert.strictEqual(false, s.isSocket());
assert.strictEqual(false, s.isBlockDevice());
assert.strictEqual(false, s.isCharacterDevice());
assert.strictEqual(false, s.isFIFO());
assert.strictEqual(false, s.isSymbolicLink());
assert.strictEqual(s.isDirectory(), false);
assert.strictEqual(s.isFile(), true);
assert.strictEqual(s.isSocket(), false);
assert.strictEqual(s.isBlockDevice(), false);
assert.strictEqual(s.isCharacterDevice(), false);
assert.strictEqual(s.isFIFO(), false);
assert.strictEqual(s.isSymbolicLink(), false);
const keys = [
'dev', 'mode', 'nlink', 'uid',
'gid', 'rdev', 'ino', 'size',
Expand Down

0 comments on commit c6126b1

Please sign in to comment.