From d4f25ed6567f091407f2017bb0273150474b1324 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 8 Oct 2018 13:17:32 -0700 Subject: [PATCH] test: add WPT console-label-conversion test Add console-label-conversion.any.js from WPT to the test suite. PR-URL: https://github.com/nodejs/node/pull/23340 Reviewed-By: Richard Lau Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Colin Ihrig --- .../test-whatwg-console-label-conversion.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/parallel/test-whatwg-console-label-conversion.js diff --git a/test/parallel/test-whatwg-console-label-conversion.js b/test/parallel/test-whatwg-console-label-conversion.js new file mode 100644 index 00000000000000..74c6c007b0151a --- /dev/null +++ b/test/parallel/test-whatwg-console-label-conversion.js @@ -0,0 +1,45 @@ +'use strict'; + +require('../common'); + +const { test, assert_true, assert_throws } = + require('../common/wpt'); + +/* eslint-disable max-len, object-curly-spacing */ + +/* The following tests should not be modified as they are copied */ +/* WPT Refs: + https://github.com/web-platform-tests/wpt/blob/6f0a96ed650935b17b6e5d277889cfbe0ccc103e/console/console-label-conversion.any.js + License: hhttps://github.com/web-platform-tests/wpt/blob/6f0a96ed650935b17b6e5d277889cfbe0ccc103e/LICENSE.md +*/ + +// https://console.spec.whatwg/org/#counting +// https://console.spec.whatwg/org/#timing + +const methods = ['count', 'countReset', 'time', 'timeLog', 'timeEnd']; + +for (const method of methods) { + test(() => { + let labelToStringCalled = false; + + console[method]({ + toString() { + labelToStringCalled = true; + } + }); + + assert_true(labelToStringCalled, `${method}() must call toString() on label when label is an object`); + }, `console.${method}()'s label gets converted to string via label.toString() when label is an object`); + + test(() => { + assert_throws({name: 'Error'}, () => { + console[method]({ + toString() { + throw new Error('conversion error'); + } + }); + }, `${method} must re-throw any exceptions thrown by label.toString() conversion`); + }, `console.${method}() throws exceptions generated by erroneous label.toString() conversion`); +} + +/* eslint-enable */