Skip to content

Commit

Permalink
test: improve console tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed Jan 17, 2018
1 parent b7ce7b3 commit 1193065
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
38 changes: 21 additions & 17 deletions test/parallel/test-console-assign-undefined.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
'use strict';

// Should be above require, because code in require read console
// what we are trying to avoid
// set should be earlier than get
// Patch global.console before importing modules that may modify the console
// object.

global.console = undefined;
const tmp = global.console;
global.console = 42;

// Initially, the `console` variable is `undefined`, since console will be
// lazily loaded in the getter.

require('../common');
const common = 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.
// Originally the console had a getter. Test twice to verify it had no side
// effect.
assert.strictEqual(global.console, 42);
assert.strictEqual(global.console, 42);

assert.strictEqual(global.console, undefined, 'first read');
assert.strictEqual(global.console, undefined, 'second read');
common.expectsError(
() => console.log('foo'),
{
type: TypeError,
message: 'console.log is not a function'
}
);

global.console = 1;
assert.strictEqual(global.console, 1, 'set true-like primitive');
assert.strictEqual(global.console, 1);
assert.strictEqual(console, 1);

global.console = 0;
assert.strictEqual(global.console, 0, 'set false-like primitive, again');
// Reset the console
global.console = tmp;
console.log('foo');
19 changes: 11 additions & 8 deletions test/parallel/test-console-is-a-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ assert.doesNotThrow(() => {

const self = global;

/* eslint-disable */
/* The following tests are copied from */
/* eslint-disable quotes, max-len */

/* The following tests should not be modified as they are copied */
/* 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
Expand All @@ -38,12 +39,14 @@ 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);

// test(() => {
// const prototype1 = Object.getPrototypeOf(console);
// const prototype2 = Object.getPrototypeOf(prototype1);
// This got commented out from the original test because in Node.js all
// functions are declared on the prototype.
// 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 */

0 comments on commit 1193065

Please sign in to comment.