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
  • Loading branch information
Trott committed Aug 9, 2017
1 parent 1e33f92 commit b3166e3
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 b3166e3

Please sign in to comment.