From c6126b1308d5f7a8a06a36a3c1b523268edfd3fe Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 5 Aug 2017 17:25:30 -0700 Subject: [PATCH] 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 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- test/parallel/test-fs-stat.js | 39 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index c12af535fa8..8a6bb1c6245 100644 --- a/test/parallel/test-fs-stat.js +++ b/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',