Skip to content

Commit 6ff52b6

Browse files
WandalenBridgeAR
authored andcommitted
test: add standard console tests
This imports a standard test from w3c/web-platform-tests (console-is-a-namespace). PR-URL: #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>
1 parent e99ae77 commit 6ff52b6

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
// Should be above require, because code in require read console
4+
// what we are trying to avoid
5+
// set should be earlier than get
6+
7+
global.console = undefined;
8+
9+
// Initially, the `console` variable is `undefined`, since console will be
10+
// lazily loaded in the getter.
11+
12+
require('../common');
13+
const assert = require('assert');
14+
15+
// global.console's getter is called
16+
// Since the `console` cache variable is `undefined` and therefore false-y,
17+
// the getter still calls NativeModule.require() and returns the object
18+
// obtained from it, instead of returning `undefined` as expected.
19+
20+
assert.strictEqual(global.console, undefined, 'first read');
21+
assert.strictEqual(global.console, undefined, 'second read');
22+
23+
global.console = 1;
24+
assert.strictEqual(global.console, 1, 'set true-like primitive');
25+
26+
global.console = 0;
27+
assert.strictEqual(global.console, 0, 'set false-like primitive, again');
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const { test, assert_equals, assert_true, assert_false } =
7+
require('../common/wpt');
8+
9+
assert.doesNotThrow(() => {
10+
global.console = global.console;
11+
});
12+
13+
const self = global;
14+
15+
/* eslint-disable */
16+
/* The following tests are copied from */
17+
/* WPT Refs:
18+
https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js
19+
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
20+
*/
21+
22+
// https://heycam.github.io/webidl/#es-namespaces
23+
// https://console.spec.whatwg.org/#console-namespace
24+
25+
test(() => {
26+
assert_true(self.hasOwnProperty("console"));
27+
}, "console exists on the global object");
28+
29+
test(() => {
30+
const propDesc = Object.getOwnPropertyDescriptor(self, "console");
31+
assert_equals(propDesc.writable, true, "must be writable");
32+
assert_equals(propDesc.enumerable, false, "must not be enumerable");
33+
assert_equals(propDesc.configurable, true, "must be configurable");
34+
assert_equals(propDesc.value, console, "must have the right value");
35+
}, "console has the right property descriptors");
36+
37+
test(() => {
38+
assert_false("Console" in self);
39+
}, "Console (uppercase, as if it were an interface) must not exist");
40+
41+
42+
// test(() => {
43+
// const prototype1 = Object.getPrototypeOf(console);
44+
// const prototype2 = Object.getPrototypeOf(prototype1);
45+
46+
// assert_equals(Object.getOwnPropertyNames(prototype1).length, 0, "The [[Prototype]] must have no properties");
47+
// assert_equals(prototype2, Object.prototype, "The [[Prototype]]'s [[Prototype]] must be %ObjectPrototype%");
48+
// }, "The prototype chain must be correct");
49+
/* eslint-enable */

0 commit comments

Comments
 (0)