Stop using ChromeUtils.import(..., this) for importing modules in toolkit/components/telemetry/tests/unit/
Categories
(Toolkit :: Telemetry, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox91 | --- | fixed |
People
(Reporter: standard8, Assigned: la.gandyra, Mentored)
References
Details
(Keywords: good-first-bug, Whiteboard: [lang=js])
Attachments
(1 file)
The ChromeUtils.import(..., this) form of importing modules is a legacy import format that imports directly into the global object.
This bug is about fixing the cases for toolkit/components/telemetry/tests/unit/, in particular this list.
I'm happy to mentor this bug. Note: this bug will be auto-assigned when the first patch is attached.
Here's what to do:
- Ensure you have a [working Firefox build](https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html, an artifact build is sufficient thought it doesn't matter if you have a full build.
- Run
./mach eslint --setupto set up ESLint, then ensure your editor has an integration set-up. It is not essential to do this, but it helps to show if you've made a mistake, or if formatting needs fixing whilst you're still in a particular file. - Remove the relevant lines from .eslintrc.js to enable the rule for the files.
- Run
./mach eslint toolkit/components/telemetry/tests/unit/to see where the errors are. - Fix
toolkit/components/telemetry/tests/unit/head.jsfirst. In this particular file, the imports can be incorporated into theXPCOMUtils.defineLazyModuleGetterscall. To check what the import is, load the particular.jsmfile and look for theEXPORTED_SYMBOLSdefinition.
- Note that
PromiseUtils.jsmis already included in thedefineLazyModuleGetterscall, so that line can simply be deleted.
- Now fix the remaining test files.
- If the module is already imported via the head.js file, then the line can be removed.
- Otherwise, the import should be replaced, e.g.
ChromeUtils.import(
"resource://testing-common/TelemetryArchiveTesting.jsm",
this
);
becomes
const { TelemetryArchiveTesting } = ChromeUtils.import(
"resource://testing-common/TelemetryArchiveTesting.jsm"
);
- Don't forget to check ESLint again after your fixes, with
./mach eslint toolkit/components/telemetry/tests/unit/. If there are formatting errors from prettier, then you can add the--fixargument to automatically fix those. - Check that the tests pass, use
./mach xpcshell-test toolkit/components/telemetry/tests/unit/ - Commit the changes and submit for review with a message something like
Bug nnnnnnn - Stop using this argument in ChromeUtils.import for importing modules in toolkit/components/telemetry/tests/unit/. r?Standard8.
Hello Mark,
I'd like to work on this issue. I encountered two problems while trying to fix these imports:
- In head.js https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/tests/unit/head.js#314-317, when I change
"resource://gre/modules/TelemetryScheduler.jsm",
null
);```
to
```let scheduler = ChromeUtils.import(
"resource://gre/modules/TelemetryScheduler.jsm"
);```
I get the "TypeError: can't access property "setSchedulerTickTimeout", scheduler.Policy is undefined". I can't figure out why this happens.
I tried to import the module in the defineLazyModuleGetters call but didn't help.
2. Changing the current import form of XPCOMUtils to
```const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);```
makes some tests fail with the error 'SyntaxError: redeclaration of const XPCOMUtils' for some files not listed in tests you mentioned, for instance test_TelemetryController.js and test_TelemetryControllerShutdown.js. Do I have to modify this tests and delete the import of XPCOMUtils?
Thanks in advance.
(In reply to gystemd from comment #1)
Hello Mark,
I'd like to work on this issue. I encountered two problems while trying to fix these imports:
- In head.js https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/tests/unit/head.js#314-317, when I change
"resource://gre/modules/TelemetryScheduler.jsm", null );``` to ```let scheduler = ChromeUtils.import( "resource://gre/modules/TelemetryScheduler.jsm" );``` I get the "TypeError: can't access property "setSchedulerTickTimeout", scheduler.Policy is undefined". I can't figure out why this happens. I tried to import the module in the defineLazyModuleGetters call but didn't help. 2. Changing the current import form of XPCOMUtils to ```const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);``` makes some tests fail with the error 'SyntaxError: redeclaration of const XPCOMUtils' for some files not listed in tests you mentioned, for instance test_TelemetryController.js and test_TelemetryControllerShutdown.js. Do I have to modify this tests and delete the import of XPCOMUtils? Thanks in advance.
Sorry for the bad formatting, I don't have the permissions to modify it.
We also expanded the EXPORTED_SYMBOLS lists of some .jsm files, because otherwise we got the error that these symbols were undefined.
Updated•4 years ago
|
Comment 5•4 years ago
|
||
| bugherder | ||
Description
•