diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /tools/lint/eslint/eslint-plugin-mozilla/tests/no-cu-reportError.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tools/lint/eslint/eslint-plugin-mozilla/tests/no-cu-reportError.js | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-cu-reportError.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-cu-reportError.js new file mode 100644 index 0000000000..6650c8bf4e --- /dev/null +++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-cu-reportError.js @@ -0,0 +1,100 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// ------------------------------------------------------------------------------ +// Requirements +// ------------------------------------------------------------------------------ + +var rule = require("../lib/rules/no-cu-reportError"); +var RuleTester = require("eslint").RuleTester; + +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } }); + +// ------------------------------------------------------------------------------ +// Tests +// ------------------------------------------------------------------------------ + +function callError() { + return [{ messageId: "useConsoleError", type: "CallExpression" }]; +} + +ruleTester.run("no-cu-reportError", rule, { + valid: [ + "console.error('foo')", + "Cu.cloneInto({}, {})", + "foo().catch(console.error)", + // TODO: Bug 1802347 - this should be treated as an error as well. + "Cu.reportError('foo', stack)", + ], + invalid: [ + { + code: "Cu.reportError('foo')", + output: "console.error('foo')", + errors: callError(), + }, + { + code: "Cu.reportError(bar)", + output: "console.error(bar)", + errors: callError(), + }, + { + code: "Cu.reportError(bar.stack)", + output: "console.error(bar.stack)", + errors: callError(), + }, + { + code: "foo().catch(Cu.reportError)", + output: "foo().catch(console.error)", + errors: callError(), + }, + { + code: "foo().then(bar, Cu.reportError)", + output: "foo().then(bar, console.error)", + errors: callError(), + }, + // When referencing identifiers/members, try to reference them rather + // than stringifying: + { + code: "Cu.reportError('foo' + e)", + output: "console.error('foo', e)", + errors: callError(), + }, + { + code: "Cu.reportError('foo' + msg.data)", + output: "console.error('foo', msg.data)", + errors: callError(), + }, + // Don't touch existing concatenation of literals (usually done for + // wrapping reasons) + { + code: "Cu.reportError('foo' + 'bar' + 'baz')", + output: "console.error('foo' + 'bar' + 'baz')", + errors: callError(), + }, + // Ensure things work when nested: + { + code: "Cu.reportError('foo' + e + 'baz')", + output: "console.error('foo', e, 'baz')", + errors: callError(), + }, + // Ensure things work when nested in different places: + { + code: "Cu.reportError('foo' + e + 'quux' + 'baz')", + output: "console.error('foo', e, 'quux' + 'baz')", + errors: callError(), + }, + { + code: "Cu.reportError('foo' + 'quux' + e + 'baz')", + output: "console.error('foo' + 'quux', e, 'baz')", + errors: callError(), + }, + // Ensure things work with parens changing order of operations: + { + code: "Cu.reportError('foo' + 'quux' + (e + 'baz'))", + output: "console.error('foo' + 'quux' + (e + 'baz'))", + errors: callError(), + }, + ], +}); |