Skip to content

Commit c6126b1

Browse files
committed
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: #14645 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 0eb7268 commit c6126b1

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

test/parallel/test-fs-stat.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
/* eslint-disable strict */
22+
'use strict';
2323
const common = require('../common');
24+
2425
const assert = require('assert');
2526
const fs = require('fs');
2627

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

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

4451
// fstat
4552
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
46-
assert.ok(!err);
53+
assert.ifError(err);
4754
assert.ok(fd);
4855

4956
fs.fstat(fd, common.mustCall(function(err, stats) {
5057
assert.ifError(err);
5158
assert.ok(stats.mtime instanceof Date);
5259
fs.close(fd, assert.ifError);
53-
assert.strictEqual(this, global);
60+
// Confirm that we are not running in the context of the internal binding
61+
// layer.
62+
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
63+
assert.strictEqual(this, undefined);
5464
}));
5565

56-
assert.strictEqual(this, global);
66+
// Confirm that we are not running in the context of the internal binding
67+
// layer.
68+
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
69+
assert.strictEqual(this, null);
5770
}));
5871

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

7386
fs.stat(__filename, common.mustCall(function(err, s) {
7487
assert.ifError(err);
75-
assert.strictEqual(false, s.isDirectory());
76-
assert.strictEqual(true, s.isFile());
77-
assert.strictEqual(false, s.isSocket());
78-
assert.strictEqual(false, s.isBlockDevice());
79-
assert.strictEqual(false, s.isCharacterDevice());
80-
assert.strictEqual(false, s.isFIFO());
81-
assert.strictEqual(false, s.isSymbolicLink());
88+
assert.strictEqual(s.isDirectory(), false);
89+
assert.strictEqual(s.isFile(), true);
90+
assert.strictEqual(s.isSocket(), false);
91+
assert.strictEqual(s.isBlockDevice(), false);
92+
assert.strictEqual(s.isCharacterDevice(), false);
93+
assert.strictEqual(s.isFIFO(), false);
94+
assert.strictEqual(s.isSymbolicLink(), false);
8295
const keys = [
8396
'dev', 'mode', 'nlink', 'uid',
8497
'gid', 'rdev', 'ino', 'size',

0 commit comments

Comments
 (0)