Source code

Revision control

Copy as Markdown

Other Tools

/* Any copyright is dedicated to the Public Domain.
"use strict";
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require("../lib/rules/reject-eager-module-in-lazy-getter");
var RuleTester = require("eslint").RuleTester;
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } });
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
function invalidCode(code, uri) {
return { code, errors: [{ messageId: "eagerModule", data: { uri } }] };
}
ruleTester.run("reject-eager-module-in-lazy-getter", rule, {
valid: [
`
ChromeUtils.defineModuleGetter(
);
`,
`
XPCOMUtils.defineLazyModuleGetters(lazy, {
});
`,
`
ChromeUtils.defineESModuleGetters(lazy, {
Integration: "resource://gre/modules/Integration.sys.mjs",
});
`,
],
invalid: [
invalidCode(
`
ChromeUtils.defineModuleGetter(
);
`,
),
invalidCode(
`
XPCOMUtils.defineLazyModuleGetters(lazy, {
});
`,
),
invalidCode(
`
ChromeUtils.defineESModuleGetters(lazy, {
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
});
`,
"resource://gre/modules/AppConstants.sys.mjs"
),
],
});