Closed Bug 2044029 Opened 5 days ago Closed 4 days ago

console.createInstance can't be used within window scope in mochitests because of the console wrapper

Categories

(Testing :: Mochitest, task)

task

Tracking

(firefox153 fixed)

RESOLVED FIXED
153 Branch
Tracking Status
firefox153 --- fixed

People

(Reporter: standard8, Assigned: standard8)

References

(Blocks 2 open bugs)

Details

Attachments

(1 file)

For some of the Urlbar work, we are transitioning various modules from system modules to chrome window scope as they will be used in different contexts going forward.

As part of this, we want to use console.createInstance within the chrome window scope, and it works fine normally, but for mochitests it is undefined.

The reason for this is that mochitests are replacing the console used within windows with the one from Console.sys.mjs. A current workaround would be to use window.nativeConsole.createInstance if window.console.createInstance doesn't exist, however that isn't ideal, and doesn't fit with our wanting to remove Console.sys.mjs.

The wrapper was a workaround for the lack of output of console.* messages (bug 1175318). As the console can now dump its own logs, the wrapper should no longer be necessary (and it also only fixes half the problem as it only affects window scope, and not system modules).

We've done a few comparisons with and without the wrapper. There's a couple of downsides without the wrapper:

  • When using console.error only the first line of the stack gets reported (related to bug 1813485?)
  • When logging various items like Sets or Maps via console.error they are reported as generic objects, i.e. [object Set] rather than the error details (xref bug 1820804)
    • For anything other than console.error we get the same level of logging with or without the wrapper.

There is one upside:

  • When using something other than console.error to log an Error, then the first line of the stack is reported when not using the wrapper. With the wrapper you just get the error message.

Although I think ideally we would resolve the other bugs first, we should still consider avoiding workarounds for production code, and this is likely to confuse developers if they hit it.

This allows console.createInstance to be used within chrome Windows and not have tests fail due to the function being undefined.

This is no longer necessary as console logging is output by default for tests.

Assignee: nobody → standard8
Status: NEW → ASSIGNED
Attachment #9592100 - Attachment description: Bug 2044029 - Remove the console API wrapper from mochitests. r?Gijs!,#devtools-reviewers! → Bug 2044029 - Expose console.createInstance to chrome Windows in mochitests. r?Gijs!
Status: ASSIGNED → RESOLVED
Closed: 4 days ago
Resolution: --- → FIXED
Target Milestone: --- → 153 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: