Open Bug 1873018 Opened 10 months ago Updated 9 months ago

Move aboutwelcome code to use mjs files, rather than defining sourceType for ESLint

Categories

(Firefox :: Messaging System, task, P3)

task

Tracking

()

People

(Reporter: standard8, Unassigned)

References

(Blocks 2 open bugs)

Details

With the transition to using ES modules rather than JSMs getting started, we are now using the .mjs extension for those files.

We'd like to transition our content code that is using modules to use the .mjs extension as well - the primary gains of this are that we a) don't need to manually specify sourceType: module for ESLint, b) this gives a visual distinction to developers that the file is a module rather than a regular JavaScript file.

This bug is for the aboutwelcome files.

I took a look at this today, and found that renaming browser/components/aboutwelcome/tests/unit/unit-entry.js to use .mjs was enough to upset webpack/karma when running the unit tests.

I suspect the problem is that due to the mix of commonjs based aboutwelcome bundle, the jsms processed to commonjs, and the test files being ES module.

I tried various things in the karma configuration to treat it as a module and potentially stop using webpack, but none of that seemed to work properly. I think we'll probably have to wait until we get the remaining jsms converted to ES modules, and then maybe see if we can update everything together to be ES modules - hence leaving this bug as a reminder to all the problems.

Priority: -- → P3
Depends on: 1878556

Bug 1878556 does the work for the content files, which leaves the test files still to do.

Comment 1 is still largely accurate, however I don't think this is entirely the fault of jsms now. According to this Karma issue, it seems you have to manually list all the modules that are running for the tests, and the ones that might get imported.

I tried doing that, and whilst I could get a simple .mjs based test to load a .mjs based file, trying to do the same for the jsx files just didn't want to work with very little information as to what was wrong.

This might get simpler if we can largely remove Babel once the jsm -> mjs transition is done. However, I'm largely suspecting that Karma not supporting ES modules is a large part of the issue here, and they don't seem keen on making it work nicely either.

There is a package referenced on that issue that is no longer updated, and references Web Test Runner, I have no idea if it'd be suitable, but it might support ES modules better.

Having bug 1878783 done might also help here.

Depends on: 1878783
You need to log in before you can comment on or make changes to this bug.