diff --git a/.eslintrc.js b/.eslintrc.js index c864fd4c35e7..8c46880ec648 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -739,7 +739,7 @@ module.exports = { "browser/components/newtab/content-src/components/DiscoveryStreamComponents/TopSites/TopSites.jsx ", "browser/components/newtab/content-src/components/TopSites/TopSiteForm.jsx ", "browser/components/newtab/lib/CFRMessageProvider.sys.mjs ", - "browser/components/newtab/lib/PlacesFeed.jsm ", + "browser/components/newtab/lib/PlacesFeed.sys.mjs ", "browser/components/originattributes/test/browser/browser_broadcastChannel.js", "browser/components/originattributes/test/browser/browser_cache.js", "browser/components/originattributes/test/browser/browser_favicon_firstParty.js", diff --git a/browser/components/newtab/karma.mc.config.js b/browser/components/newtab/karma.mc.config.js index 8696b8888e57..778869bac527 100644 --- a/browser/components/newtab/karma.mc.config.js +++ b/browser/components/newtab/karma.mc.config.js @@ -134,9 +134,9 @@ module.exports = function (config) { branches: 78, }, /** - * PlacesFeed.jsm is tested via an xpcshell test + * PlacesFeed.sys.mjs is tested via an xpcshell test */ - "lib/PlacesFeed.jsm": { + "lib/PlacesFeed.sys.mjs": { statements: 7, lines: 7, functions: 8, diff --git a/browser/components/newtab/lib/ActivityStream.jsm b/browser/components/newtab/lib/ActivityStream.jsm index c0ccfcb8f1f5..5610d8114a02 100644 --- a/browser/components/newtab/lib/ActivityStream.jsm +++ b/browser/components/newtab/lib/ActivityStream.jsm @@ -14,6 +14,7 @@ ChromeUtils.defineESModuleGetters(lazy, { DefaultPrefs: "resource://activity-stream/lib/ActivityStreamPrefs.sys.mjs", HighlightsFeed: "resource://activity-stream/lib/HighlightsFeed.sys.mjs", NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", + PlacesFeed: "resource://activity-stream/lib/PlacesFeed.sys.mjs", Region: "resource://gre/modules/Region.sys.mjs", TelemetryFeed: "resource://activity-stream/lib/TelemetryFeed.sys.mjs", }); @@ -43,11 +44,6 @@ ChromeUtils.defineModuleGetter( "RecommendationProvider", "resource://activity-stream/lib/RecommendationProvider.jsm" ); -ChromeUtils.defineModuleGetter( - lazy, - "PlacesFeed", - "resource://activity-stream/lib/PlacesFeed.jsm" -); ChromeUtils.defineModuleGetter( lazy, "PrefsFeed", diff --git a/browser/components/newtab/lib/PlacesFeed.jsm b/browser/components/newtab/lib/PlacesFeed.sys.mjs similarity index 97% rename from browser/components/newtab/lib/PlacesFeed.jsm rename to browser/components/newtab/lib/PlacesFeed.sys.mjs index a446e8111881..5120f9b4f5b5 100644 --- a/browser/components/newtab/lib/PlacesFeed.jsm +++ b/browser/components/newtab/lib/PlacesFeed.sys.mjs @@ -1,18 +1,24 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; -const { - actionCreators: ac, - actionTypes: at, - actionUtils: au, -} = ChromeUtils.importESModule( - "resource://activity-stream/common/Actions.sys.mjs" -); +import { + actionCreators as ac, + actionTypes as at, + actionUtils as au, +} from "resource://activity-stream/common/Actions.sys.mjs"; + const { shortURL } = ChromeUtils.import( "resource://activity-stream/lib/ShortURL.jsm" ); + +// We use importESModule here instead of static import so that +// the Karma test environment won't choke on this module. This +// is because the Karma test environment already stubs out +// AboutNewTab, and overrides importESModule to be a no-op (which +// can't be done for a static import statement). + +// eslint-disable-next-line mozilla/use-static-import const { AboutNewTab } = ChromeUtils.importESModule( "resource:///modules/AboutNewTab.sys.mjs" ); @@ -133,7 +139,7 @@ class PlacesObserver { } } -class PlacesFeed { +export class PlacesFeed { constructor() { this.placesChangedTimer = null; this.customDispatch = this.customDispatch.bind(this); @@ -562,5 +568,3 @@ class PlacesFeed { // Exported for testing only PlacesFeed.PlacesObserver = PlacesObserver; - -const EXPORTED_SYMBOLS = ["PlacesFeed"]; diff --git a/browser/components/newtab/test/unit/lib/ActivityStream.test.js b/browser/components/newtab/test/unit/lib/ActivityStream.test.js index 1372c1c8faaf..cdd73d69f7a0 100644 --- a/browser/components/newtab/test/unit/lib/ActivityStream.test.js +++ b/browser/components/newtab/test/unit/lib/ActivityStream.test.js @@ -8,7 +8,7 @@ import { DefaultPrefs } from "lib/ActivityStreamPrefs.sys.mjs"; import { NewTabInit } from "lib/NewTabInit.jsm"; import { SectionsFeed } from "lib/SectionsManager.jsm"; import { RecommendationProvider } from "lib/RecommendationProvider.jsm"; -import { PlacesFeed } from "lib/PlacesFeed.jsm"; +import { PlacesFeed } from "lib/PlacesFeed.sys.mjs"; import { PrefsFeed } from "lib/PrefsFeed.jsm"; import { SystemTickFeed } from "lib/SystemTickFeed.jsm"; import { TelemetryFeed } from "lib/TelemetryFeed.sys.mjs"; diff --git a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js index 4283820a9e4a..4e2fd6c48393 100644 --- a/browser/components/newtab/test/xpcshell/test_PlacesFeed.js +++ b/browser/components/newtab/test/xpcshell/test_PlacesFeed.js @@ -14,6 +14,7 @@ ChromeUtils.defineESModuleGetters(this, { NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", PartnerLinkAttribution: "resource:///modules/PartnerLinkAttribution.sys.mjs", pktApi: "chrome://pocket/content/pktApi.sys.mjs", + PlacesFeed: "resource://activity-stream/lib/PlacesFeed.sys.mjs", PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", SearchService: "resource://gre/modules/SearchService.sys.mjs", @@ -21,10 +22,6 @@ ChromeUtils.defineESModuleGetters(this, { TestUtils: "resource://testing-common/TestUtils.sys.mjs", }); -const { PlacesFeed } = ChromeUtils.import( - "resource://activity-stream/lib/PlacesFeed.jsm" -); - const { PlacesObserver } = PlacesFeed; const FAKE_BOOKMARK = {