summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorwandalen <wandalen.me@gmail.com>2017-04-17 04:36:45 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-18 18:12:21 +0100
commit6ff52b69cc6b3fd05aa332623cbc49c5d3eb7ece (patch)
tree0dc8f4db4b0963b075b641944e08ebb0e2212d60 /test
parente99ae7764d9fe77fb7ecadc180c55664ebfd4f19 (diff)
downloadandroid-node-v8-6ff52b69cc6b3fd05aa332623cbc49c5d3eb7ece.tar.gz
android-node-v8-6ff52b69cc6b3fd05aa332623cbc49c5d3eb7ece.tar.bz2
android-node-v8-6ff52b69cc6b3fd05aa332623cbc49c5d3eb7ece.zip
test: add standard console tests
This imports a standard test from w3c/web-platform-tests (console-is-a-namespace). 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>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-console-assign-undefined.js27
-rw-r--r--test/parallel/test-console-is-a-namespace.js49
2 files changed, 76 insertions, 0 deletions
diff --git a/test/parallel/test-console-assign-undefined.js b/test/parallel/test-console-assign-undefined.js
new file mode 100644
index 0000000000..83afcb70c3
--- /dev/null
+++ b/test/parallel/test-console-assign-undefined.js
@@ -0,0 +1,27 @@
+'use strict';
+
+// Should be above require, because code in require read console
+// what we are trying to avoid
+// set should be earlier than get
+
+global.console = undefined;
+
+// Initially, the `console` variable is `undefined`, since console will be
+// lazily loaded in the getter.
+
+require('../common');
+const assert = require('assert');
+
+// global.console's getter is called
+// Since the `console` cache variable is `undefined` and therefore false-y,
+// the getter still calls NativeModule.require() and returns the object
+// obtained from it, instead of returning `undefined` as expected.
+
+assert.strictEqual(global.console, undefined, 'first read');
+assert.strictEqual(global.console, undefined, 'second read');
+
+global.console = 1;
+assert.strictEqual(global.console, 1, 'set true-like primitive');
+
+global.console = 0;
+assert.strictEqual(global.console, 0, 'set false-like primitive, again');
diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js
new file mode 100644
index 0000000000..f413000805
--- /dev/null
+++ b/test/parallel/test-console-is-a-namespace.js
@@ -0,0 +1,49 @@
+'use strict';
+
+require('../common');
+
+const assert = require('assert');
+const { test, assert_equals, assert_true, assert_false } =
+ require('../common/wpt');
+
+assert.doesNotThrow(() => {
+ global.console = global.console;
+});
+
+const self = global;
+
+/* eslint-disable */
+/* The following tests are copied from */
+/* WPT Refs:
+ 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
+*/
+
+// https://heycam.github.io/webidl/#es-namespaces
+// https://console.spec.whatwg.org/#console-namespace
+
+test(() => {
+ assert_true(self.hasOwnProperty("console"));
+}, "console exists on the global object");
+
+test(() => {
+ const propDesc = Object.getOwnPropertyDescriptor(self, "console");
+ assert_equals(propDesc.writable, true, "must be writable");
+ assert_equals(propDesc.enumerable, false, "must not be enumerable");
+ assert_equals(propDesc.configurable, true, "must be configurable");
+ assert_equals(propDesc.value, console, "must have the right value");
+}, "console has the right property descriptors");
+
+test(() => {
+ assert_false("Console" in self);
+}, "Console (uppercase, as if it were an interface) must not exist");
+
+
+// test(() => {
+// const prototype1 = Object.getPrototypeOf(console);
+// 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");
+/* eslint-enable */