Skip to content

Commit

Permalink
test: refactor test-console
Browse files Browse the repository at this point in the history
assert.equal() -> assert.strictEqual()

PR-URL: nodejs#9873
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Matt Crummey authored and Jonathan Darling committed Dec 8, 2016
1 parent bd91ef7 commit b1553a2
Showing 1 changed file with 19 additions and 17 deletions.
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

0 comments on commit b1553a2

Please sign in to comment.