<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#187; javascript</title>
	<atom:link href="http://monket.net/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://monket.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 12 Apr 2010 13:11:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Small Update to Loris (0.1.3)</title>
		<link>http://monket.net/blog/2010/04/small-update-to-loris-0-1-3/</link>
		<comments>http://monket.net/blog/2010/04/small-update-to-loris-0-1-3/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 13:11:21 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[loris]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=300</guid>
		<description><![CDATA[A few months ago I wrote about Loris, a small tool that will automatically run your javascript tests whenever a file changes. I&#8217;ve just released a new version of the Loris gem with a couple of minor fixes: The dependency on win32-process has now been removed from the gem. This means the gem now installs [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago <a href="http://monket.net/blog/2009/11/loris-autotest-for-javascript/">I wrote about Loris</a>, a small tool that will automatically run your javascript tests whenever a file changes.</p>

<p>I&#8217;ve just released a new version of the <a href="http://rubygems.org/gems/loris">Loris gem</a> with a couple of minor fixes:</p>

<ul>
<li><p>The dependency on <code>win32-process</code> has now been removed from the gem. This means the gem now installs correctly on OSX. Windows users will manually need to install the <code>win32-process</code> gem.</p></li>
<li><p>The dependancy on <code>visionmedia-bind</code> has been updated to just <code>bind</code>, reflecting the gems new name on RubyGems.</p></li>
<li><p>The JS Test Driver server is now reset between all tests. This stops it getting into a situation where it failed to pick up changes to files.</p></li>
</ul>

<p>Because <a href="http://rubygems.org/">RubyGems</a> is now the default gem host, this install process is a little simpler.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> loris</pre></div></div>


<p>or on Windows</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> loris
gem <span style="color: #c20cb9; font-weight: bold;">install</span> win32-process</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2010/04/small-update-to-loris-0-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnitAdapter 1.1.0</title>
		<link>http://monket.net/blog/2010/04/qunitadapter-1-1-0/</link>
		<comments>http://monket.net/blog/2010/04/qunitadapter-1-1-0/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 12:22:00 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=293</guid>
		<description><![CDATA[I&#8217;ve updated the JS Test Driver QUnitAdapter to improve compatibility with QUnit. Variables set on the this object within are now available within setup, teardown, and the tests themselves. module&#40;'Lifecycle', &#123; setup: function&#40;&#41; &#123; this.mockString = &#34;some string&#34;; &#125;, teardown: function&#40;&#41; &#123; equals&#40;this.mockString, &#34;some string&#34;&#41;; &#125; &#125;&#41;; &#160; test&#40;&#34;Things assigned to this in setup are [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated the JS Test Driver <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnitAdapter</a> to improve compatibility with QUnit.</p>

<p>Variables set on the <code>this</code> object within are now available within setup, teardown, and the tests themselves.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  teardown<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    equals<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Things assigned to this in setup are available in test&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  equals<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mockString</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;some string&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>The <code>test</code> function now supports the optional second parameter of the expected number of assertions.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// declare that this test has expects 1 assertion</span>
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Test with expected defined as 2nd param'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>My thanks go to <code>anotherhero</code> for providing the <a href="http://code.google.com/p/js-test-driver/issues/detail?id=116">patch</a> to fix both these issues.</p>

<p>You can always <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">download the latest version of QUnitAdapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2010/04/qunitadapter-1-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting when a page is loaded from the browser cache</title>
		<link>http://monket.net/blog/2010/02/detecting-when-a-page-is-loaded-from-the-browser-cache/</link>
		<comments>http://monket.net/blog/2010/02/detecting-when-a-page-is-loaded-from-the-browser-cache/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 13:55:50 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=290</guid>
		<description><![CDATA[When a user presses the back button in their browser to return to a previous page, that page is usually loaded straight from the browser&#8217;s cache, without any requests being made to the server. When that page shows information that could be out of date (such a an old list of products in your basket) [...]]]></description>
			<content:encoded><![CDATA[<p>When a user presses the back button in their browser to return to a previous page, that page is usually loaded straight from the browser&#8217;s cache, without any requests being made to the server. When that page shows information that could be out of date (such a an old list of products in your basket) this can cause problems.</p>

<p>So how about we knock up a little code that allows us to determine whether the page has been loaded from the server or the browsers cache. Then we can reload those parts of the page that may need updating (such as the basket).</p>

<p>We can do this by setting a cookie on every response from the server, and modifying that cookie using javascript. We can then use this cookie to know whether the page has been loaded from the server or the browser cache.</p>

<h2>Setting the cookie on every response from the server</h2>

<p>We will use a <code>loadedFromBrowserCache</code> cookie to facilitate the cache detection. We will set it to <code>false</code> every time a page is loaded from the server.</p>

<p>You can use the <code>BrowserCacheIndicator</code> class below to manage the cookie.</p>

<h3>BrowserCacheIndicator.cs</h3>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> SevenDigital.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Com</span>.<span style="color: #0000FF;">Code</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> BrowserCacheIndicator <span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> CACHE_COOKIE <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;loadedFromBrowserCache&quot;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// This works with the javascript on the site to determine whether</span>
		<span style="color: #008080; font-style: italic;">// a page has been loaded from the browser cache</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// *Every time* a page is loaded from the server we need to set</span>
		<span style="color: #008080; font-style: italic;">// the loadedFromBrowserCache cookie to false</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// This method should be called in all Master Pages</span>
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> ClearCacheCookie<span style="color: #000000;">&#40;</span>HttpResponse response<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			response.<span style="color: #0000FF;">SetCookie</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> HttpCookie<span style="color: #000000;">&#40;</span>CACHE_COOKIE, <span style="color: #666666;">&quot;false&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<p>And then set the cookie in every Master page:</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> SevenDigital.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Com</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> ExampleMasterPage<span style="color: #008000;">:</span> BaseMasterPage <span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">readonly</span> BrowserCacheIndicator BrowserCacheIndicator <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BrowserCacheIndicator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			BrowserCacheIndicator.<span style="color: #0000FF;">ClearCacheCookie</span><span style="color: #000000;">&#40;</span>Response<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<h2>Using the cookie to know whether the page was loaded from the browser cache</h2>

<p>The <code>loadedFromBrowserCache</code> cookie will be reset set to <code>false</code> by the HTTP Response header every time the page is loaded from the server. But it will not be reset when the page is loaded from the cache. We can use this to our advantage by setting the <code>loadedFromBrowserCache</code> cookie to <code>true</code> in javascript.</p>

<p>Then we know that the browser was loaded from the cache if the cookie is true on page load (because it was not reset by the server).</p>

<p>We just need to make sure we check the cookie before we set it to <code>true</code>!</p>

<h3>browser-cache.js</h3>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Detect whether or not we are loading this page from the browser cache</span>
<span style="color: #006600; font-style: italic;">// Set the value $.loadedFromBrowserCache, which other scripts can use</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> CACHE_COOKIE <span style="color: #339933;">=</span> <span style="color: #3366CC;">'loadedFromBrowserCache'</span><span style="color: #339933;">;</span>
	jQuery.<span style="color: #660066;">loadedFromBrowserCache</span> <span style="color: #339933;">=</span> getCookie<span style="color: #009900;">&#40;</span>CACHE_COOKIE<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'true'</span><span style="color: #339933;">;</span>
	setCookie<span style="color: #009900;">&#40;</span>CACHE_COOKIE<span style="color: #339933;">,</span> <span style="color: #3366CC;">'true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Now we have a <code>$.loadedFromBrowserCache&lt;</code> variable that let&#8217;s us know whether the page was loaded from the browser cache.</p>

<p>Note, the above function can run immediately, it does not need to wait for the <code>jQuery</code> <code>ready</code> event, or the <code>window.onload</code> event as it does not modify the DOM.</p>

<h2>Using <code>$.loadedFromBrowserCache</code> to do something useful</h2>

<p>Now we can do something useful with the knowledge a page was reloaded from the cache. How about reloading the users basket to ensure it is always up to date:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Reload the basket using ajax</span>
<span style="color: #006600; font-style: italic;">// This is so that users still see the latest basket when using the back</span>
<span style="color: #006600; font-style: italic;">// button in their browsers</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">loadedFromBrowserCache</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		refreshBasket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2010/02/detecting-when-a-page-is-loaded-from-the-browser-cache/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>QUnitAdapter 1.0.3</title>
		<link>http://monket.net/blog/2009/11/qunitadapter-1-0-3/</link>
		<comments>http://monket.net/blog/2009/11/qunitadapter-1-0-3/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 07:32:34 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=285</guid>
		<description><![CDATA[Just a small update to the JS Test Driver QUnitAdapter. Version 1.0.3 has been released, and fixes a single bug: Issue 64: QUnit Adapter fails to run tests if you don&#8217;t include a module You can now declare tests without a module, and they will run under the Default Module. In previous versions these tests [...]]]></description>
			<content:encoded><![CDATA[<p>Just a small update to the JS Test Driver <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnitAdapter</a>. Version 1.0.3 has been released, and fixes a single bug:</p>

<p><strong><a href="http://code.google.com/p/js-test-driver/issues/detail?id=64">Issue 64</a>: QUnit Adapter fails to run tests if you don&#8217;t include a module</strong></p>

<p>You can now declare tests without a module, and they will run under the <code>Default Module</code>. In previous versions these tests would be silently ignored (whoops!).</p>

<p>You can always <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">download the latest version of QUnitAdapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/11/qunitadapter-1-0-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loris: Autotest for Javascript</title>
		<link>http://monket.net/blog/2009/11/loris-autotest-for-javascript/</link>
		<comments>http://monket.net/blog/2009/11/loris-autotest-for-javascript/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:26:54 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript lint]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[jspec]]></category>
		<category><![CDATA[loris]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=261</guid>
		<description><![CDATA[I&#8217;ve previously written a number of posts on javascript and autotest. Explaining how to integrate javascript lint, unit tests, and growl with the ruby Autotest project. While this all worked, it felt a little clunky as Autotest doesn&#8217;t natively support the idea of running multiple tasks one after the other. Rather than hack at the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve <a href="http://monket.net/blog/tag/autotest/">previously written a number of posts on javascript and autotest</a>. Explaining how to integrate javascript lint, unit tests, and growl with the ruby <a href="http://ph7spot.com/articles/getting_started_with_autotest">Autotest</a> project.</p>

<p>While this all worked, it felt a little clunky as Autotest doesn&#8217;t natively support the idea of running multiple tasks one after the other. Rather than hack at the Autotest codebase, I thought I&#8217;d get some ruby experience by rolling my own autotest-style framework. Not great for reuse of code, but a great way for me to learn :)</p>

<h2>Loris</h2>

<p>Loris will monitor your project and run <a href="http://www.javascriptlint.com/">Javascript Lint</a> and <a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a> whenever a file changes, it will report the results to the command line and using <a href="http://growl.info/">Growl</a>. If required, Loris will automatically start the JS Test Driver server and register your default browser with it.</p>

<h3>Installing</h3>

<p>Loris is hosted on <a href="http://gemcutter.org/">Gemcutter</a>, so you need to install their gem if you haven&#8217;t already.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> gemcutter
gem tumble</pre></div></div>


<p>Then to install Loris, just run the following:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> loris</pre></div></div>


<p>Loris has no command line options, and no configuration file (at the moment). It looks for configurations files to decide which tasks to run.</p>

<h3>Configuring Javascript Lint</h3>

<p>To enable Javascript Lint, create a <code>jsl.conf</code> file in the folder where you run Loris. This should be a standard Javascript Lint config file. If you need here is an <a href="http://mike.kruckenberg.com/archives/2009/03/configuration-options-for-javascript-lint.html">example Javascript Lint config file</a></p>

<p>You just need to specify which files Javascipt Lint should process. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">### Files
# Specify which files to lint
# Use &quot;+recurse&quot; to enable recursion (disabled by default).
# To add a set of files, use &quot;+process FileName&quot;, &quot;+process Folder\Path\*.js&quot;,
# or &quot;+process Folder\Path\*.htm&quot;.
#
+process src/js/*.js
+process tests/js/*.js</pre></div></div>


<p>If no <code>jsl.conf</code> file is found, the Javascript Lint task is silently skipped.</p>

<h3>Configuring JS Test Driver</h3>

<p>To enable JS Test Driver, create a <code>jsTestDriver.conf</code> file in the folder where you run Loris. This should be a standard <a href="http://code.google.com/p/js-test-driver/wiki/ConfigurationFile">JS Test Driver config file</a>.</p>

<p>This should specify which files JS Test Driver should process, and how it connects to the JS Test Driver server. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">server: http://localhost:9876
&nbsp;
load:
  - tests/qunit/equiv.js
  - tests/qunit/QUnitAdapter.js
&nbsp;
  - src/js/*.js
  - tests/js/*.js</pre></div></div>


<p>If no <code>jsTestDriver.conf</code> file is found, the JS Test Driver task is silently skipped.</p>

<p>To make it really simple to run JS Test Driver tests, if the server is set to run on <code>localhost</code>, and Loris doesn&#8217;t detect one running, it will automatically start one, and register your default browser with it.</p>

<p>This makes it a one step process to get automated tests up and running.</p>

<h3>Running</h3>

<p>To run, open a command line window, navigate to the root folder of your project, and run:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">loris</pre></div></div>


<p>Loris will run Javascript Lint, and JS Test Driver tasks (if it finds their configuration files), and will output the results on the command line.</p>

<h4>Example output</h4>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Javascript Lint
success
All files are clean
&nbsp;
0 error(s), 0 warning(s)
JS Test Driver
success
All tests pass
[PASSED] GreeterTest.testGreet
  [LOG] JsTestDriver Hello World!
[PASSED] GreeterTest.testGoodbye
[PASSED] GreeterTest.testSetName
[PASSED] GreeterTest.testSetNameAndNameParamter
[PASSED] Asserts.test OK true succeeds
[PASSED] Asserts.test Equals succeeds
  [LOG] about to call assertEquals
[PASSED] Asserts.test Same assert succeeds
[PASSED] Lifecycle.test Setup and Teardown are run, and can contain assertions
Total 8 tests (Passed: 8; Fails: 0; Errors: 0) (3.00 ms)
  Firefox 1.9.1.4 MacIntel: Run 8 tests (Passed: 8; Fails: 0; Errors 0) (3.00 ms)</pre></div></div>


<p>Every time you make a change to a Javascript file, or a configuration file, Loris will automatically re-run Javascript Lint and JS Test Driver. So you can instant feedback on your changes.</p>

<p>Loris will clear the command line when re-running tasks. So the latest run is always at the top of you command line.</p>

<p>Loris will also report a summary of each task using <a href="http://growl.info/">Growl</a> (if it is installed). This allows you to get quick feedback without needing to refer back to the command line on every change.</p>

<h3>Requirements</h3>

<p>JS Test Driver is written in Java, so you will need to have Java installed to run it.</p>

<p>To get Growl notifications, you will need to install either <a href="http://growl.info/">Growl for OSX</a> or <a href="http://www.growlforwindows.com/">Growl for Windows</a>. Growl for Windows requires the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&amp;displaylang=en">.NET Framework 2.0+</a>.</p>

<h3>Caveat</h3>

<p>Loris is pretty limited at the moment, I just wired up the basics to get it running for a work project.</p>

<p>It doesn&#8217;t have any configuration options at the moment, so you have to follow it&#8217;s assumptions for now. I&#8217;m happy to add configuration options for any element as required.</p>

<p>Loris only comes with a few tasks (Javascript Lint, JS Test Driver, JSpec, and RSpec), but I hope to allow it have new tasks added via new gems (kind of similar to Autotest).</p>

<p>It comes packaged with a version of Javascript Lint, and JS Test Driver, and will use it&#8217;s own versions. It only includes the OSX and Windows versions of Javascript Lint.</p>

<p>If you want to modify the code, just fork the <a href="http://github.com/karl/loris">Loris github project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/11/loris-autotest-for-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>QUnit to JSpec Adapter</title>
		<link>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/</link>
		<comments>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 08:07:16 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jspec]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=207</guid>
		<description><![CDATA[JSpec is a Javascript BDD framework with a lot of great things going for it: It can run without a browser (great for continuous integration servers), it has a Ruby style custom syntax which makes tests easier to write and read, and it uses a BDD style describe/should syntax. It’s a very tempting framework to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/">JSpec</a> is a Javascript BDD framework with a lot of great things going for it: It can run without a browser (great for continuous integration servers), it 
has a Ruby style custom syntax which makes tests easier to write and read, and 
it uses a BDD style describe/should syntax.</p>

<p>It’s a very tempting framework to use, but I already have a large collection
of tests using qunit. I don’t want to use two frameworks for one project, and I 
don’t want to rewrite 300+ tests, so what to do?</p>

<p>How about a QUnit to JSpec Adapter, in the vein of my 
<a href="http://github.com/visionmedia/js-mock-timers/tree/master">QUnit to JS Test Driver Adapter</a>. Just load the adapter into JSpec as a
normal javascript file, and you can now<code>exec()</code> qunit test files in JSpec.</p>

<h2>Downloading the QUnit to JSpec Adapter</h2>

<p>First up <a href="http://monket.net/blog/wp-content/uploads/2009/09/QUnitToJSpecAdapter.js">download the QUnit to JSpec Adapter</a>, or copy the code below, and
save it somewhere in your project (e.g. a <code>lib</code> folder).</p>

<h4><a href="http://monket.net/blog/wp-content/uploads/2009/09/QUnitToJSpecAdapter.js">QUnitToJSpecAdapter.js</a></h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
QUnitToJSpecAdapter
Version: 1.0.0
&nbsp;
Run qunit tests using JSspec
&nbsp;
This provides almost the same api as qunit.
&nbsp;
Tests must run sychronously, which means no use of stop and start methods.
You can use the JSpec mock timers to deal with timeouts, intervals, etc
&nbsp;
The qunit #main DOM element is not included. If you need to do any DOM manipulation
you need to set it up and tear it down in each test.
&nbsp;
*/</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    JSpec.<span style="color: #660066;">addMatchers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        be_ok <span style="color: #339933;">:</span> <span style="color: #3366CC;">'!!actual'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    JSpec.<span style="color: #660066;">context</span> <span style="color: #339933;">=</span> JSpec.<span style="color: #660066;">defaultContext</span><span style="color: #339933;">;</span>
    JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        modules<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    module <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> lifecycle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span>
            tests<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            setup<span style="color: #339933;">:</span>    <span style="color: #009900;">&#40;</span>lifecycle <span style="color: #339933;">&amp;&amp;</span> lifecycle.<span style="color: #660066;">setup</span><span style="color: #009900;">&#41;</span>    <span style="color: #339933;">?</span> lifecycle.<span style="color: #660066;">setup</span>    <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
            teardown<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>lifecycle <span style="color: #339933;">&amp;&amp;</span> lifecycle.<span style="color: #660066;">teardown</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> lifecycle.<span style="color: #660066;">teardown</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        JSpec.<span style="color: #660066;">describe</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                it<span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> adapter <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                        expectedAsserts<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
                        calledAsserts<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
&nbsp;
                        expect<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">expectedAsserts</span> <span style="color: #339933;">=</span> count<span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        ok<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>actual<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>actual<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">be_ok</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        equals<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">be</span><span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        start<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'start and stop methods are not available when using JSpec.<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">'Use the JSpec timer to deal with timeouts and intervals:<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> 
                                <span style="color: #3366CC;">'http://github.com/visionmedia/jspec/tree/master'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        <span style="color: #000066;">stop</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'start and stop methods are not available when using JSpec.<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">'Use the JSpec timer to deal with timeouts and intervals:<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> 
                                <span style="color: #3366CC;">'http://github.com/visionmedia/jspec/tree/master'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        same<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #339933;">++;</span>
                            JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">eql</span><span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'reset method is not available when using JSpec'</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                        isLocal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'with(adapter) {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">setup</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'try {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">testCallback</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'} catch(ex) { throw(ex); } finally {'</span> <span style="color: #339933;">+</span>
                        JSpec.<span style="color: #660066;">contentsOf</span><span style="color: #009900;">&#40;</span>QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">teardown</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                        <span style="color: #3366CC;">'} }'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>adapter.<span style="color: #660066;">expectedAsserts</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        JSpec.<span style="color: #660066;">expect</span><span style="color: #009900;">&#40;</span>adapter.<span style="color: #660066;">calledAsserts</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span>JSpec.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">equal</span><span style="color: #339933;">,</span> adapter.<span style="color: #660066;">expectedAsserts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            after_each<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                QUnitAdapter.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            after<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                QUnitAdapter.<span style="color: #660066;">modules</span>.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    test <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> testCallback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span><span style="color: #009900;">&#91;</span>JSpec.<span style="color: #660066;">context</span>.<span style="color: #660066;">QUnitAdapter</span>.<span style="color: #660066;">modules</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tests</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span>
            testCallback<span style="color: #339933;">:</span> testCallback
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<h2>Having some QUnit tests</h2>

<p>First up you need some qunit tests. Having the qunit test files in the <code>spec</code>
directory helps simplify loading them.</p>

<p>As an example you can use the following:</p>

<h4>qunit-tests.js</h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Examples'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'True is ok'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Examples with lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    started <span style="color: #339933;">=</span> <span style="color: #3366CC;">'yes'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  teardown<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ok<span style="color: #009900;">&#40;</span>started<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    started <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Test has started'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  equals<span style="color: #009900;">&#40;</span>started<span style="color: #339933;">,</span> <span style="color: #3366CC;">'yes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<h2>Configuring QUnit Support</h2>

<p>Then to enable QUnit tests to be run in JSpec, you must have JSpec load the
adapater as a normal javascript file, and<code>exec()</code> the QUnit test file as you
would a JSpec spec file.</p>

<p>For JSpec rhino support your <code>spec.rhino.js</code> file would look like:</p>

<h4>spec.rhino.js</h4>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">load<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.10.0/lib/jspec.js'</span><span style="color: #009900;">&#41;</span>
load<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lib/QUnitAdapter.js'</span><span style="color: #009900;">&#41;</span>
&nbsp;
JSpec
.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'spec/qunit-tests.js'</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> formatter <span style="color: #339933;">:</span> JSpec.<span style="color: #660066;">formatters</span>.<span style="color: #660066;">Terminal</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">report</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>


<p>Notice how the QUnit test file is exec’d exactly as you would a normal spec
file. You can run specs and Qunit tests along side each other without any 
interference.</p>

<p>And for running the tests within a browser your <code>spec.dom.html</code> file would look
like:</p>

<h4>spec.dom.html</h4>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
    &lt;head&gt;
        &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.2.1/lib/jspec.css&quot; /&gt;
        &lt;script src=&quot;/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.2.1/lib/jspec.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;../lib/QUnitAdapter.js&quot;&gt;&lt;/script&gt;
        &lt;script&gt;
            function runSuites() {
                JSpec
                .exec('qunit-tests.js')
                .run()
                .report()
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body class=&quot;jspec&quot; onLoad=&quot;runSuites();&quot;&gt;
        &lt;div id=&quot;jspec-top&quot;&gt;&lt;h2 id=&quot;jspec-title&quot;&gt;JSpec &lt;em&gt;&lt;script&gt;document.write(JSpec.version)&lt;/script&gt;&lt;/em&gt;&lt;/h2&gt;&lt;/div&gt;
        &lt;div id=&quot;jspec&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;jspec-bottom&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>


<h2>Running the tests</h2>

<p>To run the tests just launch JSpec as normal. My prefered method is to run the
tests using rhino, to do this navigate to your project root directory in a 
terminal window and run:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jspec run <span style="color: #660033;">--rhino</span></pre></div></div>


<p>And you should now see your QUnit tests running in JSpec:</p>


<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;"> Passes: 5 Failures: 0
&nbsp;
 Examples
  True is ok..
&nbsp;
 Examples with lifecycle
  Test has started...</pre></div></div>


<h2>Limitations</h2>

<p>This adapter has many of the same limitations and my 
<a href="http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/">QUnit to JS Test Driver adapter</a>.</p>

<p>The tests must run synchronously (which means no use of the qunit <code>stop</code> and 
<code>start</code> methods).</p>

<p>If you need to test timeouts, intervals, or other asynchronous sections of code
, you can use the<a href="http://github.com/visionmedia/js-mock-timers/tree/master">mock timers that come with JSpec</a>.</p>

<p>QUnit DOM support is not included. Consider avoiding interacting directly with
the browser within your unit tests. But if you do need to, you’ll need to create
and remove the DOM objects yourself with each test, or the setup and teardown 
methods.</p>

<p>And lastly, tests are broken out of any closures before they run. This means
they lose access to any closure variables. For example, the follow test would 
work in QUnit, but not in JSpec. When running in JSpec access to the<code>setup</code>
variable is lost.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> setup <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do setup...</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/09/qunit-to-jspec-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUnit Adapter 1.0.2</title>
		<link>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/</link>
		<comments>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 20:14:51 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=203</guid>
		<description><![CDATA[A new version of the JS Test Driver QUnit Adapter is available. Version 1.0.2 fixes a small bug where a module lifecycle object without Setup or Teardown methods would cause a test to error. For example: module&#40;'Lifecycle', &#123;&#125;&#41;; &#160; test&#40;'', function&#40;&#41; &#123; expect&#40;1&#41;; ok&#40;true, 'tests still run successfully even if Setup and Teardown are undefined'&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>A new version of the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">JS Test Driver QUnit Adapter</a> is available.</p>

<p>Version 1.0.2 fixes a small bug where a module lifecycle object without Setup or Teardown methods would cause a test to error. For example:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Lifecycle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	expect<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ok<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'tests still run successfully even if Setup and Teardown are undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Would give the error <code>Lifecycle.test  error (1.00 ms): Result of expression 'l.setUp' [undefined] is not a function.</code>.</p>

<p>This is now fixed so the test behaves as if no lifecycle was defined.</p>

<p>You can get the new <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">1.0.2 verison of the QUnit Adapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/08/qunit-adapter-1-0-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running JS Test Driver in Team City</title>
		<link>http://monket.net/blog/2009/08/running-js-test-driver-in-team-city/</link>
		<comments>http://monket.net/blog/2009/08/running-js-test-driver-in-team-city/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 14:16:43 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[teamcity]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=193</guid>
		<description><![CDATA[JS Test Driver is a great new Javascript Testing Framework from the guys at Google. It provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this introduction to JS Test Driver by Miško Hevery for a great overview. Getting JS Test Driver up and running on your development workstation [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a> is a great new Javascript Testing Framework from the guys at Google. It provides a blisteringly fast, and easily automated way of running your Javascript unit tests. See this <a href="http://misko.hevery.com/2009/05/22/yet-another-javascript-testing-framework/">introduction to JS Test Driver by Miško Hevery</a> for a great overview.</p>

<p>Getting JS Test Driver up and running on your development workstation is easy enough. But how about on a continuous integration server such as <a href="http://www.jetbrains.com/teamcity/">TeamCity</a>?</p>

<p>It&#8217;s easy, just follow the instructions below!</p>

<h2>Install Java and the JS Test Driver jar on all the build agents</h2>

<p>JS Test Driver is packaged as a Java jar, and therefore all the TeamCity build agents will need a copy of Java and the JS Test Driver jar in order to run the tests.</p>

<ul>
<li>For each Build Agent</li>
<li><a href="http://www.java.com/en/download/manual.jsp">Download Java</a> and install it.</li>
<li><a href="http://code.google.com/p/js-test-driver/downloads/list">Download the JS Test Driver jar</a> and save it to <code>c:\TeamCityBuildTools\JSTestDriver\</code> (or whichever location you wish)</li>
</ul>

<h2>Configure JS Test Driver</h2>

<p>This guide assumes you already have JS Test Driver and some tests set up on your local machine. If not see this <a href="http://misko.hevery.com/2009/05/22/yet-another-javascript-testing-framework/">introduction to JS Test Driver by Miško Hevery</a>.</p>

<p>Just make sure that the JS Test Driver config file is set to connect to the local machine, on port 9876 (on another port of your choice).
E.g.</p>


<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">server: http://localhost:9876
&nbsp;
load:
  # list of files to load here...</pre></div></div>


<h2>Configure your build process to call JS Test Driver</h2>

<p>Now that we have JS Test Driver installed on our build machines, and configured correctly, let&#8217;s call it from our build process. At 7digital we are using MSBuild, so we can create a JSTestDriver Target as so:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;JSTestDriver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;##teamcity[progressMessage 'Running JS Test Driver']&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;-------- Running JS Test Driver --------&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;JSTestDriverJar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;quot;</span>$(BuildToolsPath)\JSTestDriver\jsTestDriver.jar<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/JSTestDriverJar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ConfigFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;quot;</span>$(SolutionFolder)\jsTestDriver.conf<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ConfigFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;IEPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;quot;</span>C:\Program Files\Internet Explorer\iexplore.exe<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/IEPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OutputDir<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;quot;</span>$(SolutionFolder)\output\JSTestDriver<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OutputDir<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;java -jar $(JSTestDriverJar) --port 9876 --browser $(IEPath) --config $(ConfigFile) --tests all --testOutput $(OutputDir)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<p>The important points here are that you have the properties configured correctly (JSTestDriverJar, ConfigFile, etc) for your individual setup.</p>

<p>The Exec command will automatically create a JS Test Driver server, launch IE, and run all the tests. The test results will be output to the OutputDir in a JUnit compatible xml format. See the <a href="http://code.google.com/p/js-test-driver/wiki/ContinuousBuild">JS Test Driver continuous integration page</a> for more information.</p>

<p>Once you have created this Target, ensure it is called by your standard bulid Target by adding it as a dependancy:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BuildAndUnitTest&quot;</span> <span style="color: #000066;">DependsOnTargets</span>=<span style="color: #ff0000;">&quot;Compile;JSLint;JSTestDriver;NUnit&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<h2>Have TeamCity pick up the test results</h2>

<p>If you run your build through TeamCity now, you will see that it runs all your Javascript tests using JS Test Driver. But it doesn&#8217;t report any results. And test failures don&#8217;t stop the build.</p>

<p>Luckily TeamCity can import the JS Test Driver output xml, because it is JUnit compatible.</p>

<ul>
<li>Select the build which is running the JS Test Driver tests</li>
<li>Click <code>Edit Configuration Settings</code></li>
<li>Click on build step 3 (e.g. <code>Runner: MSBuild</code>)</li>
<li>Under the <code>XML Report Processing</code> section, choose <code>Ant JUnit</code> from the <code>Import data</code> from dropdown</li>
<li>In the <code>Report paths</code> text area add the relative path the the JS Test Driver output file (e.g. <code>output\JSTestDriver\TEST-com.google.jstestdriver.1.xml</code>)</li>
<li>Click <code>save</code>!</li>
</ul>

<p>Now when you run your build again you will see your JS Test Driver tests showing up in the Tests tab, and test failures now stop the build.</p>

<p>Your Javascript unit tests now sit as first class citizens within TeamCity!</p>

<p><a href="http://monket.net/blog/wp-content/uploads/2009/08/JSTestDriverFailedTest.png"><img src="http://monket.net/blog/wp-content/uploads/2009/08/JSTestDriverFailedTest.png" alt="JSTestDriverFailedTest" title="JSTestDriverFailedTest" width="822" height="247" class="aligncenter size-full wp-image-198" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/08/running-js-test-driver-in-team-city/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Update to QUnit Adapter</title>
		<link>http://monket.net/blog/2009/07/update-to-qunit-adapter/</link>
		<comments>http://monket.net/blog/2009/07/update-to-qunit-adapter/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 06:32:25 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[qunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=154</guid>
		<description><![CDATA[I&#8217;ve made a small update to the QUnit Adapter for JS Test Driver. This fixes a bug where the ok() assertion was much stricter than the qunit equivalent. It was only succeeding when passed a boolean true value. Now it behaves the same as the qunit version, and succeeds with all values other than 0, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a small update to the <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnit Adapter for JS Test Driver</a>.</p>

<p>This fixes a bug where the <code>ok()</code> assertion was much stricter than the qunit equivalent. It was only succeeding when passed a boolean <code>true</code> value.</p>

<p>Now it behaves the same as the qunit version, and succeeds with all values other than <code>0</code>, <code>false</code>, or <code>null</code>.</p>

<p>You can get the new <a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">1.0.1 verison of the QUnit Adapter from Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/07/update-to-qunit-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jsUnit Mock Timeouts and JS Test Driver</title>
		<link>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/</link>
		<comments>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 16:45:30 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js test driver]]></category>
		<category><![CDATA[jsunit]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=139</guid>
		<description><![CDATA[As part of my experimenting with JS Test Driver, I have been porting over a suite of about 300 existing tests. Some of these tests deal with time based logic, such as delayed callbacks or time limited user interaction. Currently these tests are run in a HTML page using qunit. To deal with the time [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my experimenting with <a href="http://code.google.com/p/js-test-driver/">JS Test Driver</a>, I have been porting over a suite of about 300 existing tests.</p>

<p>Some of these tests deal with time based logic, such as delayed callbacks or time limited user interaction. Currently these tests are run in a HTML page using <a href="http://docs.jquery.com/QUnit">qunit</a>.</p>

<p>To deal with the time based logic I use the jsUnit&#8217;s Mock Timeout. See <a href="http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html">Simulating Time in jsUnit Tests on the Google Testing Blog</a>.</p>

<p>jsUnit&#8217;s Mock Timeout overrides the built in <code>setTimeout</code>, <code>clearTimeout</code>, <code>setInterval</code>, and <code>clearInterval</code> methods, and provides a <code>Clock</code> object that allows you to control the passage of time.</p>

<h2>Problem</h2>

<p>This works fine in qunit, but it fails catastrophically in JS Test Driver. This is because JS Test Driver uses the <code>setTimeout</code> and <code>setInterval</code> methods to control it&#8217;s own behaviour. Once these have been overridden with the mock versions JS Test Driver no longer works.</p>

<p>As a temporary fix for this I have created a patched version of JS Test Driver, which creates it&#8217;s own copies of the original <code>setTimeout</code>, <code>clearTimeout</code>, <code>setInterval</code>, and <code>clearInterval</code> methods, before loading any code. This ensures it works well with the jsUnit Mock Timeout.</p>

<h2>Patched JS Test Driver</h2>

<p><a href="http://monket.net/blog/wp-content/uploads/2009/07/JsTestDriver-1.0b-own-timeouts.jar">Download a patched JsTestDriver with no-confilict timeouts.</a></p>

<p>Just use this jar in place of the original <code>JsTestDriver-1.0b.jar</code>, and you can include <code>jsUnitMockTimeout.js</code> in your tests without breaking JS Test Driver!</p>

<p>You may also want to <a href="http://monket.net/blog/wp-content/uploads/2009/07/jsUnitMockTimeout.js">download jsUnitMockTimeout.js</a> (to save you finding it within the jsUnit source).</p>

<h2>The Future</h2>

<p>I see this patched JS Test Driver as very much a temporary stepping stone, while the correct solution is worked out. Beware of relying on it too heavily!</p>

<div class="info">

<p><strong>Update</strong>: <a href="http://groups.google.com/group/js-test-driver/browse_thread/thread/1393946af440ed90/c532267cd6c90710#c532267cd6c90710">This solution has been integrated into JS Test Driver</a>, and will be available in the next release.</p>

</div>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/07/jsunit-mock-timeouts-and-js-test-driver/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
