test: improve console tests
PR-URL: https://github.com/nodejs/node/pull/17708 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
parent
6ff52b69cc
commit
7809f386b0
@ -1,27 +1,31 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Should be above require, because code in require read console
|
// Patch global.console before importing modules that may modify the console
|
||||||
// what we are trying to avoid
|
// object.
|
||||||
// set should be earlier than get
|
|
||||||
|
|
||||||
global.console = undefined;
|
const tmp = global.console;
|
||||||
|
global.console = 42;
|
||||||
|
|
||||||
// Initially, the `console` variable is `undefined`, since console will be
|
const common = require('../common');
|
||||||
// lazily loaded in the getter.
|
|
||||||
|
|
||||||
require('../common');
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
// global.console's getter is called
|
// Originally the console had a getter. Test twice to verify it had no side
|
||||||
// Since the `console` cache variable is `undefined` and therefore false-y,
|
// effect.
|
||||||
// the getter still calls NativeModule.require() and returns the object
|
assert.strictEqual(global.console, 42);
|
||||||
// obtained from it, instead of returning `undefined` as expected.
|
assert.strictEqual(global.console, 42);
|
||||||
|
|
||||||
assert.strictEqual(global.console, undefined, 'first read');
|
common.expectsError(
|
||||||
assert.strictEqual(global.console, undefined, 'second read');
|
() => console.log('foo'),
|
||||||
|
{
|
||||||
|
type: TypeError,
|
||||||
|
message: 'console.log is not a function'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
global.console = 1;
|
global.console = 1;
|
||||||
assert.strictEqual(global.console, 1, 'set true-like primitive');
|
assert.strictEqual(global.console, 1);
|
||||||
|
assert.strictEqual(console, 1);
|
||||||
|
|
||||||
global.console = 0;
|
// Reset the console
|
||||||
assert.strictEqual(global.console, 0, 'set false-like primitive, again');
|
global.console = tmp;
|
||||||
|
console.log('foo');
|
||||||
|
@ -12,8 +12,9 @@ assert.doesNotThrow(() => {
|
|||||||
|
|
||||||
const self = global;
|
const self = global;
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable quotes, max-len */
|
||||||
/* The following tests are copied from */
|
|
||||||
|
/* The following tests should not be modified as they are copied */
|
||||||
/* WPT Refs:
|
/* WPT Refs:
|
||||||
https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js
|
https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js
|
||||||
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
|
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
|
||||||
@ -38,12 +39,14 @@ test(() => {
|
|||||||
assert_false("Console" in self);
|
assert_false("Console" in self);
|
||||||
}, "Console (uppercase, as if it were an interface) must not exist");
|
}, "Console (uppercase, as if it were an interface) must not exist");
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const prototype1 = Object.getPrototypeOf(console);
|
||||||
|
const prototype2 = Object.getPrototypeOf(prototype1);
|
||||||
|
|
||||||
// test(() => {
|
// This got commented out from the original test because in Node.js all
|
||||||
// const prototype1 = Object.getPrototypeOf(console);
|
// functions are declared on the prototype.
|
||||||
// const prototype2 = Object.getPrototypeOf(prototype1);
|
// assert_equals(Object.getOwnPropertyNames(prototype1).length, 0, "The [[Prototype]] must have no properties");
|
||||||
|
assert_equals(prototype2, Object.prototype, "The [[Prototype]]'s [[Prototype]] must be %ObjectPrototype%");
|
||||||
|
}, "The prototype chain must be correct");
|
||||||
|
|
||||||
// assert_equals(Object.getOwnPropertyNames(prototype1).length, 0, "The [[Prototype]] must have no properties");
|
|
||||||
// assert_equals(prototype2, Object.prototype, "The [[Prototype]]'s [[Prototype]] must be %ObjectPrototype%");
|
|
||||||
// }, "The prototype chain must be correct");
|
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user