Skip to content

Commit

Permalink
Merge pull request #6 from mhalitk/fix/issue-5
Browse files Browse the repository at this point in the history
[Issue #5] Fix skipped cases effect to total count
  • Loading branch information
Muhammet Halit Karakis authored Jan 6, 2017
2 parents 6afe3c4 + 9272b2d commit ffa605b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 45 deletions.
50 changes: 28 additions & 22 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,60 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module-sa


<section class="readme">
<article><h1>salep</h1><p><a href="https://travis-ci.org/mhalitk/salep"><img src="https://travis-ci.org/mhalitk/salep.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/mhalitk/salep"><img src="https://codecov.io/gh/mhalitk/salep/branch/master/graph/badge.svg" alt="codecov"></a></p>
<p>salep is platform independent Javascript testing framework. It basically puts itself into global scope and runs while your code is running. It gives all collected test informations as JS object when you stopped it. That's it.</p>
<h1>Install</h1><p>Install salep globally:</p>
<pre class="prettyprint source"><code>npm install --global salep</code></pre><p>or install as a dependency to your project</p>
<pre class="prettyprint source"><code>npm install --save-dev salep</code></pre><h1>Usage</h1><p>Here is a sample test code using salep</p>
<p>```javascript
require('salep');</p>
<p>function add(a, b) {
<article><h1>salep</h1><p><a href="https://travis-ci.org/mhalitk/salep"><img src="https://travis-ci.org/mhalitk/salep.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/mhalitk/salep"><img src="https://codecov.io/gh/mhalitk/salep/branch/master/graph/badge.svg" alt="codecov"></a> <a href="https://github.com/mhalitk/salep"><img src="https://img.shields.io/badge/dependencies-none-brightgreen.svg" alt="dependencies"></a> <a href="https://github.com/mhalitk/salep/releases"><img src="https://badge.fury.io/gh/mhalitk%2Fsalep.svg" alt="GitHub version"></a> <a href="https://github.com/mhalitk/salep/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a></p>
<p>salep is platform independent Javascript testing framework. It basically puts itself into global scope and runs while your code is running. It gives all collected test informations as JS object whenever you requested.</p>
<h1>Install</h1><h2>Node.js</h2><pre class="prettyprint source"><code>npm install salep</code></pre><h2>Smartface</h2><p>If you are developing a Smartface application go to <code>scripts</code> folder of your workspace and install <code>salep</code>.</p>
<pre class="prettyprint source"><code>cd ~/workspace/scripts && npm install salep</code></pre><h2>Other Platforms</h2><p>You can get standalone Javascript distribution from <a href="https://github.com/mhalitk/salep/releases">releases</a> and run on your Javascript system before <code>salep</code> test codes.</p>
<h1>Usage</h1><p>Here is a sample test code using salep, for more information you can check <a href="https://mhalitk.github.io/salep/">api documentation</a>.</p>
<pre class="prettyprint source lang-javascript"><code>require('salep');

function add(a, b) {
return a + b;
}</p>
<p>// This function has bug
}

// This function has bug
function fibonacci(n) {
if (n &lt;= 2) {
return 0;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}</p>
<p>// Set event handlers
}

// Set event handlers
salep.on(&quot;fail&quot;, function(testCase) {
console.log(&quot;Case [&quot; + testCase.name + &quot;] finished with fail: &quot; + testCase.reason);
});</p>
<p>salep.on(&quot;success&quot;, function(testCase) {
});

salep.on(&quot;success&quot;, function(testCase) {
console.log(&quot;Case [&quot; + testCase.name + &quot;] finished with success&quot;);
});</p>
<p>// Write tests and cases
});

// Write tests and cases
salep.test(&quot;Add/Fibonacci Functions Test&quot;, function() {
// This will be recorded as success
this.case(&quot;add(3,5) should return 8&quot;, function() {
var result = add(3,5);
if (result !== 8) {
throw &quot;add(3,5) returned '&quot; + result + &quot;', expected value was '8'&quot;;
}
});</p>
<p> // This will be recorded as fail
});

// This will be recorded as fail
this.case(&quot;fibonacci(7) should be equal to 13&quot;, function() {
var result = fibonacci(7);
if (result !== 13) {
throw &quot;fibonacci(7) returned '&quot; + result + &quot;', expected value was '13'&quot;;
}
});
});</p>
<p>// Get results
});

// Get results
var result = salep.getResults();
console.log(result.fail + &quot; Failed&quot;);
console.log(result.success + &quot; Succeeded&quot;);
console.log(result.skip + &quot; Skipped&quot;);
console.log(result.total + &quot; Total&quot;);</p></article>
console.log(result.total + &quot; Total&quot;);</code></pre><h1>License</h1><p><a href="https://github.com/mhalitk/salep/blob/master/LICENSE">MIT</a></p></article>
</section>


Expand All @@ -107,7 +113,7 @@ <h1>Install</h1><p>Install salep globally:</p>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 04 2017 23:39:07 GMT+0300 (+03) using the Minami theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jan 06 2017 09:50:37 GMT+0300 (+03) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
3 changes: 2 additions & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ <h1 class="page-title">index.js</h1>
}

function skip(testOrCase) {
totalCount++;
skipCount++;
skipNextEnabled = false;
/**
Expand Down Expand Up @@ -479,7 +480,7 @@ <h1 class="page-title">index.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 04 2017 23:39:07 GMT+0300 (+03) using the Minami theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jan 06 2017 09:50:37 GMT+0300 (+03) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
16 changes: 8 additions & 8 deletions docs/module-salep-Result.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h4 class="name" id="Result"><span class="type-signature"></span>new Result<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line377">line 377</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line378">line 378</a>
</li></ul></dd>


Expand Down Expand Up @@ -211,7 +211,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line423">line 423</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line424">line 424</a>
</li></ul></dd>


Expand Down Expand Up @@ -283,7 +283,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line391">line 391</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line392">line 392</a>
</li></ul></dd>


Expand Down Expand Up @@ -355,7 +355,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line398">line 398</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line399">line 399</a>
</li></ul></dd>


Expand Down Expand Up @@ -427,7 +427,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line384">line 384</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line385">line 385</a>
</li></ul></dd>


Expand Down Expand Up @@ -501,7 +501,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line414">line 414</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line415">line 415</a>
</li></ul></dd>


Expand Down Expand Up @@ -573,7 +573,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line405">line 405</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line406">line 406</a>
</li></ul></dd>


Expand Down Expand Up @@ -609,7 +609,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 04 2017 23:39:07 GMT+0300 (+03) using the Minami theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jan 06 2017 09:50:37 GMT+0300 (+03) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/module-salep.html
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ <h5>Type:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line311">line 311</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line312">line 312</a>
</li></ul></dd>


Expand Down Expand Up @@ -1706,7 +1706,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 04 2017 23:39:07 GMT+0300 (+03) using the Minami theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jan 06 2017 09:50:37 GMT+0300 (+03) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ function success(testCase) {
}

function skip(testOrCase) {
totalCount++;
skipCount++;
skipNextEnabled = false;
/**
Expand Down
11 changes: 6 additions & 5 deletions test/eventtest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** globals salep */
var testResult = true;

require("../src/index.js");
Expand Down Expand Up @@ -82,11 +83,11 @@ shouldTestStartEventCount++;

var result = salep.stop();

if (caseStartEventCount !== shouldCaseStartEventCount ||
failEventCount !== shouldFailEventCount ||
skipEventCount !== shouldSkipEventCount ||
successEventCount !== shouldSuccessEventCount ||
testStartEventCount !== shouldTestStartEventCount ||
if (caseStartEventCount !== shouldCaseStartEventCount ||
failEventCount !== shouldFailEventCount ||
skipEventCount !== shouldSkipEventCount ||
successEventCount !== shouldSuccessEventCount ||
testStartEventCount !== shouldTestStartEventCount ||
disabledCallbackCount !== shouldDisabledCallbackCount) {
testResult = false;
}
Expand Down
14 changes: 11 additions & 3 deletions test/failtest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/** globals salep */
require("../src/index.js");

var shouldFailCount = 0;
var shouldSkipCount = 0;
var shouldSuccessCount = 0;
var shouldTotalCount = 0;

salep.test("A test without any case", function() {

Expand All @@ -13,33 +15,39 @@ salep.test("A test with failing cases", function() {
throw "Fail 1";
});
shouldFailCount++;
shouldTotalCount++;

this.case("Fail case 2", function() {
throw "Fail 2";
});
shouldFailCount++;
shouldTotalCount++;

this.case("Success cases shouldn't increment fail count", function() {
// empty means success
});
shouldSuccessCount++;
shouldTotalCount++;
});

salep.case("A salep case to fail", function() {
throw "Fail 3";
});
shouldFailCount++;
shouldTotalCount++;

salep.case("A successful salep case", function() {
// empty
});
shouldSuccessCount++;
shouldTotalCount++;

var result = salep.stop();

if (result.skip === 0 &&
result.fail === shouldFailCount &&
result.success === shouldSuccessCount) {
if (result.skip === shouldSkipCount &&
result.fail === shouldFailCount &&
result.success === shouldSuccessCount &&
result.total === shouldTotalCount) {
exports.success = true;
} else {
exports.success = false;
Expand Down
13 changes: 9 additions & 4 deletions test/skiptest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/** globals salep */
require("../src/index.js");

var shouldSkipCount = 0;
var shouldFailCount = 0;
var shouldSuccessCount = 0;
var totalCount = 0;
var shouldTotalCount = 0;

// Skipping salep
salep.skipNext();
Expand All @@ -21,24 +22,28 @@ salep.test("should skip this test", function() {
});
});
shouldSkipCount++;
shouldTotalCount++

// Skipping salep cases
salep.skipNext();
salep.case("should skip this case and count it as skipped", function() {
throw "This exception shouldn't affect skip status";
});
shouldSkipCount++;
shouldTotalCount++;

salep.case("this shouldn't skip", function() {
// empty
});
shouldSuccessCount++;
shouldTotalCount++;

var result = salep.getResults();

if (result.skip === shouldSkipCount &&
result.fail === shouldFailCount &&
result.success === shouldSuccessCount) {
if (result.skip === shouldSkipCount &&
result.fail === shouldFailCount &&
result.success === shouldSuccessCount &&
result.total === shouldTotalCount) {
exports.success = true;
} else {
exports.success = false;
Expand Down

0 comments on commit ffa605b

Please sign in to comment.