Get help with testing, discuss unit testing strategies etc.


Post by nuridesengin »

Hi there, I've started to use code-coverage feature through this guide. I've used this command to produce report:
__SiestaDir__ localhost:1841/myapp/test/Siesta/index.html --coverage-report-format=html
Through the guide, I thought it'll produce the report only for those tests which has instrument config but instead of that it runs whole tests (unit tests + ui/integration tests). So;
  • - How can i state a specific test file or test group?
    - I couldn't wait for terminal-based test runner because it started 2 hours ago and still keep going.. So how I'll achieve to code-coverage report's HTML? End of terminal-test?
Here is harness:
harness.configure({
    title               : 'Siesta Examples',
    enableCodeCoverage: true,
    preload         : [
        {
            type        : 'js',  // optional if file ends with ".js"
            url         : '../../app/Globals.js',
            instrument  : true
        }
    ]
});

harness.start(
    {
        group   : 'Unit Tests',
        runCore : 'sequential',
        items   : [
            {
                title           : 'Globals: typeof & return',
                pageUrl         : '../../index.html?unittest',
                url             : '01-unit-tests/010_globals-typeof.t.js'
            }, {
                title           : 'utils/SessionMonitor: typeof & return',
                pageUrl         : '../../index.html?unittest',
                url             : '01-unit-tests/020_sessionmonitor-typeof.t.js'
            }, {
                title           : 'utils/Router: typeof & return',
                pageUrl         : '../../index.html?unittest',
                url             : '01-unit-tests/030_router-typeof.t.js'
            }
        ]
    },

Post by nickolay »

Basically, when using `pageUrl` code coverage is not supported.

When you run the launcher with --coverage-report-format option, it still runs the full suite (possibly filtered with --filter and --include options) and then generate the coverage report.

Also note, when using "pageUrl" the "preload" config is not inherited from top-level descriptors.

Post by nuridesengin »

so then what is the alternative for pageUrl ? So far I know i can not use hostPageUrl as well because you mentioned that it has been deprecated.

and I've used preload to run code-coverage only for Globals.js. What about if I'll not use preload config and using instrument: true just under test-file itself? Still keep doing coverage?
Last edited by nuridesengin on Thu Dec 28, 2017 12:36 pm, edited 1 time in total.

Post by nickolay »

`pageUrl` and `hostPageUrl` are the same thing - just different names.

"instrument : true" is a property of the preload descriptor only, its not recognized anywhere else.

Check here: https://www.bryntum.com/docs/siesta/#!/ ... tationHook

Post by nuridesengin »

dear nickolay, sorry for that much questions but it still runs all test files and i'm not able to produce report.

So I've reconfigured the harness like this;
harness.configure({
    title               : 'Siesta Examples',
    enableCodeCoverage  : true,
    coverageUnit        : 'extjs_class',
    preload         : [
        {
            text    : harness.getLoaderInstrumentationHook()
        },
        {
            url         : '../../app/Globals.js',
            instrument  : true
        }
    ]
});

harness.start(
    {
        group   : 'Unit Tests',
        runCore : 'sequential',
        items   : [
            {
                title           : 'Globals: typeof & return',
                pageUrl         : '../../index.html?unittest',
                url             : '01-unit-tests/010_globals-typeof.t.js'
            }, 
I've added getLoaderInstrumentationHook method to preload and set the coverageUnit: 'extjs_class' (just couldn't be if I uses this config correct)

and update command like this;
/siesta-4.3.2-standard/bin/webdriver localhost:1841/myapp/test/Siesta/index.html --coverage-report-format=HTML --report-file Dev/myapp/test/Siesta/coverage/code-coverage.html

Post by nickolay »

First of all, the "preload" descriptor is not used by the "010_globals-typeof.t.js" test, since it uses `pageUrl` and that stops the inheritance (which is usually what you want).

You need to use the 2nd option, mentioned in the link, "Or, when using Siesta.Harness.pageUrl option:" The `eval(parent.harness.getLoaderInstrumentationHook())` has to be called right before the application begins loading of required classes.

Post by nuridesengin »

ok. Unfortunately i've been totally confused =(

first of all I've stated second option on both app's index.html & siesta's index.html. Copy pasted those lines;
<script type="text/javascript">
        // will be executed when running in testing environment only
        // the `harness` here should match the name of the main scope variable for harness
        parent.harness && eval(parent.harness.getLoaderInstrumentationHook())
    </script>
as well tried several options for preload config but non of them produced coverage report;
  • 1. Disabling preload on harness.configure and state it on harness.start with unit-test file (010_globals-typeof.t.js). As well disabled pageUrl and re-able back but all behaves same.
    harness.configure({
        title               : 'Siesta Examples',
        enableCodeCoverage  : true,
        coverageUnit        : 'extjs_class',
        // preload         : [
        //    {
        //         url         : '01-unit-tests/010_globals-typeof.t.js',
        //         instrument  : true
        //     }
        // ],
        viewDOM             : true,
        waitForTimeout: 10000
    });
    
    harness.start(
        {
            group   : 'Unit Tests',
            runCore : 'sequential',
            items   : [
                {
                    title           : 'Globals: typeof & return',
                    //pageUrl         : '../../index.html?unittest',
                    url             : '01-unit-tests/010_globals-typeof.t.js',
                    preload         : [
                        {
                            url         : '01-unit-tests/010_globals-typeof.t.js',
                            instrument  : true
                        }
                    ]
  • 2. and then disabled preload on harness.start and re-able on harness.configure with 010_globals..
    also disabled pageUrl and re-able back but still same.
    harness.configure({
        title               : 'Siesta Examples',
        enableCodeCoverage  : true,
        coverageUnit        : 'extjs_class',
        preload         : [
           {
                url         : '01-unit-tests/010_globals-typeof.t.js',
                instrument  : true
            }
        ],
        viewDOM             : true,
        waitForTimeout: 10000
    });
    
    harness.start(
        {
            group   : 'Unit Tests',
            runCore : 'sequential',
            items   : [
                {
                    title           : 'Globals: typeof & return',
                    pageUrl         : '../../index.html?unittest',
                    url             : '01-unit-tests/010_globals-typeof.t.js',
                    // preload         : [
                    //     {
                    //         url         : '01-unit-tests/010_globals-typeof.t.js',
                    //         instrument  : true
                    //     }
                    // ]
Unfortunately I still couldn't get it or where/how i am doing wrong.

Post by nickolay »

Well, need to understand how it works, mechanically changing the configs won't do it. Note, that for `pageUrl` case, the coverage is only supported for classes, loaded through "Ext.require" mechanism (possibly as dependencies for other classes). The
`eval(parent.harness.getLoaderInstrumentationHook())` has to be called before application has started loading. For that:
- App should be built using "development" Sencha Cmd mode (possibly "testing" build works too).
- The <script> tag should be placed at the right place in app's "index.html"

If you can prepare a standalone reproducible test case, I can take a look. Make sure it is actually standalone - that is, if you unpack it to different location it still works.

Post by nuridesengin »

Dear nickolay hello, actually I've sent code-snippets with PM to you on 28 of Dec. Did you get it?

Post by nickolay »

Hi,

Oh, right, found it. Will check soon, holidays time here :)

Post Reply