Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using strictEquals instead of equals #9873

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const assert = require('assert');
assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable);
// Support legacy API
assert.equal('number', typeof process.stdout.fd);
assert.equal('number', typeof process.stderr.fd);
assert.strictEqual('number', typeof process.stdout.fd);
assert.strictEqual('number', typeof process.stderr.fd);

assert.doesNotThrow(function() {
process.once('warning', common.mustCall((warning) => {
Expand Down Expand Up @@ -35,28 +35,28 @@ global.process.stderr.write = function(string) {
errStrings.push(string);
};

// test console.log()
// test console.log() goes to stdout
console.log('foo');
console.log('foo', 'bar');
console.log('%s %s', 'foo', 'bar', 'hop');
console.log({slashes: '\\\\'});
console.log(custom_inspect);

// test console.info()
// test console.info() goes to stdout
console.info('foo');
console.info('foo', 'bar');
console.info('%s %s', 'foo', 'bar', 'hop');
console.info({slashes: '\\\\'});
console.info(custom_inspect);

// test console.error()
// test console.error() goes to stderr
console.error('foo');
console.error('foo', 'bar');
console.error('%s %s', 'foo', 'bar', 'hop');
console.error({slashes: '\\\\'});
console.error(custom_inspect);

// test console.warn()
// test console.warn() goes to stderr
console.warn('foo');
console.warn('foo', 'bar');
console.warn('%s %s', 'foo', 'bar', 'hop');
Expand Down Expand Up @@ -102,29 +102,31 @@ const expectedStrings = [
];

for (const expected of expectedStrings) {
assert.equal(expected + '\n', strings.shift()); // console.log (stdout)
assert.equal(expected + '\n', errStrings.shift()); // console.error (stderr)
assert.strictEqual(expected + '\n', strings.shift());
assert.strictEqual(expected + '\n', errStrings.shift());
}

for (const expected of expectedStrings) {
assert.equal(expected + '\n', strings.shift()); // console.info (stdout)
assert.equal(expected + '\n', errStrings.shift()); // console.warn (stderr)
assert.strictEqual(expected + '\n', strings.shift());
assert.strictEqual(expected + '\n', errStrings.shift());
}

assert.equal("{ foo: 'bar', inspect: [Function: inspect] }\n", strings.shift());
assert.equal("{ foo: 'bar', inspect: [Function: inspect] }\n", strings.shift());
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
strings.shift());
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n",
strings.shift());
assert.notEqual(-1, strings.shift().indexOf('foo: [Object]'));
assert.equal(-1, strings.shift().indexOf('baz'));
assert.strictEqual(-1, strings.shift().indexOf('baz'));
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^hasOwnProperty: \d+\.\d{3}ms$/.test(strings.shift().trim()));

assert.equal('Trace: This is a {"formatted":"trace"} 10 foo',
errStrings.shift().split('\n').shift());
assert.strictEqual('Trace: This is a {"formatted":"trace"} 10 foo',
errStrings.shift().split('\n').shift());

assert.equal(strings.length, 0);
assert.equal(errStrings.length, 0);
assert.strictEqual(strings.length, 0);
assert.strictEqual(errStrings.length, 0);

assert.throws(() => {
console.assert(false, 'should throw');
Expand Down