Get help with testing, discuss unit testing strategies etc.


Post by nickolay »

When I open "index.html" from your it shows nothing - missing "locale.js", "bootstrap.js" etc.

Anyway, from the "index.html":
    <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>
    <script type="text/javascript" src="resources/locale/locale.js"></script>
    
    <!-- The line below must be kept intact for Sencha Cmd to build your application -->
    <script id="microloader" type="text/javascript" src="bootstrap.js"></script>
The cause is probably that loader hook is installed at the point, when there's no Ext.Loader class on the page. Thus, nothing happens.

The loader will probably appear after the "bootstrap.js" has completed. Thing is, bootstrap.js will (again probably) use asynchronous loading, so just moving the script tag with `eval(parent.harness.getLoaderInstrumentationHook())` after the "bootstrap.js" won't help.

Please try the following setup:
    
    <script type="text/javascript" src="resources/locale/locale.js"></script>
    
    <!-- The line below must be kept intact for Sencha Cmd to build your application -->
    <script id="microloader" type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript">
       Ext.onReady(function () {
             parent.harness && eval(parent.harness.getLoaderInstrumentationHook())
       })        
    </script>

Post by nuridesengin »

It couldn't recognise Ext.onReady and created a folder with name of coverage but it's empty of course;
RTP-Frontend-Mac:~ nengin$ other-sdks/Siesta/siesta-4.4.0-standard/bin/webdriver localhost:1841/oweb/test/Siesta/index.html --include=01-unit-tests/010_globals.t.js --browser-arg disable-web-security --coverage-report-format=html
Launching test suite, OS: MacOS, browser: Chrome 63.0.3239.84
fail 1 - Test  threw an exception
TypeError: Ext.onReady is not a function
    at https://localhost:1841/oweb/index.html?unittest:68:13
[FAIL]  01-unit-tests/010_globals.t.js

0 passed, 1 failed assertions took 2.6s to complete

Post by nickolay »

Ok, may be then put that code into "app.js", before the "Ext.application()" call.

Post by nuridesengin »

Nope =( It's now not give this error; TypeError: Ext.onReady is not a function. But not produce coverage report in coverage folder as well. Still couldn't figure out what i am missing =( Here is snippets that I've set;

index.js
harness.configure({
    title               : 'Siesta Examples',
    enableCodeCoverage  : true,
    coverageUnit        : 'extjs_class',

harness.start(
    {
        group   : 'Unit Tests',
        runCore : 'sequential',
        items   : [
            {
                title           : 'Globals.js',
                pageUrl         : '../../index.html?unittest',
                url             : '01-unit-tests/010_globals.t.js',
                instrument      : true
            }
        ]
    },
Application.js
Ext.onReady(function () {
    parent.harness && eval(parent.harness.getLoaderInstrumentationHook())
});

Ext.define('OWeb.Application', {
    extend: 'Ext.app.Application',
and command
other-sdks/Siesta/siesta-4.4.0-standard/bin/webdriver localhost:1841/oweb/test/Siesta/index.html --include=01-unit-tests/010_globals.t.js --browser-arg disable-web-security --coverage-report-format=html
Launching test suite, OS: MacOS, browser: Chrome 63.0.3239.84

Post by nickolay »

Ok, that seems to be trickier than expected. What are your Sencha Cmd and ExtJS versions (precisely)? I'll try to prepare a new example of using code coverage with Sencha Cmd app.

Post by nuridesengin »

Thanks a lot for your effort nickolay. So here is the environment that we use;

Post by nuridesengin »

Dear nickolay hold on please!! I just found another coverage folder but under base-root folder on my computer! it's includes several files as well such as; index.html, code-coverage-report.js, coverage-data.json and css folder.

I've tried to open but gave error! Please let me examine this folder first.

Post by nuridesengin »

OK! Finally I got the report =) not sure how long that folder existed but I'll figure out. Somehow I had a coverage folder under testing folder within app directory. I've deleted it and I've ran this command again;
other-sdks/Siesta/siesta-4.4.0-standard/bin/webdriver localhost:1841/oweb/test/Siesta/index.html --include=01-unit-tests/010_globals.t.js --browser-arg disable-web-security --coverage-report-format=html
It has created coverage folder and reproduced index.html of coverage repote under root directory instead of testing folder!

This is coverage report's screen shot @ https://prnt.sc/hwe5cw
As you will notice, It's include only Global namespace thats probably because of I've specified --include=01-unit-tests/010_globals.t.js in terminal command, right?

But report.json's metrics shows covered is 0 for all as you see below!

Here is coverage-report.json;
{
coverageNoSource: false,
htmlReport: {
prefix: [ ],
root: {
name: "/",
fullName: "/",
kind: "dir",
metrics: {
lines: {
total: 0,
covered: 0,
pct: 100
},
statements: {
total: 0,
covered: 0,
pct: 100
},
functions: {
total: 0,
covered: 0,
pct: 100
},
branches: {
total: 0,
covered: 0,
pct: 100
}
},
parent: null,
children: [ ]
}
},
coverageUnit: "extjs_class"
}


So... two more notation;
  • - Seems like ?unittest parameter is not work! After all adjustment through under index.html & Application.js with;
    Ext.onReady(function () {
        parent.harness && eval(parent.harness.getLoaderInstrumentationHook())
    });
    
    It still runs whole created test files w/o --include=testFile notation on terminal command.
    - and how to set directory navigation for coverage folder?
Below is coverage folder included.
coverage.zip
coverage_folder
(2.14 MiB) Downloaded 199 times
Last edited by nuridesengin on Mon Jan 08, 2018 12:26 pm, edited 1 time in total.

Post by nickolay »

As you will notice, It's include only Global namespace thats probably because of I've specified --include=01-unit-tests/010_globals.t.js in terminal command, right?
No, this just means its an empty report.
- Seems like ?unittest parameter is not work! After all adjustment through under index.html & Application.js with;
CODE: SELECT ALL
Ext.onReady(function () {
parent.harness && eval(parent.harness.getLoaderInstrumentationHook())
});

It still runs whole created test files w/o --include=testFile notation when I delete --include notation on terminal command.
- and how to set directory navigation for coverage folder?
Sorry, not quite clear what you mean.

May be just wait some time until I'll provide a sample setup.

Post by nuridesengin »

Dear nickolay any news?

Post Reply