Code coverage for non-extjs-files

Discuss anything related to web development but *no* technical support questions
Post Reply
User avatar
klodoma
Posts: 15
Joined: Thu Oct 01, 2015 11:55 am

Code coverage for non-extjs-files

Post by klodoma » Thu Jul 20, 2017 11:11 am

How can you enable/see the code-coverage for non-extjs files?
The code-coverage for extjs files works well.

Now, I want to test some simple prototype functions like:

file: /js/common/Prototypes.js

Code: Select all

if ( !String.prototype.capitalizeFirst ) {
    String.prototype.capitalizeFirst = function ()
    {
        return this.charAt( 0 ).toUpperCase() + this.slice( 1 );
    };
}
with:

Code: Select all

StartTest( function ( t )
{
    t.it( "String.prototype.capitalizeFirst", function ( t )
    {
        t.is( "aaa".capitalizeFirst(), "Aaa" );
        t.is( "baa".capitalizeFirst(), "Baa" );
    } );

} );
The test is working, but I can't get the code coverage.

Configs:

Code: Select all

var harness = new Siesta.Harness.Browser.ExtJS();

harness.configure( {
    title: 'Interpid Test Suite',
    viewDOM: true,

    enableCodeCoverage: true,
    //coverageUnit: 'extjs_class', // can be "file" or "extjs_class"
    coverageUnit: 'file', // can be "file" or "extjs_class"

    // Define any global JS and CSS dependencies, these files will be injected into each test.
    preload: preloadsExt5,

    // If your tests use dynamic loading, you can setup your paths using the 'loaderPath' config.
    loaderPath: {
        'Ipd': BASE_URL + '/js/ipd',
        'Ext.ux': BASE_URL + '/vendor/js/extjs-ux/6.5.0'
    }
} );


harness.start(
    {
        group: 'Ipd',
        items: [
            {
                group: 'Prototypes',
                items: [
                    {
                        preload: [
                            BASE_URL + '/js/common/Prototypes.js'
                        ],
                        url: 'prototype/String.t.js'
                    }
                ]
            },
...


User avatar
nickolay
Core Developer
Core Developer
Posts: 3317
Joined: Mon May 16, 2011 10:48 am

Re: Code coverage for non-extjs-files

Post by nickolay » Thu Jul 20, 2017 12:35 pm

Need to supply the "instrument : true" flag in the preload descriptor:

Code: Select all

preload: [
    {
        url         : BASE_URL + '/js/common/Prototypes.js',
        instrument  : true
    }
],
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
klodoma
Posts: 15
Joined: Thu Oct 01, 2015 11:55 am

Re: Code coverage for non-extjs-files

Post by klodoma » Thu Jul 20, 2017 2:02 pm

Cool! Thanks!

User avatar
Alizeh
Posts: 1
Joined: Fri Jul 14, 2017 8:34 am
Contact:

Re: Code coverage for non-extjs-files

Post by Alizeh » Tue Jul 25, 2017 8:14 am

I was also facing the same problem earlier. Now my problem is solved. Thanks again. :)

User avatar
tocnaza
Posts: 1
Joined: Mon Apr 08, 2019 2:29 pm

Re: Code coverage for non-extjs-files

Post by tocnaza » Mon Apr 08, 2019 2:30 pm

Great code! Thanks for sharing us!

User avatar
nikhil.bhatia
Posts: 2
Joined: Fri May 03, 2019 9:34 am

Re: Code coverage for non-extjs-files

Post by nikhil.bhatia » Fri May 03, 2019 9:41 am

This does not work with the new release of Siesta (5.1.0).

Post Reply