Is it possible to change a karma coverage report title? - code-coverage

I'm working on an application who has two sides; a desktop and a mobile. In order to test that everything work's fine, we wrote some unit tests, and setup a karma-coverage.
I already have two config file, the first one is for mobile, the second one for desktop, and it generate two distinct coverage reports.
What I need, is to change the default report title. Actually, this is "Code coverage report for All files". I want to set it up to "Code coverage report for All files - Smartphone|Desktop".
Anyone knows if there is a parameter to change this default title?

Use a Greasemonkey/Tampermonkey script for this:
document.querySelector(".entity").innerHTML += " - Smartphone|Desktop"
For example:
// ==UserScript==
// #name Code Coverage
// #namespace script[id]
// #include http://127.0.0.1:8080/
// #version 1
// #grant none
// ==/UserScript==
document.querySelector(".entity").innerHTML += " - Smartphone|Desktop"
Then save the page as HTML, MHTML, data URL, or PDF.
References
Test Cases · greasemonkey/greasemonkey Wiki
Creating a dismissible banner component with Vanilla JavaScript

Related

Printing from a Xamarin.Forms app

I'm all new to Xamarin and I'm currently working on a sample or a "prove of concept" app using Xamarin.Forms.
I'm supposed to perform a print task from this app though I'm not at this point sure what to print yet (the screen, content of a label, a file etc.).
Either way, what is the easiest way to print from a Xamarin.Forms app?
(current target is primarily Android 4.4+).
I hope this isn't too complicated :)
EDIT:
Ok let me just update this post as the original text might be a bit ambitious/vague.
I have a Xamarin.Forms project (+ an Android part) and I have some HTML available in the XF part of the project that I need to get into a WebView and print it.
From what I understand, the thing with the WebView has to be done on the Android part of the project due to the fact that this is where the printing will be handled.
I was hoping this could be done from code since I don't really need to display the WebView, just print it's content.
The Android part of the project has only the MainActivity and no layouts or XAML files.
I don't know where to add the WebView or how to access it (other than DependecyService seems to be a buzz word here) so I'm kinda stuck here.
I'm thinking that this task should be rather trivial to someone with a little more Xamarin experience than me.
Every platform XF supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyService (or some other DI engine).
Here is a good example, of course, using dependency service:
https://codemilltech.com/xamarin-forms-e-z-print/
I so wanted to do this but it was too hard. Finally built it into Forms9Patch - a MIT licensed open source project.
Verifying that Printing is available
Before printing, you should verify that printing is available on your device. To do so, call:
if (Forms9Patch.PrintService.CanPrint)
{
// do the printing here
}
Print the contents of a Xamarin.Forms.WebView
using Forms9Patch;
...
var myWebView = new Xamarin.Forms.WebView
myWebView.Source = new HtmlWebViewSource
{
Html = "some HTML text here"
};
...
myWebView.Print("my_print_job_name");
Note that your WebView does not have to be attached to a Layout. This allows you to Print without having to display the WebView in your app’s UI.
Printing an HTML string
using Forms9Patch;
...
var myHtmlString = #"
<!DOCTYPE html>
<html>
<body>
<h1>Convert to PNG</h1>
<p>This html will be converted to a PNG, PDF, or print.</p>
</body>
</html>
";
...
myHtmlString.Print("my_print_job_name");
PLEASE NOTE: iOS sometimes places the page breaks in weird places. I have a StackOverflow Bounty on why this happens and how to fix it.
Using EmbeddedResource as a source for a Xamarin.Forms.WebView
This is sort of an experimental feature I’ve built that I’ve found it useful. As such the documentation is sparse. It allow you to put HTML content in a folder in your app’s EmbeddedResources folder and then use it as a source for a WebView. A much nicer solution than using platform specific approach provided by Xamarin. It also supports putting all of the HTML content into a zip file. Please take a look at the source code to see how it works.
You can handle the printing of lists/ invoices .. with the xfinium pdf component from xamarin componentstore. With that you create your _pdffile and then call the following method which starts the adobereader from where you can select a printer (in my case google cloudprint)
public void printPdfToCloud(string _pdffile)
{
try
{
var saveto = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "YourApp/"+_pdffile);
string file_path = saveto;
if (System.IO.File.Exists(file_path))
{
Android.Net.Uri pdfFile = Android.Net.Uri.FromFile(new Java.IO.File(file_path));
Intent pdfIntent = new Intent(Intent.ActionView);
pdfIntent.SetPackage("com.adobe.reader");
pdfIntent.SetDataAndType(pdfFile, "application/pdf");
pdfIntent.SetFlags(ActivityFlags.NoHistory);
StartActivity(pdfIntent);
}else
{
// give a note that the file does not exist
}
}
catch (Exception E)
{
// Do some Error dialog
}
}

How to delete part of a URL using Greasemonkey?

I'm trying to make a Greasemonkey script that passes me from this:
http://redirector/referal_ID:site#link
to this:
link
In other words, I need to delete the first part of the links that I click on, bypassing the redirector pages http://redirector/referal_ID:site# and keep only what is after the # character the link.
Note that redirector changes frequently, referal_id is always unique and different, and site# is the only constant string in all of the links.
I've tried to modify various scripts but my, next to null, knowledge of javascript foils all my attempts.
--------------------------------------------------------------------EDIT-----------------------------------------------------------------------
An example of what I need to do is to modify this:
http://firstfirst.net/identi_ref?q=Waterfox%2033.0.2%20[Mozilla%20Firefox%20de%2064%20bits]&ref=http://www.identi.li/c#https://shared.com/dhq1l9djj1?s=l
into this:
https://shared.com/dhq1l9djj1?s=l
The site where I want the script to work is http://www.identi.li/
The trickiest part of this is making sure the script does not fire on pages that are not redirectors. To do that, use a regex #include.
After that, it's just a matter of extracting the target site and changing the location. Here's a complete script:
// ==UserScript==
// #name _Skip redirects
// #include /site#http/
// #run-at document-start
// ==/UserScript==
var targetSite = location.href.replace (/^.+?site#(http.+)$/, "$1");
//--- Use assign() for debug or replace() to keep the browser history clean.
location.assign (targetSite);
//location.replace (targetSite);
Note that the #run-at document-start is not strictly necessary, but it can shave the response time, of a redirect script, by a fair amount.

"document" in mozilla extension js modules?

I am building Firefox extension, that creates single XMPP chat connection, that can be accessed from all tabs and windows, so I figured, that only way to to this, is to create connection in javascript module and include it on every browser window. Correct me if I am wrong...
EDIT: I am building traditional extension with xul overlays, not using sdk, and talking about those modules: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules
So I copied Strophe.js into js module. Strophe.js uses code like this:
/*_Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
[---]
if (document.implementation.createDocument === undefined) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
and later uses doc.createElement() to create xml(or html?) nodes.
All worked fine, but in module I got error "Error: ReferenceError: document is not defined".
How to get around this?
(Larger piece of exact code: http://pastebin.com/R64gYiKC )
Use the hiddenDOMwindow
Cu.import("resource://gre/modules/Services.jsm");
var doc = Services.appShell.hiddenDOMWindow.document;
It sounds like you might not be correctly attaching your content script to the worker page. Make sure that you're using something like tabs.attach() to attach one or more content scripts to the worker page (see documentation here).
Otherwise you may need to wait for the DOM to load, waiting for the entire page to load
window.onload = function ()
{
Javascript code goes here
}
Should take at least diagnose that issue (even if the above isn't the best method to use in production). But if I had to wager, I'd say that you're not attaching the content script.

In UI Automation for iOS, how do I wait for performTaskWithPathArgumentsTimeout to finish before performing #import

Using Apple's UI Automation, I have been successful in building and executing my test scripts through a bash script.
I'm trying to automate testing for an app that requires comparing data in a sqlite file with data shown in the app.
I've written a python script which saves the sqlite data as javascript variables in a file called settings.js. Using performTaskWithPathArgumentsTimeout, I can execute this script to create the settings.js file:
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/usr/bin/python",["/Users/Matt/Code/automation/DBData/UIAsettingsKVDump.py", "/Users/Matt/Code/automation/DBData/settings.sqlite"],20);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
#import "./../DBData/settings.js"
This successfully creates the settings.js file. However, when I try to import the settings.js file like above, I get an "Import file not found(null)" error before the three logDebug messages are output onto the console -this leads me to believe that the #import is done before the script is executed.
What can I do to make sure my settings.js file is created before the #import is performed?
There's no documentation about this, but from my experience Apple is preprocessing the JavaScript files and performing the imports at script parsing time before the script is evaluated. I think this happens because the #import statement isn't part of of the JS language.
Rather than try to import the JavaScript file, what if you just had your Python script print the settings JavaScript to standard out. That way you can get that output from the result returned from performTaskWithPathArgumentsTimeout and use eval() to convert it into a JavaScript result. That may be finicky and you're certainly going to have trouble debugging it, but that might be the quickest way to get what you want.

Use h5bp / ant-build-script to remove debug output

In the ant-build-script docs, it says I can mark my scripts with comments to state which Javascript files to minify & concat.
<-- scripts concatenated and minified via build script -->
<script src="js/plugins.js"></script> <cript
src="js/main.js"></script> <-- end scripts -->
Is there a way I can use a similar approach to disable debug output, or remove specific lines in any files (Javascript, PHP, etc.)
An example of what I'm trying to accomplish:
<!-- Remove these lines --> console.log("Starting test");
console.log("Test 2"); <-- end remove these lines -->
Also, using that same example, if it could replace a line. An example of that is if I wanted it to change a variable from a local test directory to a remote production directory.
I hope that make sense and I appreciate any help.
Thanks!
If you are trying to remove lines of Javascript using the h5bp default Google Closure Compiler I suggest looking at #define JSDoc Tag
/** #define {boolean} */
var DEBUG = true;
Then, in your project.properties file look for: # Closure Compiler Options and set: tool.closure.opts = --define DEBUG=false
Finally, wrap any code you want ignored, in production, in a conditional:
if (!DEBUG) {
console.log("Starting test");
console.log("Test 2");
}
The #define JSDoc Tag will help with your second question also.
/**
* #define {string}
*/
var AJAX_URL = 'http://localhost/';
console.log(AJAX_URL);
with the compilations options: --compilation_level ADVANCED_OPTIMIZATIONS --define AJAX_URL=\'http://example.com/\' (Note: you made need to fiddle with the quote escaping, depending on your platform) the resulting code is:
console.log("http://example.com/");
There are many ways to go about this of course, see:
http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
http://dailyjs.com/2012/02/02/console/
https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en

Resources