Browse Source

test: refactor test-fs-stat

* 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: https://github.com/nodejs/node/pull/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>
v6
Rich Trott 7 years ago
parent
commit
c6126b1308
  1. 39
      test/parallel/test-fs-stat.js

39
test/parallel/test-fs-stat.js

@ -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) {
@ -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
@ -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',

Loading…
Cancel
Save