Is it possible to disable firefox error messages during karma tests - javascript

I'm running tests with jasmine/karma and although all tests run ok, process exits with 1. I suspect that these are Firefox's web console error messages, which are produced when I try to add existing record into IndexedDB object store. Is there any option to disable these messages or ignore them in Karma runner?
UPD: These errors occur in web console even if I wrap my code inside try..catch, so it's browsers default behaviour.
https://travis-ci.org/1999/sklad/builds/36609101

Just in case someone needs this. The answer is here. In brief, Firefox shows that this is a usual DOM error and it has default behavior. So if you prevent default 'onerror' behavior which is 'abort', everything goes fine. You can see the result here.

Related

"Debug" function in Chrome

probably a silly question, but somehow i ended up on the debug function available in Google Chrome Console, which if i try to print it on the console i get:
ƒ debug(function, condition) { [Command Line API] }
however i'm totally unable to console.log something from it in any way, and I can't find any documentation online...
I've tested it on Firefox and i get Uncaught ReferenceError: debug is not defined so it's not cross platform, but maybe for development purpose it might be helpful
Maybe is related to debugger;?...
This is documented in the Console Utilities API Reference:
debug(function)
When the specified function is called, the debugger is
invoked and breaks inside the function on the Sources panel allowing
to step through the code and debug it.
debug(getData);
Use undebug(fn) to stop breaking on the function, or use the UI to
disable all breakpoints.
For more information on breakpoints, see Pause Your Code With
Breakpoints.

What could cause Electron to not show any errors?

I have taken over an Electron project from another developer.
The problem I am facing is that the project does not show any errors. Even including something like throw "this is an error" does not produce any output on the main process or render process consoles or any sort of standard error popup.
I have checked to confirm that electron-unhandled is not in use and that nothing registers 'uncaughtException'.
What am I missing that could cause this behavior?
Search for: unhandledRejection
unhandledRejection : This will catch any thrown errors, or non fatal errors you have successfully handled via throw.
uncaughtException : This only catches fatal errors or errors that would crash your node instance
WebWorkers : There will be yet another console for webworkers if your using those.
package.json : Take a look in here at the script executed to start electron or however your starting it... Make sure the console is not being sent to a remote console. This feature would allow for debugging the application via Chrome/Firefox vs the standard console. Pretty common for electron apps. If is done via the startup command.
May look something like this:
process.on('unhandledRejection', function (err) {
});
Also, make sure you include any modules in your searching for suppressors as the issue may exist somewhere in the node_modules directory and many IDE's (mine does by default) exclude that directory in indexing/searches.
Another possible reason could be stdout and/or stderr redirection, the problem is this could be achieved by several ways so it's hard to suggest you what to check...
If there is some child_process call to launch a sub-process you could check the stdio array used, or you can check if some low level operation is performed against file descriptors 1 and 2...
Hope this helps.
Are you facing the problem as mentioned in this official thread. You may disable the original event listeners and manage the ELECTRON_BROWSER_WINDOW_ALERT event by my event listener.
Here is the solution
ipcMain.removeAllListeners("ELECTRON_BROWSER_WINDOW_ALERT")
ipcMain.on("ELECTRON_BROWSER_WINDOW_ALERT", (event, message, title)=>{
console.warn(`[Alert] ** ${title} ** ${message}`)
event.returnValue = 0 // **IMPORTANT!**
})

should I use a js function other than console.log(message)?

I would like to use console.log(message) to write out some information to the browser console. However, I came across this url which seems to recommend against it:
https://developer.mozilla.org/en-US/docs/Web/API/Console/log
Are you currently choosing to use console.log(message) as part of your js code? If not then have you identified an alternative?
I agree with Mike C above-- console is generally available in most browsers, but you should probably remove console logs before a site gets pushed to production.
Additionally, some older browser might not have the console, and if you did accidentally leave in a console log, it would fire an error when it attempted to interact with with something that wasn't defined. As an extra failsafe, you can declare console and console.log in the global namespace if they are not detected, just in case:
if (!console) {
console = {
log: function () { //noop }
};
}
should I use a js function other than console.log(message)?
simple answer is yes, But also the console.log(message) is usaually used for testing purposes and for other relevant intentions like letting other developers interract with your js source code in some sort.
However.
You should not use it to log very important messages as this could be a hole your application presumably.
Hope it helps.
While the console object is not defined in the official Javascript standard, it is specified in:
Google Chrome
Mozilla Firefox
Internet Explorer 9+
Opera
Safari
Node.js
PhantomJS (since it uses V8 like Chrome and Node.js)
and more, I'm sure. As long as you're debugging in any of the environments which supports it, you're fine. You should be removing your logging statements before pushing to production anyway so as long as it works for debugging, it's nothing to worry about.

How to report JavaScript errors during functional tests using Intern?

How can I report JavaScript errors that occur during test execution using Intern? Basically, if there are any JavaScript errors on the page (even as part of things that aren't explicitly tested) I want to know.
Background
I'm just getting started with Intern and testing in general and I'm trying to test all major pages on my site in all browsers because I just changed all our JavaScript to load via require.js. While it looks good in Chrome, I've had issues with require.js and random browsers in the past so I wanted to automate everything. The most likely issue that will arise is that some random JS will fail to execute due to asynchronous loading and load of an expected global. Since there are no current tests setup, I basically want to start by running a 'test' go to through all major pages and report any JavaScript errors.
In order to report uncaught errors, you need to hook the window.onerror method of the page. This is possible, but the page load will need to be finished before you add the hook, which means that any errors that occur before/during the page load (or that occur while the page unloads) simply cannot be caught and reported. It also means if you perform an action that moves to a new page (like a form submission), you will need to make sure you retrieve the list of errors before you perform the action that causes navigation, and reconfigure the window.onerror handler after you get to the new page.
To perform such reporting with a functional test, your test would end up looking something like this:
return this.remote
.get('http://example.com')
.execute(function () {
window.__internErrors__ = [];
window.onerror = function () {
__internErrors__.push(Array.prototype.slice.call(arguments, 0));
};
})
// ... interact with the page ...
.execute(function () {
return window.__internErrors__;
})
.then(function (errors) {
// read `errors` array to get list of errors
});
Note that (as of August 2014) errors from window.onerror in all browsers except recent versions of Chrome provide only the message, script source, line number, and (sometimes) column number, so this information would only be useful to say “this action caused an error, go do it manually to get a stack trace”.
During unit tests, Intern already tries to automatically catch any unhandled errors and treats them as fatal errors that halt the system (since you should never have code that generates this kind of unhandled error).

Output the rendered contents of a page on a JavaScript error

I'm having problems with getting decent JavaScript error invormation in a Production environment.
When I'm developing I can just attach a debugger and (usually) fix the problem.
When I get the same error in a production environment however at best I see is an error report that looks like this:
Error: Object doesn't support this property or method
Url: SomePage
Line: 42
Char: 13
Which doesn't help me very much - I can't see the rendered page and so I have no idea what line 42 looks like.
Is there any way for me to log the entire rendered page contents whenever an error like this occurs? (So line 42 of the output is the line where the error occured)
While I'm at it, are there any other techniques that I can use to help with getting useful error information from JavaScript (without need to break into the debugger) - failing that is there any way that I can structure my JavaScript slightly differently to help getting decent debug information?
I'm predominantly interested in IE - this is the browser that tends to cause me most problems.
I don't think you'll be able to get the exact original HTML source of the page back in all pages and all browsers.
Regarding debugging, you could use a logging library such as log4javascript (disclaimer: I wrote it) and intersperse logging calls in your code. log4javascript enables you to send logging messages back to the server via Ajax.
Unfortunately, IE has by default the most utterly useless error reporting. The script and line number reported in the error are essentially guaranteed to be absolutely wrong. You can, however, install the IE developer tool bar (for IE7 and older, it's built into IE8) from Microsoft, which can help track down the error source.

Categories