Bug 1246896 - Add some basic tests for ESLint rule mozilla/no-cpows-in-tests.js. r=florian

MozReview-Commit-ID: 2tZS1GYUUbH

--HG--
extra : rebase_source : 9feff09ef0305e67b3580c6260740ccdbfa699c4
This commit is contained in:
Mark Banner 2017-10-13 16:10:36 +01:00
Родитель 0555fa0126
Коммит 272b0102c2
1 изменённых файлов: 42 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,42 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-cpows-in-tests");
var RuleTester = require("eslint/lib/testers/rule-tester");
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
function wrapCode(code, filename = "browser_fake.js") {
return {code, filename};
}
function invalidCode(code, item) {
let message = `${item} is a possible Cross Process Object Wrapper (CPOW).`;
let obj = wrapCode(code);
obj.errors = [{message, type: "MemberExpression"}];
return obj;
}
ruleTester.run("no-cpows-in-tests", rule, {
valid: [
"window.document",
wrapCode("ContentTask.spawn(browser, null, () => { content.document; });")
],
invalid: [
invalidCode("let x = gBrowser.contentWindow;", "gBrowser.contentWindow"),
invalidCode("let x = gBrowser.contentDocument;", "gBrowser.contentDocument"),
invalidCode("let x = gBrowser.selectedBrowser.contentWindow;", "gBrowser.selectedBrowser.contentWindow"),
invalidCode("let x = browser.contentDocument;", "browser.contentDocument"),
invalidCode("let x = window.content;", "window.content")
]
});