0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-console-count.js
Rich Trott 90c9b162fe test: make test-console-count engine agnostic
Do not check the error message if it is generated by the JavaScript
engine (V8, ChakraCore, etc.). Do confirm that it is a `TypeError`.

PR-URL: https://github.com/nodejs/node/pull/16272
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-11-11 17:40:17 -08:00

66 lines
1.4 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const stdoutWrite = process.stdout.write;
let buf = '';
process.stdout.write = (string) => buf = string;
console.count();
assert.strictEqual(buf, 'default: 1\n');
// 'default' and undefined are equivalent
console.count('default');
assert.strictEqual(buf, 'default: 2\n');
console.count('a');
assert.strictEqual(buf, 'a: 1\n');
console.count('b');
assert.strictEqual(buf, 'b: 1\n');
console.count('a');
assert.strictEqual(buf, 'a: 2\n');
console.count();
assert.strictEqual(buf, 'default: 3\n');
console.count({});
assert.strictEqual(buf, '[object Object]: 1\n');
console.count(1);
assert.strictEqual(buf, '1: 1\n');
console.count(null);
assert.strictEqual(buf, 'null: 1\n');
console.count('null');
assert.strictEqual(buf, 'null: 2\n');
console.countReset();
console.count();
assert.strictEqual(buf, 'default: 1\n');
console.countReset('a');
console.count('a');
assert.strictEqual(buf, 'a: 1\n');
// countReset('a') only reset the a counter
console.count();
assert.strictEqual(buf, 'default: 2\n');
process.stdout.write = stdoutWrite;
// Symbol labels do not work. Only check that the `Error` is a `TypeError`. Do
// not check the message because it is different depending on the JavaScript
// engine.
assert.throws(
() => console.count(Symbol('test')),
TypeError);
assert.throws(
() => console.countReset(Symbol('test')),
TypeError);