From 5c9aa1848404084a7c2398348a719d95c6048004 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 28 Oct 2016 16:42:38 -0700 Subject: [PATCH] constants: errors -> errno lib/constants.js was incorrectly copying the constants from the binding, by copying from `contants.os.errors` instead of `constants.os.errno`. PR-URL: https://github.com/nodejs/node/pull/9349 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Prince John Wesley Reviewed-By: Ron Korving Reviewed-By: Luigi Pinca --- lib/constants.js | 2 +- test/parallel/test-constants.js | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index deebf90513da46..fec7e13d94145a 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -5,7 +5,7 @@ // are most relevant. const constants = process.binding('constants'); Object.assign(exports, - constants.os.errors, + constants.os.errno, constants.os.signals, constants.fs, constants.crypto); diff --git a/test/parallel/test-constants.js b/test/parallel/test-constants.js index ea0b93ba7fab6a..c11935783f861d 100644 --- a/test/parallel/test-constants.js +++ b/test/parallel/test-constants.js @@ -1,12 +1,26 @@ 'use strict'; require('../common'); -const constants = process.binding('constants'); +const binding = process.binding('constants'); +const constants = require('constants'); const assert = require('assert'); -assert.ok(constants); -assert.ok(constants.os); -assert.ok(constants.os.signals); -assert.ok(constants.os.errno); -assert.ok(constants.fs); -assert.ok(constants.crypto); +assert.ok(binding); +assert.ok(binding.os); +assert.ok(binding.os.signals); +assert.ok(binding.os.errno); +assert.ok(binding.fs); +assert.ok(binding.crypto); + +['os', 'fs', 'crypto'].forEach((l) => { + Object.keys(binding[l]).forEach((k) => { + if (typeof binding[l][k] === 'object') { // errno and signals + Object.keys(binding[l][k]).forEach((j) => { + assert.strictEqual(binding[l][k][j], constants[j]); + }); + } + if (l !== 'os') { // top level os constant isn't currently copied + assert.strictEqual(binding[l][k], constants[k]); + } + }); +});