console.createInstance can't be used within window scope in mochitests because of the console wrapper
Categories
(Testing :: Mochitest, task)
Tracking
(firefox153 fixed)
| 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.erroronly the first line of the stack gets reported (related to bug 1813485?) - When logging various items like
Sets orMaps viaconsole.errorthey are reported as generic objects, i.e.[object Set]rather than the error details (xref bug 1820804)- For anything other than
console.errorwe get the same level of logging with or without the wrapper.
- For anything other than
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.
| Assignee | ||
Comment 1•5 days ago
|
||
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.
Updated•5 days ago
|
Updated•5 days ago
|
Comment 3•4 days ago
|
||
| bugherder | ||
Description
•