mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 18:29:01 +00:00

In preparation for a lint rule that will enforce assert.deepStrictEqual() over assert.deepEqual(), change tests and benchmarks accordingly. For tests and benchmarks that are testing or benchmarking assert.deepEqual() itself, apply a comment to ignore the upcoming rule. PR-URL: https://github.com/nodejs/node/pull/6213 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
61 lines
2.1 KiB
JavaScript
61 lines
2.1 KiB
JavaScript
'use strict';
|
|
// Flags: --expose_internals
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const internalUtil = require('internal/util');
|
|
const spawnSync = require('child_process').spawnSync;
|
|
|
|
function getHiddenValue(obj, name) {
|
|
return function() {
|
|
internalUtil.getHiddenValue(obj, name);
|
|
};
|
|
}
|
|
|
|
function setHiddenValue(obj, name, val) {
|
|
return function() {
|
|
internalUtil.setHiddenValue(obj, name, val);
|
|
};
|
|
}
|
|
|
|
assert.throws(getHiddenValue(), /obj must be an object/);
|
|
assert.throws(getHiddenValue(null, 'foo'), /obj must be an object/);
|
|
assert.throws(getHiddenValue(undefined, 'foo'), /obj must be an object/);
|
|
assert.throws(getHiddenValue('bar', 'foo'), /obj must be an object/);
|
|
assert.throws(getHiddenValue(85, 'foo'), /obj must be an object/);
|
|
assert.throws(getHiddenValue({}), /name must be a string/);
|
|
assert.throws(getHiddenValue({}, null), /name must be a string/);
|
|
assert.throws(getHiddenValue({}, []), /name must be a string/);
|
|
assert.deepStrictEqual(internalUtil.getHiddenValue({}, 'foo'), undefined);
|
|
|
|
assert.throws(setHiddenValue(), /obj must be an object/);
|
|
assert.throws(setHiddenValue(null, 'foo'), /obj must be an object/);
|
|
assert.throws(setHiddenValue(undefined, 'foo'), /obj must be an object/);
|
|
assert.throws(setHiddenValue('bar', 'foo'), /obj must be an object/);
|
|
assert.throws(setHiddenValue(85, 'foo'), /obj must be an object/);
|
|
assert.throws(setHiddenValue({}), /name must be a string/);
|
|
assert.throws(setHiddenValue({}, null), /name must be a string/);
|
|
assert.throws(setHiddenValue({}, []), /name must be a string/);
|
|
const obj = {};
|
|
assert.strictEqual(internalUtil.setHiddenValue(obj, 'foo', 'bar'), true);
|
|
assert.strictEqual(internalUtil.getHiddenValue(obj, 'foo'), 'bar');
|
|
|
|
let arrowMessage;
|
|
|
|
try {
|
|
require('../fixtures/syntax/bad_syntax');
|
|
} catch (err) {
|
|
arrowMessage = internalUtil.getHiddenValue(err, 'node:arrowMessage');
|
|
}
|
|
|
|
assert(/bad_syntax\.js:1/.test(arrowMessage));
|
|
|
|
const args = [
|
|
'--expose-internals',
|
|
'-e',
|
|
"require('internal/util').error('foo %d', 5)"
|
|
];
|
|
const result = spawnSync(process.argv[0], args, { encoding: 'utf8' });
|
|
assert.strictEqual(result.stderr.indexOf('%'), -1);
|
|
assert(/foo 5/.test(result.stderr));
|