diff options
author | James M Snell <jasnell@gmail.com> | 2017-04-26 12:42:18 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-02 08:23:07 -0700 |
commit | cc43c8fb54c872fbce2a795d089aa111eccdfb89 (patch) | |
tree | deb7967091a3c733746727ba1777164a7d7f4707 /test/parallel/test-console-count.js | |
parent | 98bae2930453d40dadf3f36f5ad89eb73b23ef3a (diff) | |
download | android-node-v8-cc43c8fb54c872fbce2a795d089aa111eccdfb89.tar.gz android-node-v8-cc43c8fb54c872fbce2a795d089aa111eccdfb89.tar.bz2 android-node-v8-cc43c8fb54c872fbce2a795d089aa111eccdfb89.zip |
console: add console.count() and console.clear()
Both are simple utility functions defined by the WHATWG
console spec (https://console.spec.whatwg.org/).
PR-URL: https://github.com/nodejs/node/pull/12678
Ref: https://github.com/nodejs/node/issues/12675
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test/parallel/test-console-count.js')
-rw-r--r-- | test/parallel/test-console-count.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/parallel/test-console-count.js b/test/parallel/test-console-count.js new file mode 100644 index 0000000000..64e2641f0a --- /dev/null +++ b/test/parallel/test-console-count.js @@ -0,0 +1,63 @@ +'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 +assert.throws( + () => console.count(Symbol('test')), + /^TypeError: Cannot convert a Symbol value to a string$/); +assert.throws( + () => console.countReset(Symbol('test')), + /^TypeError: Cannot convert a Symbol value to a string$/); |