Browse Source

tools: add eslint rule prefer-assert-methods

PR-URL: https://github.com/nodejs/node/pull/8622
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: Jackson Tian <shvyo1987@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
v7.x
Dany Shaanan 8 years ago
committed by James M Snell
parent
commit
d469321946
  1. 1
      test/.eslintrc
  2. 4
      test/addons/load-long-path/test.js
  3. 2
      test/gc/test-http-client-connaborted.js
  4. 3
      test/gc/test-http-client-timeout.js
  5. 3
      test/gc/test-http-client.js
  6. 2
      test/gc/test-net-timeout.js
  7. 1
      test/parallel/test-child-process-detached.js
  8. 2
      test/parallel/test-child-process-fork-regr-gh-2847.js
  9. 2
      test/parallel/test-cluster-setup-master-argv.js
  10. 2
      test/parallel/test-domain-http-server.js
  11. 7
      test/parallel/test-domain-top-level-error-handler-throw.js
  12. 20
      test/parallel/test-event-emitter-listeners-side-effects.js
  13. 2
      test/parallel/test-file-write-stream2.js
  14. 8
      test/parallel/test-fs-access.js
  15. 2
      test/parallel/test-fs-mkdtemp.js
  16. 4
      test/parallel/test-fs-readfile-pipe-large.js
  17. 4
      test/parallel/test-fs-readfile-pipe.js
  18. 2
      test/parallel/test-fs-readfile-unlink.js
  19. 4
      test/parallel/test-fs-readfilesync-pipe-large.js
  20. 8
      test/parallel/test-fs-stat.js
  21. 2
      test/parallel/test-fs-write-stream-autoclose-option.js
  22. 6
      test/parallel/test-http-agent-destroyed-socket.js
  23. 2
      test/parallel/test-http-byteswritten.js
  24. 14
      test/parallel/test-http-client-default-headers-exist.js
  25. 6
      test/parallel/test-http-methods.js
  26. 2
      test/parallel/test-http-write-head.js
  27. 2
      test/parallel/test-https-byteswritten.js
  28. 5
      test/parallel/test-internal-modules.js
  29. 2
      test/parallel/test-process-config.js
  30. 2
      test/parallel/test-process-getgroups.js
  31. 2
      test/parallel/test-repl-context.js
  32. 2
      test/parallel/test-require-json.js
  33. 4
      test/parallel/test-stream-duplex.js
  34. 12
      test/parallel/test-stream-transform-split-objectmode.js
  35. 2
      test/parallel/test-stream2-writable.js
  36. 2
      test/parallel/test-timers-active.js
  37. 2
      test/parallel/test-tls-alert-handling.js
  38. 6
      test/parallel/test-tls-pfx-gh-5100-regr.js
  39. 2
      test/parallel/test-tls-server-connection-server.js
  40. 4
      test/parallel/test-url.js
  41. 8
      test/parallel/test-vm-harmony-symbols.js
  42. 8
      test/parallel/test-vm-proxies.js
  43. 6
      test/pummel/test-net-connect-memleak.js
  44. 6
      test/pummel/test-tls-connect-memleak.js
  45. 6
      test/pummel/test-tls-session-timeout.js
  46. 2
      test/sequential/test-child-process-emfile.js
  47. 2
      test/sequential/test-child-process-fork-getconnections.js
  48. 39
      tools/eslint-rules/prefer-assert-methods.js

1
test/.eslintrc

@ -3,3 +3,4 @@
rules:
## common module is mandatory in tests
required-modules: [2, common]
prefer-assert-methods: 2

4
test/addons/load-long-path/test.js

@ -30,5 +30,5 @@ fs.writeFileSync(addonDestinationPath, contents);
// Attempt to load at long path destination
var addon = require(addonDestinationPath);
assert(addon != null);
assert(addon.hello() == 'world');
assert.notEqual(addon, null);
assert.equal(addon.hello(), 'world');

2
test/gc/test-http-client-connaborted.js

@ -64,7 +64,7 @@ function status() {
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert(count === countGC);
assert.strictEqual(count, countGC);
process.exit(0);
}
}

3
test/gc/test-http-client-timeout.js

@ -73,8 +73,7 @@ function status() {
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert(count === countGC);
assert.strictEqual(count, countGC);
process.exit(0);
}
}

3
test/gc/test-http-client.js

@ -62,8 +62,7 @@ function status() {
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert(count === countGC);
assert.strictEqual(count, countGC);
process.exit(0);
}
}

2
test/gc/test-net-timeout.js

@ -69,7 +69,7 @@ function status() {
global.gc();
console.log('All should be collected now.');
console.log('Collected: %d/%d', countGC, count);
assert(count === countGC);
assert.strictEqual(count, countGC);
process.exit(0);
}, 200);
}

1
test/parallel/test-child-process-detached.js

@ -23,4 +23,3 @@ process.on('exit', function() {
process.kill(persistentPid);
});
});

2
test/parallel/test-child-process-fork-regr-gh-2847.js

@ -45,7 +45,7 @@ var server = net.createServer(function(s) {
worker.process.once('close', common.mustCall(function() {
// Otherwise the crash on `_channel.fd` access may happen
assert(worker.process._channel === null);
assert.strictEqual(worker.process._channel, null);
server.close();
}));

2
test/parallel/test-cluster-setup-master-argv.js

@ -12,7 +12,7 @@ cluster.on('setup', function() {
realArgs[realArgs.length - 1]);
});
assert(process.argv[process.argv.length - 1] !== 'OMG,OMG');
assert.notStrictEqual(process.argv[process.argv.length - 1], 'OMG,OMG');
process.argv.push('OMG,OMG');
process.argv.push('OMG,OMG');
cluster.setupMaster();

2
test/parallel/test-domain-http-server.js

@ -30,7 +30,7 @@ var server = http.createServer(function(req, res) {
var data = JSON.stringify(objects[req.url.replace(/[^a-z]/g, '')]);
// this line will throw if you pick an unknown key
assert(data !== undefined, 'Data should not be undefined');
assert.notStrictEqual(data, undefined, 'Data should not be undefined');
res.writeHead(200);
res.end(data);

7
test/parallel/test-domain-top-level-error-handler-throw.js

@ -37,8 +37,11 @@ if (process.argv[2] === 'child') {
});
child.on('close', function onChildClosed() {
assert(stderrOutput.indexOf(domainErrHandlerExMessage) !== -1);
assert(stderrOutput.indexOf(internalExMessage) === -1);
assert.notStrictEqual(
stderrOutput.indexOf(domainErrHandlerExMessage),
-1
);
assert.strictEqual(stderrOutput.indexOf(internalExMessage), -1);
});
child.on('exit', function onChildExited(exitCode, signal) {

20
test/parallel/test-event-emitter-listeners-side-effects.js

@ -10,16 +10,16 @@ var fl; // foo listeners
fl = e.listeners('foo');
assert(Array.isArray(fl));
assert(fl.length === 0);
assert.strictEqual(fl.length, 0);
assert(!(e._events instanceof Object));
assert.deepStrictEqual(Object.keys(e._events), []);
e.on('foo', common.fail);
fl = e.listeners('foo');
assert(e._events.foo === common.fail);
assert.strictEqual(e._events.foo, common.fail);
assert(Array.isArray(fl));
assert(fl.length === 1);
assert(fl[0] === common.fail);
assert.strictEqual(fl.length, 1);
assert.strictEqual(fl[0], common.fail);
e.listeners('bar');
@ -27,13 +27,13 @@ e.on('foo', assert.ok);
fl = e.listeners('foo');
assert(Array.isArray(e._events.foo));
assert(e._events.foo.length === 2);
assert(e._events.foo[0] === common.fail);
assert(e._events.foo[1] === assert.ok);
assert.strictEqual(e._events.foo.length, 2);
assert.strictEqual(e._events.foo[0], common.fail);
assert.strictEqual(e._events.foo[1], assert.ok);
assert(Array.isArray(fl));
assert(fl.length === 2);
assert(fl[0] === common.fail);
assert(fl[1] === assert.ok);
assert.strictEqual(fl.length, 2);
assert.strictEqual(fl[0], common.fail);
assert.strictEqual(fl[1], assert.ok);
console.log('ok');

2
test/parallel/test-file-write-stream2.js

@ -85,6 +85,6 @@ for (var i = 0; i < 11; i++) {
console.error('%d %j', i, ret);
// return false when i hits 10
assert(ret === (i != 10));
assert.strictEqual(ret, i != 10);
}
cb_occurred += 'write ';

8
test/parallel/test-fs-access.js

@ -58,10 +58,10 @@ if (!common.isWindows && process.getuid() === 0) {
}
}
assert(typeof fs.F_OK === 'number');
assert(typeof fs.R_OK === 'number');
assert(typeof fs.W_OK === 'number');
assert(typeof fs.X_OK === 'number');
assert.strictEqual(typeof fs.F_OK, 'number');
assert.strictEqual(typeof fs.R_OK, 'number');
assert.strictEqual(typeof fs.W_OK, 'number');
assert.strictEqual(typeof fs.X_OK, 'number');
fs.access(__filename, function(err) {
assert.strictEqual(err, null, 'error should not exist');

2
test/parallel/test-fs-mkdtemp.js

@ -10,7 +10,7 @@ common.refreshTmpDir();
const tmpFolder = fs.mkdtempSync(path.join(common.tmpDir, 'foo.'));
assert(path.basename(tmpFolder).length === 'foo.XXXXXX'.length);
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
assert(common.fileExists(tmpFolder));
const utf8 = fs.mkdtempSync(path.join(common.tmpDir, '\u0222abc.'));

4
test/parallel/test-fs-readfile-pipe-large.js

@ -32,8 +32,8 @@ var cmd = 'cat ' + filename + ' | ' + node + ' ' + f + ' child';
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert(stdout === dataExpected, 'it reads the file and outputs it');
assert(stderr === '', 'it does not write to stderr');
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
});

4
test/parallel/test-fs-readfile-pipe.js

@ -28,7 +28,7 @@ var cmd = 'cat ' + f + ' | ' + node + ' ' + f + ' child';
exec(cmd, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert(stdout === dataExpected, 'it reads the file and outputs it');
assert(stderr === '', 'it does not write to stderr');
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
});

2
test/parallel/test-fs-readfile-unlink.js

@ -19,7 +19,7 @@ fs.writeFileSync(fileName, buf);
fs.readFile(fileName, function(err, data) {
assert.ifError(err);
assert(data.length == buf.length);
assert.equal(data.length, buf.length);
assert.strictEqual(buf[0], 42);
fs.unlinkSync(fileName);

4
test/parallel/test-fs-readfilesync-pipe-large.js

@ -29,8 +29,8 @@ var cmd = 'cat ' + filename + ' | ' + node + ' ' + f + ' child';
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert(stdout === dataExpected, 'it reads the file and outputs it');
assert(stderr === '', 'it does not write to stderr');
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
});

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

@ -6,7 +6,7 @@ var fs = require('fs');
fs.stat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
assert(this === global);
assert.strictEqual(this, global);
}));
fs.stat('.', common.mustCall(function(err, stats) {
@ -17,7 +17,7 @@ fs.stat('.', common.mustCall(function(err, stats) {
fs.lstat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
assert(this === global);
assert.strictEqual(this, global);
}));
// fstat
@ -29,10 +29,10 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
fs.close(fd);
assert(this === global);
assert.strictEqual(this, global);
}));
assert(this === global);
assert.strictEqual(this, global);
}));
// fstatSync

2
test/parallel/test-fs-write-stream-autoclose-option.js

@ -12,7 +12,7 @@ stream.end();
stream.on('finish', common.mustCall(function() {
process.nextTick(common.mustCall(function() {
assert.strictEqual(stream.closed, undefined);
assert(stream.fd !== null);
assert.notStrictEqual(stream.fd, null);
next();
}));
}));

6
test/parallel/test-http-agent-destroyed-socket.js

@ -23,7 +23,7 @@ var server = http.createServer(function(req, res) {
var request1 = http.get(requestOptions, function(response) {
// assert request2 is queued in the agent
var key = agent.getName(requestOptions);
assert(agent.requests[key].length === 1);
assert.strictEqual(agent.requests[key].length, 1);
console.log('got response1');
request1.socket.on('close', function() {
console.log('request1 socket closed');
@ -51,7 +51,7 @@ var server = http.createServer(function(req, res) {
process.nextTick(function() {
// assert that the same socket was not assigned to request2,
// since it was destroyed.
assert(request1.socket !== request2.socket);
assert.notStrictEqual(request1.socket, request2.socket);
assert(!request2.socket.destroyed, 'the socket is destroyed');
});
});
@ -62,7 +62,7 @@ var server = http.createServer(function(req, res) {
assert(!request2.socket.destroyed);
assert(request1.socket.destroyed);
// assert not reusing the same socket, since it was destroyed.
assert(request1.socket !== request2.socket);
assert.notStrictEqual(request1.socket, request2.socket);
console.log('got response2');
var gotClose = false;
var gotResponseEnd = false;

2
test/parallel/test-http-byteswritten.js

@ -9,7 +9,7 @@ var httpServer = http.createServer(common.mustCall(function(req, res) {
httpServer.close();
res.on('finish', common.mustCall(function() {
assert(typeof req.connection.bytesWritten === 'number');
assert.strictEqual(typeof req.connection.bytesWritten, 'number');
assert(req.connection.bytesWritten > 0);
}));
res.writeHead(200, { 'Content-Type': 'text/plain' });

14
test/parallel/test-http-client-default-headers-exist.js

@ -25,12 +25,18 @@ var server = http.createServer(function(req, res) {
var requestHeaders = Object.keys(req.headers);
requestHeaders.forEach(function(header) {
assert(expectedHeaders[req.method].indexOf(header.toLowerCase()) !== -1,
header + ' shoud not exist for method ' + req.method);
assert.notStrictEqual(
expectedHeaders[req.method].indexOf(header.toLowerCase()),
-1,
header + ' shoud not exist for method ' + req.method
);
});
assert(requestHeaders.length === expectedHeaders[req.method].length,
'some headers were missing for method: ' + req.method);
assert.strictEqual(
requestHeaders.length,
expectedHeaders[req.method].length,
'some headers were missing for method: ' + req.method
);
if (expectedMethods.length === requestCount)
server.close();

6
test/parallel/test-http-methods.js

@ -6,7 +6,7 @@ var util = require('util');
assert(Array.isArray(http.METHODS));
assert(http.METHODS.length > 0);
assert(http.METHODS.indexOf('GET') !== -1);
assert(http.METHODS.indexOf('HEAD') !== -1);
assert(http.METHODS.indexOf('POST') !== -1);
assert.notStrictEqual(http.METHODS.indexOf('GET'), -1);
assert.notStrictEqual(http.METHODS.indexOf('HEAD'), -1);
assert.notStrictEqual(http.METHODS.indexOf('POST'), -1);
assert.deepStrictEqual(util._extend([], http.METHODS), http.METHODS.sort());

2
test/parallel/test-http-write-head.js

@ -40,7 +40,7 @@ function runTest() {
http.get({ port: this.address().port }, function(response) {
response.on('end', function() {
assert.equal(response.headers['test'], '2');
assert(response.rawHeaders.indexOf('Test') !== -1);
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
s.close();
});
response.resume();

2
test/parallel/test-https-byteswritten.js

@ -18,7 +18,7 @@ var body = 'hello world\n';
var httpsServer = https.createServer(options, function(req, res) {
res.on('finish', function() {
assert(typeof req.connection.bytesWritten === 'number');
assert.strictEqual(typeof req.connection.bytesWritten, 'number');
assert(req.connection.bytesWritten > 0);
httpsServer.close();
console.log('ok');

5
test/parallel/test-internal-modules.js

@ -7,4 +7,7 @@ assert.throws(function() {
require('internal/freelist');
});
assert(require(path.join(common.fixturesDir, 'internal-modules')) === 42);
assert.strictEqual(
require(path.join(common.fixturesDir, 'internal-modules')),
42
);

2
test/parallel/test-process-config.js

@ -8,7 +8,7 @@ var path = require('path');
assert(process.hasOwnProperty('config'));
// ensure that `process.config` is an Object
assert(Object(process.config) === process.config);
assert.strictEqual(Object(process.config), process.config);
var configPath = path.resolve(__dirname, '..', '..', 'config.gypi');
var config = fs.readFileSync(configPath, 'utf8');

2
test/parallel/test-process-getgroups.js

@ -22,5 +22,5 @@ if (typeof process.getgroups === 'function') {
}
function check(a, b) {
for (var i = 0; i < a.length; ++i) assert(b.indexOf(a[i]) !== -1);
for (var i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1);
}

2
test/parallel/test-repl-context.js

@ -19,7 +19,7 @@ function testContext(repl) {
assert(context.console instanceof require('console').Console);
// ensure that the repl's global property is the context
assert(context.global === context);
assert.strictEqual(context.global, context);
// ensure that the repl console instance does not have a setter
assert.throws(() => context.console = 'foo');

2
test/parallel/test-require-json.js

@ -8,5 +8,5 @@ try {
} catch (err) {
var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/;
var i = err.message.match(re);
assert(null !== i, 'require() json error should include path');
assert.notStrictEqual(null, i, 'require() json error should include path');
}

4
test/parallel/test-stream-duplex.js

@ -27,6 +27,6 @@ stream.push({ val: 1 });
stream.end({ val: 2 });
process.on('exit', function() {
assert(read.val === 1);
assert(written.val === 2);
assert.strictEqual(read.val, 1);
assert.strictEqual(written.val, 2);
});

12
test/parallel/test-stream-transform-split-objectmode.js

@ -8,8 +8,8 @@ var parser = new Transform({ readableObjectMode: true });
assert(parser._readableState.objectMode);
assert(!parser._writableState.objectMode);
assert(parser._readableState.highWaterMark === 16);
assert(parser._writableState.highWaterMark === (16 * 1024));
assert.strictEqual(parser._readableState.highWaterMark, 16);
assert.strictEqual(parser._writableState.highWaterMark, 16 * 1024);
parser._transform = function(chunk, enc, callback) {
callback(null, { val: chunk[0] });
@ -24,7 +24,7 @@ parser.on('data', function(obj) {
parser.end(Buffer.from([42]));
process.on('exit', function() {
assert(parsed.val === 42);
assert.strictEqual(parsed.val, 42);
});
@ -32,8 +32,8 @@ var serializer = new Transform({ writableObjectMode: true });
assert(!serializer._readableState.objectMode);
assert(serializer._writableState.objectMode);
assert(serializer._readableState.highWaterMark === (16 * 1024));
assert(serializer._writableState.highWaterMark === 16);
assert.strictEqual(serializer._readableState.highWaterMark, 16 * 1024);
assert.strictEqual(serializer._writableState.highWaterMark, 16);
serializer._transform = function(obj, _, callback) {
callback(null, Buffer.from([obj.val]));
@ -48,5 +48,5 @@ serializer.on('data', function(chunk) {
serializer.write({ val: 42 });
process.on('exit', function() {
assert(serialized[0] === 42);
assert.strictEqual(serialized[0], 42);
});

2
test/parallel/test-stream2-writable.js

@ -168,7 +168,7 @@ test('write no bufferize', function(t) {
});
tw._write = function(chunk, encoding, cb) {
assert(typeof chunk === 'string');
assert.strictEqual(typeof chunk, 'string');
chunk = Buffer.from(chunk, encoding);
return TestWriter.prototype._write.call(this, chunk, encoding, cb);
};

2
test/parallel/test-timers-active.js

@ -13,7 +13,7 @@ legitTimers.forEach(function(legit) {
const savedTimeout = legit._idleTimeout;
active(legit);
// active() should mutate these objects
assert(legit._idleTimeout === savedTimeout);
assert.strictEqual(legit._idleTimeout, savedTimeout);
assert(Number.isInteger(legit._idleStart));
assert(legit._idleNext);
assert(legit._idlePrev);

2
test/parallel/test-tls-alert-handling.js

@ -86,6 +86,6 @@ function sendBADTLSRecord() {
}
process.on('exit', function() {
assert(iter === max_iter);
assert.strictEqual(iter, max_iter);
assert(success);
});

6
test/parallel/test-tls-pfx-gh-5100-regr.js

@ -21,7 +21,11 @@ const server = tls.createServer({
requestCert: true,
rejectUnauthorized: false
}, common.mustCall(function(c) {
assert(c.authorizationError === null, 'authorizationError must be null');
assert.strictEqual(
c.authorizationError,
null,
'authorizationError must be null'
);
c.end();
})).listen(0, function() {
var client = tls.connect({

2
test/parallel/test-tls-server-connection-server.js

@ -24,7 +24,7 @@ const server = tls.createServer(options, function(s) {
};
server.on('connection', common.mustCall(function(socket) {
assert(socket.server === server);
assert.strictEqual(socket.server, server);
server.close();
}));

4
test/parallel/test-url.js

@ -1663,5 +1663,5 @@ var throws = [
for (let i = 0; i < throws.length; i++) {
assert.throws(function() { url.format(throws[i]); }, TypeError);
}
assert(url.format('') === '');
assert(url.format({}) === '');
assert.strictEqual(url.format(''), '');
assert.strictEqual(url.format({}), '');

8
test/parallel/test-vm-harmony-symbols.js

@ -6,11 +6,11 @@ var vm = require('vm');
// The sandbox should have its own Symbol constructor.
var sandbox = {};
vm.runInNewContext('this.Symbol = Symbol', sandbox);
assert(typeof sandbox.Symbol === 'function');
assert(sandbox.Symbol !== Symbol);
assert.strictEqual(typeof sandbox.Symbol, 'function');
assert.notStrictEqual(sandbox.Symbol, Symbol);
// Unless we copy the Symbol constructor explicitly, of course.
sandbox = { Symbol: Symbol };
vm.runInNewContext('this.Symbol = Symbol', sandbox);
assert(typeof sandbox.Symbol === 'function');
assert(sandbox.Symbol === Symbol);
assert.strictEqual(typeof sandbox.Symbol, 'function');
assert.strictEqual(sandbox.Symbol, Symbol);

8
test/parallel/test-vm-proxies.js

@ -8,11 +8,11 @@ var vm = require('vm');
// context. Make sure that the new context has a Proxy object of its own.
var sandbox = {};
vm.runInNewContext('this.Proxy = Proxy', sandbox);
assert(typeof sandbox.Proxy === 'function');
assert(sandbox.Proxy !== Proxy);
assert.strictEqual(typeof sandbox.Proxy, 'function');
assert.notStrictEqual(sandbox.Proxy, Proxy);
// Unless we copy the Proxy object explicitly, of course.
sandbox = { Proxy: Proxy };
vm.runInNewContext('this.Proxy = Proxy', sandbox);
assert(typeof sandbox.Proxy === 'function');
assert(sandbox.Proxy === Proxy);
assert.strictEqual(typeof sandbox.Proxy, 'function');
assert.strictEqual(sandbox.Proxy, Proxy);

6
test/pummel/test-net-connect-memleak.js

@ -5,7 +5,11 @@ var common = require('../common');
var assert = require('assert');
var net = require('net');
assert(typeof global.gc === 'function', 'Run this test with --expose-gc');
assert.strictEqual(
typeof global.gc,
'function',
'Run this test with --expose-gc'
);
net.createServer(function() {}).listen(common.PORT);
var before = 0;

6
test/pummel/test-tls-connect-memleak.js

@ -12,7 +12,11 @@ var tls = require('tls');
var fs = require('fs');
assert(typeof global.gc === 'function', 'Run this test with --expose-gc');
assert.strictEqual(
typeof global.gc,
'function',
'Run this test with --expose-gc'
);
tls.createServer({
cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'),

6
test/pummel/test-tls-session-timeout.js

@ -99,12 +99,12 @@ function doTest() {
server.listen(common.PORT, function() {
Client(function(connectionType) {
assert(connectionType === 'New');
assert.strictEqual(connectionType, 'New');
Client(function(connectionType) {
assert(connectionType === 'Reused');
assert.strictEqual(connectionType, 'Reused');
setTimeout(function() {
Client(function(connectionType) {
assert(connectionType === 'New');
assert.strictEqual(connectionType, 'New');
server.close();
});
}, (SESSION_TIMEOUT + 1) * 1000);

2
test/sequential/test-child-process-emfile.js

@ -31,7 +31,7 @@ for (;;) {
try {
openFds.push(fs.openSync(__filename, 'r'));
} catch (err) {
assert(err.code === 'EMFILE');
assert.strictEqual(err.code, 'EMFILE');
break;
}
}

2
test/sequential/test-child-process-fork-getconnections.js

@ -75,7 +75,7 @@ if (process.argv[2] === 'child') {
}
child.once('message', function(m) {
assert(m.status === 'closed');
assert.strictEqual(m.status, 'closed');
server.getConnections(function(err, num) {
closeSockets(i + 1);
});

39
tools/eslint-rules/prefer-assert-methods.js

@ -0,0 +1,39 @@
'use strict';
function isAssert(node) {
return node.expression &&
node.expression.type === 'CallExpression' &&
node.expression.callee &&
node.expression.callee.name === 'assert';
}
function getFirstArg(expression) {
return expression.arguments && expression.arguments[0];
}
function parseError(method, op) {
return `'assert.${method}' should be used instead of '${op}'`;
}
const preferedAssertMethod = {
'===': 'strictEqual',
'!==': 'notStrictEqual',
'==': 'equal',
'!=': 'notEqual'
};
module.exports = function(context) {
return {
ExpressionStatement(node) {
if (isAssert(node)) {
const arg = getFirstArg(node.expression);
if (arg && arg.type === 'BinaryExpression') {
const assertMethod = preferedAssertMethod[arg.operator];
if (assertMethod) {
context.report(node, parseError(assertMethod, arg.operator));
}
}
}
}
};
};
Loading…
Cancel
Save