From 847e589977e890afe6dc3526be043f7f66e3f0a5 Mon Sep 17 00:00:00 2001 From: Duy Le Date: Thu, 1 Dec 2016 08:00:27 -0800 Subject: [PATCH] remove var and use let and const remove assert.equal to use assert.strictEqual new unit test for requiring an invalid package --- test/parallel/test-child-process-kill.js | 12 +++++------ test/parallel/test-net-reconnect-error.js | 20 +++++++++---------- test/parallel/test-require-invalid-package.js | 9 +++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 test/parallel/test-require-invalid-package.js diff --git a/test/parallel/test-child-process-kill.js b/test/parallel/test-child-process-kill.js index 9f6f8f6e796196..758129e1062c27 100644 --- a/test/parallel/test-child-process-kill.js +++ b/test/parallel/test-child-process-kill.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var cat = spawn(common.isWindows ? 'cmd' : 'cat'); +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; +const cat = spawn(common.isWindows ? 'cmd' : 'cat'); cat.stdout.on('end', common.mustCall(function() {})); cat.stderr.on('data', common.fail); @@ -13,6 +13,6 @@ cat.on('exit', common.mustCall(function(code, signal) { assert.strictEqual(signal, 'SIGTERM'); })); -assert.equal(cat.killed, false); +assert.strictEqual(cat.killed, false); cat.kill(); -assert.equal(cat.killed, true); +assert.strictEqual(cat.killed, true); diff --git a/test/parallel/test-net-reconnect-error.js b/test/parallel/test-net-reconnect-error.js index 4e322bd09d2914..4e1e3d14984e80 100644 --- a/test/parallel/test-net-reconnect-error.js +++ b/test/parallel/test-net-reconnect-error.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); -var N = 20; -var client_error_count = 0; -var disconnect_count = 0; +const common = require('../common'); +const net = require('net'); +const assert = require('assert'); +const N = 20; +let client_error_count = 0; +let disconnect_count = 0; // Hopefully nothing is running on common.PORT -var c = net.createConnection(common.PORT); +const c = net.createConnection(common.PORT); c.on('connect', function() { console.error('CLIENT connected'); @@ -17,7 +17,7 @@ c.on('connect', function() { c.on('error', function(e) { console.error('CLIENT error: ' + e.code); client_error_count++; - assert.equal('ECONNREFUSED', e.code); + assert.strictEqual('ECONNREFUSED', e.code); }); c.on('close', function() { @@ -27,6 +27,6 @@ c.on('close', function() { }); process.on('exit', function() { - assert.equal(N + 1, disconnect_count); - assert.equal(N + 1, client_error_count); + assert.strictEqual(N + 1, disconnect_count); + assert.strictEqual(N + 1, client_error_count); }); diff --git a/test/parallel/test-require-invalid-package.js b/test/parallel/test-require-invalid-package.js new file mode 100644 index 00000000000000..45272cf5c3af9a --- /dev/null +++ b/test/parallel/test-require-invalid-package.js @@ -0,0 +1,9 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +// Should be an invalid package path. +assert.throws(() => require('package.json'), (err) => { + return err && err.code === 'MODULE_NOT_FOUND'; +});