<?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>the tar pit &#187; jquery</title>
	<atom:link href="http://blog.goneopen.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.goneopen.com</link>
	<description>Thrashing around in the stickiness of software</description>
	<lastBuildDate>Mon, 09 Jan 2012 23:35:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Having Jasmine tests results in TeamCity via node.js (on windows) invoked from powershell</title>
		<link>http://blog.goneopen.com/2011/09/having-jasmine-tests-results-in-teamcity-via-node-js-on-windows-invoked-from-powershell/</link>
		<comments>http://blog.goneopen.com/2011/09/having-jasmine-tests-results-in-teamcity-via-node-js-on-windows-invoked-from-powershell/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 03:47:52 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[teamcity]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2011/09/having-jasmine-tests-results-in-teamcity-via-node-js-on-windows-invoked-from-powershell/</guid>
		<description><![CDATA[I test my javascript code via jasmine on a windows machine. I primarily write jquery-plugin-style code. Now I need to get this onto CI. A colleague I worked with took my test strategy in jasmine and wrote a library to run it very quickly on node.js. There are other places showing how to integrate with [...]]]></description>
			<content:encoded><![CDATA[<p>I test my javascript code via jasmine on a windows machine. I primarily write jquery-plugin-style code. Now I need to get this onto <span class="caps">CI.</span> A colleague I worked with took my test strategy in jasmine and wrote a library to run it very quickly on node.js. There are other places showing how to integrate with TeamCity and <a href="http://benshepheard.blogspot.com/2011/05/running-jasmine-tests-in-continuous.html">Jasmine with JsTestDriver</a> or <a href="http://joseoncode.com/2011/08/09/running-qunit-tests-in-teamcity/">Qunit</a> and also the documentation on how to easily <a href="http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ImportingXMLReports">integrate service messages with TeamCity</a>.</p>

<p>One caveat: I am not wanting to test cross-browser functionality. Therefore, I don&#8217;t need or want a browser or the associated slowness and the brittleness of cross-process orchestration. (Note: I have tried to stabilise these types of tests using NUnit and <span class="caps">MST</span>est runners invoking selenium and/or watin &#8211; it gets unstable quickly and there is too much wiring up.)</p>

<p>So this approach is simple and blindly fast thanks to <a href="http://andrewpmckenzie.github.com/node-jasmine-dom/">Andrew McKenzie&#8217;s jasmine-node-dom</a> which is an extension of <a href="https://github.com/mhevery/jasmine-node">jasmine-dom</a>. He wrote his for linux and his example is with Jenkins so I have forked a <a href="http://github.com/toddb/node-jasmine-dom">version for windows</a> which has a node.exe binary which is available form <a href="http://nodejs.org/#download">node.js</a>.</p>

<p>Anyway, this blog covers the powershell script to invoke the <code>jasmine-node-dom</code> and publish it to <code>TeamCity</code>.</p>

<p>Here&#8217;s the script:</p>

<h2>build.ps1 (or directly in TeamCity)</h2>



<pre class="brush:ps">
	
	$node_dir = &quot;node-jasmine-dom\bin&quot;	

	&amp; &quot;$node_dir\node.exe&quot; &quot;$node_dir\jasmine-dom&quot; `   
				--config tests.yaml `
				--format junit `
				--output javascript-results.xml 

	write-host &quot;##teamcity[importData type='junit' path='javascript-results.xml']&quot;    
	
</pre>



<p>An explanation if it isn&#8217;t obvious. First let&#8217;s start with files that are needed. I have the windows <a href="http://github.com/toddb/node-jasmine-dom">node-jasmine-dom</a> installed in its own directory. I then call <code>node.exe</code> with <code>jasmine-dom</code>. That should just work all out-of-the-box. I then tell it where the manifest is that knows about the tests (<code>tests.yaml</code> &#8211; see below for example) and then I give it the results file. <code>jasmine-node-dom</code> is great because it reads the <code>SpecRunner.html</code> and reconstructs the <code>DOM</code> enough that the tests are valid.</p>

<p>Finally, I tell teamcity to read the results out of <code>junit</code>. This is very easy and I recommend that you find out what else you need to do.</p>

<h2>tests.yaml</h2>



<pre class="brush:text">
	---
	  test_one:
	    name: Example test one
	    runner: ./tests/SpecRunner.html
</pre>



<p>This <code>yaml</code> file points to the <code>Jasmine</code> runner.</p>

<p>Other points: </p>

<p> * All my jasmine tests are invoked from their own <code>SpecRunner.html</code> file by convention<br />
 * I will write a script that will automatically generate the <code>yaml</code> file<br />
 * I always put all my powershell scripts into <code>psake</code> scripts (then they can be run by the dev or the build machine)<br />
 * my code isn&#8217;t quite filed as above</p>

<h2>Summary Instructions:</h2>

<p> # download jasmine-node-dom and install in <code>tools\</code> directory<br />
 # add new <code>Task</code> to build scripts (I use <code>psake</code>)<br />
 # add a new <code>test.yaml</code> manifest (or build one each time)<br />
 # Add new <code>jasmine</code> tests via <code>SpecRunner.html</code> with your javascript<br />
 # Ensure that the build script is run via a <em>build step</em> in a <em>configuration</em> from <code>TeamCity</code><br />
 # Now you can inspect the Tests in TeamCity</p>]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2011/09/having-jasmine-tests-results-in-teamcity-via-node-js-on-windows-invoked-from-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint &amp; TDD: Getting started advice</title>
		<link>http://blog.goneopen.com/2011/07/sharepoint-tdd-getting-started/</link>
		<comments>http://blog.goneopen.com/2011/07/sharepoint-tdd-getting-started/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 23:19:44 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsspec]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test automation pyramid]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2011/07/sharepoint-tdd-getting-started/</guid>
		<description><![CDATA[I have a couple of people asking lately about starting on SharePoint. They&#8217;ve asked about how to move forward with unit and integration testing and stability. No one wants to go down the mocking route (typemock, pex and moles) and quite rightly. So here&#8217;s my road map: The foundations: Hello World scripted and deployable without [...]]]></description>
			<content:encoded><![CDATA[<p>I have a couple of people asking lately about starting on SharePoint. They&#8217;ve asked about how to move forward with unit and integration testing and stability. No one wants to go down the mocking route (<code>typemock</code>, <code>pex and moles</code>) and quite rightly. So here&#8217;s my road map:</p>

<h2>The foundations: Hello World scripted and deployable without the <span class="caps">GUI</span></h2>


<ol>
<li>Get a Hello World SharePoint &#8220;app&#8221; &#8211; something that is packageable and deployable as a <code>WSP</code></li>
<li>Restructure the folders of the code away from the Microsoft project structure so that the root folder has <code>src/</code>, <code>tools/</code>, <code>lib/</code> and <code>scripts/</code> folders. All source and tests are in <code>src/</code> folder. This lays the foundation for a layered code base. The layout looks like this <a href="https://github.com/toddb/msbuild-deployment-sample">sample application</a></li>
<li>Make the compilation, packaging, installation (and configuration) all scripted. Learn to use <code>psake</code> for your build scripts and <code>powershell</code> more generally (particularly against the SharePoint 2010 <span class="caps">API</span>). The goal here is that devs can build and deploy through the command line. As such, so too can the build server. I have a suggestion <a href="http://blog.goneopen.com/2010/11/sharepoint-deployment-scripting-with-powershell/">here</a> that still stands but I need to blog on improvements. Most notably, not splitting out tasks but rather keeping them in the same <code>default.ps</code> (because <code>-docs</code> works best). Rather than get reuse at the <code>task</code> level do it as functions (or cmdlets). Also, I am now moving away from the mix with <code>msbuild</code> that I blogged <a href="http://blog.goneopen.com/2010/11/sharepoint-deployment-packaging/">here</a> and am moving them into powershell. There is no real advantage other than less files and reduced mix of techniques (and lib inclusions).</li>
<li>Create a build server and link this build and deployment to it. I have been using <span class="caps">TFS </span>and TeamCity. I recommend TeamCity but <span class="caps">TFS </span>will suffice. If you haven&#8217;t created Build Definitions in <span class="caps">TFS</span> Workflow allow days-to-weeks to learn it. In the end, but only in the end, it is simple. Becareful with <span class="caps">TFS, </span>the paradigm here is that build server does tasks that devs don&#8217;t. It looks a nice approach. I don&#8217;t recommend it and there is nothing here by design that makes this inevitable. In <span class="caps">TFS, </span>you are going to need to build two build definitions: <code>SharePointBuild.xaml</code> and <code>SharePointDeploy.xaml</code>. The build is a compile, package and test. The deploy simply deploys to an environment &#8211; Dev, Test, Pre-prod and Prod. The challenge here is to work out a method for deploying into environments. In the end, I wrote a simple self-host windows workflow (<code>xamlx</code>) that did the deploying. Again, I haven&#8217;t had time to blog the sample. Alternatively, you can use <code>psexec</code>. The key is that for a SharePoint deployment you must be running on the local box and the most configurations have a specific service account for perms. So I run a service for deployment that runs under that service account. </li>
</ol>



<p>Now that you can reliably and repeatably test and deploy, you are ready to write code!</p>

<h2>Walking Skeleton</h2>

<p>Next is to start writing code based on a <a href="http://blog.goneopen.com/2010/11/sharepoint-tdd-part-2-good-layering/">layered strategy</a>. What we have found is that we need to do two important things: (1) always keep our tests running on the build server and (2) attend to keeping the tests running quickly. This is difficult in SharePoint because a lot of code relates to integration and system tests (as defined by <a href="http://blog.goneopen.com/2010/08/test-automation-pyramid-review/">test automation pyramid</a>). We find that integration tests that require setup/teardown of a site/features get brittle and slow very quickly. In this case, reduce setup and teardown in the the system tests. However, I am also had a case where the integration test showed that a redesigned object (that facaded SharePoint) would give better testability for little extra work.</p>


<ol>
<li>Create 6 more projects based on a <span class="caps">DDD </span>structure (Domain, Infrastructure, Application, Tests.Unit, Tests.Integration &amp; Tests.System). Also rename your SharePoint project to <code>UI-[Your App]</code>, this avoids naming conflicts on a SharePoint installation. We want to create a <a href="http://alistair.cockburn.us/crystal/articles/hpaaa/hexagonalportsandadaptersarchitecture.htm">port-and-adapters</a> application around SharePoint. For example, we can wrap <a href="http://blog.goneopen.com/2011/05/sharepoint-tdd-part-7-repository-pattern-for-propertybag/">property bags</a> with repository pattern. This means that we create domain models (in Domain) and return them with repositories (in Infrastructure) and can test with integration tests.</li>
<li><strong>System tests:</strong> I have used <a href="http://storyq.codeplex.com/">StoryQ</a> with the team to write tests because it allows for a setup/teardown and then multiple test scenario. I could use <a href="http://www.specflow.org/">SpecFlow</a> or nBehave just as easily. </li>
<li><strong>Integration tests:</strong> these are written classical <span class="caps">TDD </span>style.</li>
<li><strong>Unit tests:</strong> these are written also classical <span class="caps">TDD</span>/BDD style</li>
<li><strong>Javascript tests</strong>: we write all javascript code using a jQuery plugin style (aka <a href="http://blog.rebeccamurphey.com/2009/10/15/using-objects-to-organize-your-code/">Object Literal</a>) &#8211; in this case, we use <a href="http://jania.pe.kr/aw/moin.cgi/JSSpec"><span class="caps">JSS</span>pec</a> (but I would now use <a href="http://pivotal.github.com/jasmine/">Jasmine</a>) &#8211; we put all tests in <code>Tests.Unit</code> but the actual javascript is still in the <code>UI-SharePoint</code> project. You will need two sorts of tests: <code>Example</code> for exploratory testing and <code>Specs</code> for the jasmine specs. I haven&#8217;t blogged about this and need to but is based on my work for writing <a href="http://plugins.jquery.com/project/jqueryplugingen">jQuery plugins with tests</a>.</li>
<li><strong>Deployment tests</strong>: these are tests that run once that application is deployed. You can go to an <span class="caps">ATOM </span>feed which returns the results of a series of tests that run against the current system. For example, we have the standard set with tells us the binary versions and which migrations (see below) have been applied. Others check whether a certain <code>wsp</code> has been deployed, different endpoints are listening, etc. I haven&#8217;t blogged this code and mean to &#8211; this has been great for testers to see if the current system is running as expected. We also get the build server to pass/fail a build based on these results.</li>
</ol>



<p>We don&#8217;t use <code>Pex and Moles</code>. We use exploratory testings to ensure that something actually works on the page</p>

<h2>Other bits you&#8217;ll need to sort out</h2>


<ul>
<li><strong>Migrations:</strong> if you have manual configurations for each environment then you&#8217;ll want to script/automate this. Otherwise, you aren&#8217;t going to be one-click deployments. Furthermore, you&#8217;ll need to assume that each environment is in a different state/version. We use <code>migratordotnet</code> with a SharePoint adapter that I wrote &#8211; it is <a href="https://github.com/toddb/migratordotnet">here for SharePoint 2010</a> &#8211; there is also a powershell runner in the source to adapt &#8211; you&#8217;ll need to download the source and compile. Migrations as an approach works extremely well for feature activation and publishing.</li>
<li><strong>Application Configuration:</strong> we use domain models for configuration and then instantiate via an infrastructure factory &#8211; certain configs require SharePoint knowledge</li>
<li><strong>Logging:</strong> you&#8217;ll need to sort of that Service Locator because in tests you&#8217;ll swap it out for Console.Logger</li>
<li><strong>WebParts:</strong> can&#8217;t be in a strongly typed binary (we found we needed another project!)</li>
<li><strong>Extension Methods to Wrap SharePoint <span class="caps">API</span></strong>: we also found that we wrapped a lot of SharePoint material with extension methods </li>
</ul>



<h2>Other advice: stay simple</h2>

<p>For SharePoint developers not used to object oriented programming, I would stay simple. In this case, I wouldn&#8217;t create code with abstractions that allowed you to unit test like <a href="http://blog.goneopen.com/2010/12/sharepoint-tdd-part-3-procedural-untestable-code/">this</a>. I found in the end the complexity and testability outweighed the simplicity and maintainability.</p>

<p>Microsoft itself has recommended the Repository Pattern to facade the SharePoint <span class="caps">API </span>(sorry I can&#8217;t for the life of me find the link). This has been effective. It is so effective we have found that we can facade most SharePoint calls in two ways:  a repository that returns/works with a domain concept or a <code>Configurator</code> (which has the single public method <code>Process()</code>).Anymore than that it was really working against the grain. All cool, very possible but not very desirable for a team which rotates people.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2011/07/sharepoint-tdd-getting-started/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jquery-bdd</title>
		<link>http://blog.goneopen.com/2010/08/jquery-bdd/</link>
		<comments>http://blog.goneopen.com/2010/08/jquery-bdd/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 02:06:04 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[test automation pyramid]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2010/08/jquery-bdd/</guid>
		<description><![CDATA[Notes from a jQuery session Structure of session: Jump into an example Build some new functionality Come back and see the major concepts Look at what is actually needed to treat javascript as a first-class citizen Different testing libraries Quick why a library in javascript? cross-browser abstraction (dynduo circa 1998 was still hard!) jQuery, MooTools, [...]]]></description>
			<content:encoded><![CDATA[<h1>Notes from a jQuery session</h1>

<h1>Structure of session:</h1>


<ul>
<li>Jump into an example</li>
<li>Build some new functionality</li>
<li>Come back and see the major concepts</li>
<li>Look at what is actually needed to treat javascript as a first-class citizen</li>
<li>Different testing libraries</li>
</ul>



<h1>Quick why a library in javascript?</h1>


<ul>
<li>cross-browser abstraction (dynduo circa 1998 was still hard!)</li>
<li>jQuery, MooTools, Extjs, Prototype, <span class="caps">GWT, YUI,</span> Dojo, &#8230;</li>
<li>I want to work with <span class="caps">DOM </span>with some UI abstractions &#8211; with a little general purpose</li>
<li>simple <span class="caps">HTML </span>traversing, event handling</li>
<li>also functional, inline style</li>
<li>I want plugin type architecture</li>
</ul>



<h1>Story plugin demo</h1>


<ul>
<li>Viewer of StoryQ results</li>
<li>StoryQ produces <span class="caps">XML, </span>this widget gives the <span class="caps">XML </span>a pretty viewer</li>
</ul>



<h2>A screenshot and demo</h2>


<ul>
<li><a href="http://github.com/toddb/jquery.storyq/raw/master/screenshot.png">jquery storyq plugin</a></li>
<li><a href="http://github.com/toddb/jquery.storyq">downloadable</a></li>
</ul>



<h2>What would your acceptance criteria be? What do you think some of the behaviours of this page are?</h2>

<p>Acceptance: </p>

<p>eg should display the <span class="caps">PROJECT </span>at the top with the number of tests</p>

<p>Behaviours:</p>

<p>think in terms of themes: data, display, events</p>

<h2>The tests &#8230; what does the application do?</h2>


<ul>
<li>run the tests and see the categories</li>
<li>data loading: xml</li>
<li>display: traversing xml and creating html</li>
<li>events: click handlers</li>
</ul>



<h1>Let&#8217;s build some new functionality!</h1>

<p>Goal: add &#8220;Expand All | Contract All | Toggle&#8221; functionality to the page</p>

<h2>Acceptance:</h2>


<ul>
<li>The user should be able to expand, collapse or toggle the tree</li>
</ul>



<h2>Specs</h2>

<p>Display:<br />
* should show &#8220;Expand All | Contract All | Toggle&#8221;<br />
Events:<br />
* should show all results when clicking expand all<br />
* should show only top class when clicked contract all<br />
* should toggle between all and one when clicking on toggle</p>

<h1>Coding: Add acceptance</h1>

<h1>Add Display specs</h1>

<h1>Add Event specs</h1>

<h1>Return back to completing the Acceptance</h1>

<h1>Major aspects we covered</h1>

<h2><span class="caps">HTML </span>traversing</h2>


<ul>
<li>I want to program akin to how I look at the page</li>
<li>I may look for: an element, a style, some content or a relationship</li>
<li>then perform an action</li>
</ul>



$(&#8216;div &gt; p:first&#8217;)<br />
$(&#8216;#mylist&#8217;).append(&#8220;<li>another item</li>&#8220;)

<h2>Event handling</h2>


<ul>
<li>I want to look at page and add event at that point</li>
<li>I want to load data (ie xml or json)</li>
</ul>



$(&#8216;div&#8217;).click(function(){<br />
	alert(&#8220;div clicked&#8221;)<br />
})<br />
$(&#8216;div&#8217;).bind(&#8216;drag&#8217;, function(){<br />
	$(this).addClass(&#8216;dragged&#8217;)<br />
})<br />
$(&#8216;#results&#8217;).load(&#8216;result.html&#8217;)<br />
$.get(&#8216;result.xml&#8217;, function(xml){<br />
	$(&#8220;user&#8221;, xml).each(function(){<br />
		$(&#8220;<li>&#8220;).text($(this).text()
			.appendTo(&#8220;#mylist&#8221;))<br />
	})<br />
})

<h2>Functional style</h2>


<ul>
<li>almost everything in jQuery are JQuery objects</li>
<li>that returns an object</li>
<li>every method can call a jQuery object</li>
<li>that means you can chain</li>
<li>plus I want it to be short code</li>
</ul>



<p>$(&#8216;<story>&#8216;)<br />
	.addClass(&#8216;indent&#8217;)<br />
	.addClass((idx == 4) ? &#8216;scenario&#8217; : &#8221;) <br />
	.text($(this).attr(&#8216;Prefix&#8217;) + &#8216; &#8216; + $(this).attr(&#8216;Text&#8217;))<br />
	.append($(&#8216;<result>&#8216;).text(&#8220;a child piece of text&#8221;)<br />
		.click(function(){ $(this).addClass(&#8216;click&#8217;)}))	<br />
	.appendTo(results)</p>

<h2>Plugin architecture</h2>


<ul>
<li>drop in a widget (including my own)</li>
<li>then combine, extend</li>
<li>help understand customisation</li>
<li>basically just work</li>
</ul>



<p>$(&#8216;#tree&#8217;).treeview();<br />
$.ajax({<br />
	url: &#8216;/update&#8217;,<br />
	data: <a href="http://+$('#name').val()">name</a>,<br />
	type: &#8216;put&#8217;,<br />
	success: function(xml){<br />
		$(&#8216;#flash&#8217;).text(&#8220;successful update&#8221;).addClass(&#8216;success&#8217;)<br />
	}<br />
})</p>

<h1>With power and simplicity &#8230; comes responsibility</h1>


<ul>
<li>the need to follow conventions<br />
  &#8211; plugins return an array<br />
  &#8211; plugins accept parameters but have clear defaults<br />
  &#8211; respect namespace</li>
<li>the need for structure<br />
 &#8211; test data<br />
 &#8211; min &amp; pack<br />
 &#8211; releases</li>
<li>the need to avoid mundane, time consuming tasks<br />
 &#8211; downloading jquery latest<br />
 &#8211; download jQuery UI<br />
 &#8211; building and releasing packages</li>
<li>needs tests<br />
 &#8211; I use jsspec</li>
</ul>



<p>Sounds like real software development?</p>

<h1>Treat javascript as a first-class citizen</h1>

<p>Give your plugin a directory structure:</p>

<p>/src<br />
  /css<br />
  /images<br />
  query.plugin.js<br />
/test<br />
  spec_plugin.js<br />
  acceptance_plugin.js<br />
  specs.html<br />
  acceptance.html<br />
/lib<br />
 /jsspec<br />
 jquery.min.js<br />
 jquery-ui.js<br />
 /themes<br />
   /base<br />
example.html<br />
Rakefile<br />
History.txt<br />
<span class="caps">README.</span>txt</p>

<h1>Generate your plugin boilerplate code</h1>

<p><a href="http://github.com/toddb/jQuery-Plugin-Generator">jQuery Plugin Generator</a> <br />
* gem install jquery-plugin-generator</p>

<p>(function($) {<br />
  $.jquery.test = {<br />
                <span class="caps">VERSION</span>: &#8220;0.0.1&#8243;,<br />
                defaults: {<br />
                        key: &#8216;value&#8217;<br />
                }<br />
        };</p>

<p>        $.fn.extend({<br />
          jquery.test: function(settings) {<br />
      		settings = $.extend({}, $.jquery.test.defaults, settings);<br />
      		return this.each( function(){<br />
        			self = this;<br />
         			// your plugin</p>

<p>      				})<br />
                }<br />
        })<br />
 })(jQuery);</p>

<h1>Use a build tool to do the &#8230; ah &#8230; building</h1>

<p>rake acceptance            # Run acceptance test in browser<br />
rake bundles:tm            # Install TextMate bundles from <span class="caps">SVN </span>for jQuery and&#8230;<br />
rake clean                 # Remove any temporary products.<br />
rake clobber               # Remove any generated file.<br />
rake clobber_compile       # Remove compile products<br />
rake clobber_package       # Remove package products<br />
rake compile               # Build all the packages<br />
rake example               # Show example<br />
rake first_time            # First time run to demonstrate that pages are wor&#8230;<br />
rake jquery:add            # Add latest jquery core, ui and themes to lib<br />
rake jquery:add_core       # Add latest jQuery to library<br />
rake jquery:add_themes     # Add all themes to libary<br />
rake jquery:add_ui         # Add latest jQueryUI (without theme) to library<br />
rake jquery:add_version    # Add specific version of jQuery library: see with&#8230;<br />
rake jquery:packages       # List all packages for core and ui<br />
rake jquery:packages_core  # List versions of released packages<br />
rake jquery:packages_ui    # List versions of released packages<br />
rake jquery:versions       # List all versions for core and ui<br />
rake jquery:versions_core  # List jQuery packages available<br />
rake jquery:versions_ui    # List jQuery UI packages available<br />
rake merge                 # Merge js files into one<br />
rake pack                  # Compress js files to min<br />
rake package               # Build all the packages<br />
rake recompile             # Force a rebuild of the package files<br />
rake repackage             # Force a rebuild of the package files<br />
rake show                  # Show all browser examples and tests<br />
rake specs                 # Run spec tests in browser</p>



<h1>Testing &#8230; acceptance and specs</h1>


<ul>
<li>specs: <span class="caps">BDD </span>style &#8211; <span class="caps">DOM </span>traversing and events</li>
<li>acceptance: tasks on the <span class="caps">GUI </span>with the packaged version (minified or packed)</li>
<li>these both server as good documentation as well</li>
<li>plus, you have demo page baked in!</li>
</ul>



<h1>Compiling and packaging</h1>


<ul>
<li>Compiling javascript &#8230; hhh? &#8230; yes, if you minify or pack your code</li>
<li>gzip compression with caching and header control is probably easier though</li>
<li>packed code is <span class="caps">HARD </span>to debug if it doesn&#8217;t work</li>
</ul>



<h1>Now you are ready for some development</h1>








<h1>Different ways to test Javascript</h1>

<p><a href="http://www.slideshare.net/jeresig/understanding-javascript-testing">Understanding JavaScript Testing</a></p>


<ul>
<li>testing for cross-browser issues &#8211; so this is useful if you are building javascript frameworks</li>
<li>Unit &#8211; QUnit, JsUnit, FireUnit, </li>
<li>Behvaiour &#8211; Screw.Unit, <span class="caps">JSS</span>pec, <span class="caps">YUIT</span>est, </li>
<li>Functional with browser launching &#8211; Selenium (IDE &amp; RC &amp; HQ), Watir/n, <span class="caps">JST</span>estDriver, WebDriver</li>
<li>Server-side: Crosscheck, env.js, blueridge</li>
<li>Distributed: Selenium Grid, TestSwarm</li>
</ul>



<h1>Reference</h1>

<p><a href="http://www.gscottolson.com/weblog/2008/01/11/jquery-cheat-sheet/">jQuery CheatSheet</a></p>


<ul>
<li>slide 48: great explanation of <span class="caps">DOM </span>manipulation &#8211; append, prepend, after, bfore, wrap, replace &#8230;</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2010/08/jquery-bdd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and testing &#8212; JSUnit, QUnit, JsSpec [Part 2]</title>
		<link>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-2/</link>
		<comments>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-2/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 10:34:14 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsspec]]></category>
		<category><![CDATA[jsunit]]></category>
		<category><![CDATA[qunit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-2/</guid>
		<description><![CDATA[Trying QUnit with jQuery In the JSUnit entry, one of the main problems was with the sequencing of calls. Let&#8217;s see how QUnit handles this. QUnit has a simple implementation to this problem: stop() and start() commands to synchronise sequences. The basic approach is that it calls a test function. With the stop() command, it [...]]]></description>
			<content:encoded><![CDATA[<h1>Trying QUnit with jQuery</h1>

<p>In the <a href="../jquery-and-testing-jsunit-qunit-jsspec-part-1/"><span class="caps">JSU</span>nit entry</a>, one of the main problems was with the sequencing of calls. Let&#8217;s see how QUnit handles this. QUnit has a simple implementation to this problem: <code>stop()</code> and <code>start()</code> commands to synchronise sequences. The basic approach is that it calls a test function. With the <code>stop()</code> command, it will not call the next test until you say <code>start()</code>. But it does complete the rest of the current test. </p>

<p>The code that I ended up with was just what I wanted compared to JsUnit. Previously, I had said that basically I wanted to call my function and then process the result that it was in fact what I wanted. Here is the main javascript code (it&#8217;s nice and concise).</p>

<p>One point about the code at this stage. The tests had to be inside the <code>success</code> function to be run. I wonder if this is going to create a code smell in the long run. Plus there is no setup/teardown cycles, again I wonder what that will mean in the long run. Perhaps not?</p>



<pre>module(&quot;XML to object&quot;);

test(&quot;Check the xml to object conversion without showing the tree&quot;, function() {
  
  expect( 5 )
  stop();
  
   $().storyq({
        url: 'data/results-01.xml', 
        load: '',
        success: function(feed) {
          ok( feed, &quot;is an object&quot; )
          ok( !$.isFunction(feed), &quot;is not a function&quot; )
          ok( feed.version, &quot;has a version: &quot; + feed.version )
          ok( feed.items, &quot;has items&quot;)
          same( feed, reference, &quot;is the same as the reference object in data/results-01.js&quot;)
          start();
        }
    });

});
</pre>



<p>Honestly, it is that easy. </p>

<p>Here&#8217;s a couple of features that took me half an hour to work out restated from above. (1) <code>stop()</code> and <code>start()</code> almost work as you expect &#8211; but I had to put some alerts in to check the order of execution. Basically, <strong>a <code>stop()</code> halts any new tests from executing but it keeps the current test executing</strong>. The effect of this is that the asynchronise call can be completed. <code>start()</code> then tells the tests to start running again. If you don&#8217;t have a <code>start()</code> then you will find that your test runner halts altogether. There is another option and that is to put a timer on the stop and then you don&#8217;t need a start. I prefer to keep the tests running as quickly as possible.</p>

<p>Just another note. I decided to do a <code>same()</code> comparison. I have saved and preloaded an object from a file for ease. This kept the test easy to read &#8211; my reference object here is quite long. You can see the insertion of this file in the entire code below <code>&lt;script type=&quot;text/javascript&quot; src=&quot;data/results-01.js&quot;/&gt;</code></p>



<pre>
&amp;lt;html&gt;
&amp;lt;head&gt;
  &amp;lt;title&gt;Unit tests for StoryQ Results viewer&amp;lt;/title&gt;
  &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../../lib/qunit/testsuite.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;

  &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../../lib/treeview/jquery.treeview.css&quot; /&gt;
  &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../../src/css/storyq.treeview.css&quot; /&gt;
  &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../../src/css/storyq.screen.css&quot; /&gt;

  &amp;lt;script src=&quot;../../lib/jquery/jquery.js&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../lib/jquery/jquery.cookie.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../lib/treeview/jquery.treeview.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../src/storyq.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../src/storyq.treeview.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../src/storyq.xml.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../src/storyqitem.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt;
  &amp;lt;script src=&quot;../../src/storyqresults.js&quot; type=&quot;text/javascript&quot;&gt;&amp;lt;/script&gt; 

  &amp;lt;script type=&quot;text/javascript&quot; src=&quot;../../lib/qunit/testrunner.js&quot;&gt;&amp;lt;/script&gt; 
  &amp;lt;script type=&quot;text/javascript&quot; src=&quot;data/results-01.js&quot;&gt;&amp;lt;/script&gt;  
  
  &amp;lt;script type=&quot;text/javascript&quot;&gt;
    module(&quot;XML&quot;);

    test(&quot;Check the xml to object conversion without showing the tree&quot;, function() {

      expect( 5 )
      stop();

       $().storyq({
            url: 'data/results-01.xml', 
            load: '',
            success: function(feed) {
              ok( feed, &quot;is an object&quot; )
              ok( !$.isFunction(feed), &quot;is not a function&quot; )
              ok( feed.version, &quot;has a version: &quot; + feed.version )
              ok( feed.items, &quot;has items&quot;)
              same( feed, reference, &quot;is the same as the refefence object in data/results-01.js&quot;)
              start();
            }
        });

    });
  &amp;lt;/script&gt;
  
&amp;lt;/head&gt;
&amp;lt;body&gt;
  
 &amp;lt;h1&gt;QUnit tests&amp;lt;/h1&gt;
 &amp;lt;h2 id=&quot;banner&quot;&gt;&amp;lt;/h2&gt;
 &amp;lt;h2 id=&quot;userAgent&quot;&gt;&amp;lt;/h2&gt;
 &amp;lt;ol id=&quot;tests&quot;&gt;&amp;lt;/ol&gt;

 &amp;lt;div id=&quot;main&quot;&gt;&amp;lt;/div&gt;

&amp;lt;/div&gt;
&amp;lt;/div&gt;

&amp;lt;/body&gt;
&amp;lt;/html&gt;

</pre>



<p>The output results from QUnit are nice to look at and easy to read. I didn&#8217;t have a couple of errors that weren&#8217;t the easiest to debug given the output. Partly though because I was new to it, I was taking too big a step at times!</p>

<p>I&#8217;m happy with QUnit &#8211; and there are plenty of examples in the JQuery test suite. I can see that I would do <span class="caps">TDD </span>with this.</p>

<p>Being a <span class="caps">BDD </span>type of guy, I&#8217;m now off to see what <a href="../jquery-and-testing-jsunit-qunit-jsspec-part-3/" title="Part III">JsSpec</a> has to offer.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and testing &#8211; JSUnit, QUnit, JsSpec [Part 1]</title>
		<link>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-1/</link>
		<comments>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-1/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:32:11 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsspec]]></category>
		<category><![CDATA[jsunit]]></category>
		<category><![CDATA[qunit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test automation pyramid]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-1/</guid>
		<description><![CDATA[Trying JsUnit with JQuery I have started first with JSUnit because it is tried and true (and to tell the truth I thought it would be fine and didn&#8217;t bother with a quick search for alternatives). For the impatient, I won&#8217;t be going with JSUnit and here are some reasons: the problem is that the [...]]]></description>
			<content:encoded><![CDATA[<h1>Trying JsUnit with JQuery</h1>

<p>I have started first with <span class="caps">JSU</span>nit because it is tried and true (and to tell the truth I thought it would be fine and didn&#8217;t bother with a quick search for alternatives).</p>

<p>For the impatient, I won&#8217;t be going with <span class="caps">JSU</span>nit and here are some reasons:</p>


<ul>
<li>the problem is that the integration of a setup (ie onload &#8211; pausing) to load the data doesn&#8217;t integrate well with jQuery. <span class="caps">JSU</span>nit has its own setup and document loader but I am still wondering how to do this transparently (ie I didn&#8217;t actually get the test to work &#8211; I wasn&#8217;t exhaustive but then again I don&#8217;t think that I should have needed to be to get this test going)</li>
<li>Firefox 3.0 on mac doesn&#8217;t integrate well (ie it doesn&#8217;t work), but safari does! Unfortunately, I am a little bound to firebug for development. </li>
<li><span class="caps">JSU</span>nit doesn&#8217;t report tests well either</li>
</ul>



<p>I went and had a look at how <span class="caps">JSU</span>nit does it. (Remember that this framework has been around a lot longer than jQuery.) Here is the extract from the code/test samples. The basic setup is to hook into an existing <code>testManager</code> that existing within a frame and then get the data from there. Furthermore, you need to manage your own flag that the process has been complete. <span class="caps">JSU</span>nit then looks through all functions that start with <code>test</code> in this case <code>testDocumentGetElementsByTagName</code> checks expected data. Here I assume that the tests are run in a particular frame (<code>buffer()</code>) that <code>testManager</code> gives us access to.</p>



<pre>var uri = 'tests/data/data.html';

function setUpPage() {
    setUpPageStatus = 'running';
    top.testManager.documentLoader.callback = setUpPageComplete;
    top.testManager.documentLoader.load(uri);
}

function setUpPageComplete() {
    if (setUpPageStatus == 'running')
        setUpPageStatus = 'complete';
}

function testDocumentGetElementsByTagName() {
    assertEquals(setUpPageStatus, 'complete');
    var buffer = top.testManager.documentLoader.buffer();
    var elms = buffer.document.getElementsByTagName('P');
    assert('getElementsByTagName(&quot;P&quot;) returned is null', elms != null);
    assert('getElementsByTagName(&quot;P&quot;) is empty', elms.length &gt; 0);
}</pre>



<p>Below is the rewritten code to exercise my code. Here&#8217;s a couple of the features:</p>


<ul>
<li>for setup, pass in the correct xml file via <code>uri</code> variable (obviously)</li>
<li>to test, I have written a test <code>testXML2Object</code>. <br />
 <br />
p. There is one major design problem with the code itself that didn&#8217;t allow me to use my own data loader. You will see the line <code>var feed = new StoryQResults(buffer);</code>. Where did that come from? It is nothing close to the code I said that I wanted to exercise. It is infact from <strong>within</strong> the code I want to exercise. The major issue I found here is that to load and test data I had to use the <code>testManager</code> rather than use my own  <code>().storyq()</code> call. </li>
</ul>



<p>The other problem was it wouldn&#8217;t return the result that I wanted either. I was expecting my <code>feed</code> variable to be an object of the results. Instead I was getting a reference to function <code>StoryQResults</code> &#8211; given now that it wasn&#8217;t running in Firefox and I didn&#8217;t have Firebug life was getting a little hard.<br />
 </p>


<pre>var uri = '../../xml/results-01.xml';

function setUpPage() {
    setUpPageStatus = 'running';
    top.testManager.documentLoader.callback = setUpPageComplete;
    top.testManager.documentLoader.load(uri);
}

function setUpPageComplete() {
    if (setUpPageStatus == 'running')
        setUpPageStatus = 'complete';
}

function testXML2Object() {
    assertEquals(setUpPageStatus, 'complete');
    var buffer = top.testManager.documentLoader.buffer();
    
    var feed = new StoryQResults(buffer);               

    assertEquals(feed.version, '0.1')
    assertEquals(&quot;Number of stories&quot;, $(feed).size(), 1)
    $.each(feed, function(){
      alert(this)               
    })

}</pre>



<p>Even though I know that I getting a <code>function</code> returned instead of an <code>object</code> I am still going to see if I can invoke my own loading function within <span class="caps">JSU</span>nit. Here&#8217;s what the code would look like below. I wouldn&#8217;t recommend running it &#8211; just take a look at it. The code to me is a mixtures of styles that start to bloat the code. On the one hand, <span class="caps">JSU</span>nit has this setup phase with explicit flags and no anonymous functions. On the other hand, because I am using JQuery conventions, I encapsulate alot of that logic. For example, <code>jQuery(function(){})</code> waits for the page to be loaded before executing <code>(&quot;#tree&quot;).story()</code>, Then I have the callback function inline. It looks good from the outside, but it doesn&#8217;t work. </p>

<p>The order of calls is: <code>loading</code>, <code>in test</code> and then <code>loaded</code>. Indicating that my <code>JQuery</code> function runs after the test has been run. The order should have been <code>loading</code>, <code>loaded</code> and then <code>in test</code>. In this sense, while <code>setUpPage</code> runs within its own setup/test/teardown cycle. But my JQuery call isn&#8217;t linked into this. JQuery waits is waiting on a document flag rather than a custom flag (within <code>testManager</code>). At this point, I do not wish to dig into these libraries to work them out to get it to all play nicely. It wasn&#8217;t designed to work this way. Let&#8217;s find one that was.</p>



<pre>var data = '';

function setUpPage() {
    setUpPageStatus = 'running';
    alert('loading')
    jQuery(function() {
      $(&quot;#tree&quot;).storyq({
          url: '../../xml/results-01.xml', 
          success: null, 
          load: function(feed) {
            data = feed;
            alert('loaded')
            setUpPageComplete()
            }
          });
    });
}

function setUpPageComplete() {
    if (setUpPageStatus == 'running')
        setUpPageStatus = 'complete';
}

function testXML2Object() {
    alert('in test')
    assertEquals(setUpPageStatus, 'complete');

    assertEquals(data.version, '0.1')
    assertEquals(&quot;Number of stories&quot;, $(feed).size(), 1)
}
</pre>



<p>I&#8217;m invoking the two-feet principle: I&#8217;m moving onto the next framework (after a quick search): <a href="../jquery-and-testing-jsunit-qunit-jsspec-part-2/">QUnit</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and testing &#8211; JSUnit, QUnit, JsSpec [Part 3]</title>
		<link>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-3/</link>
		<comments>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-3/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 02:35:22 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsspec]]></category>
		<category><![CDATA[jsunit]]></category>
		<category><![CDATA[qunit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test automation pyramid]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-3/</guid>
		<description><![CDATA[Trying JsSpec with jQuery This is part three of three. The previous two have been focussed around managing the problem of timing: JSUnit got too hard and QUnit is easy but you still have to manage timings yourself. With JsSpec there is no problem because it is all managed for you. Nice work! Here&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<h1>Trying JsSpec with jQuery</h1>

<p>This is part three of three. The previous two have been focussed around managing the problem of timing: <a href="../jquery-and-testing-jsunit-qunit-jsspec-part-1/" title="Part I"><span class="caps">JSU</span>nit</a> got too hard and <a href="../jquery-and-testing-jsunit-qunit-jsspec-part-2/" title="Part II">QUnit</a> is easy but you still have to manage timings yourself. With JsSpec there is no problem because it is all managed for you. Nice work! Here&#8217;s the code I had to write. </p>

<p>A couple of things to writing it. I had to dig into the code to find out the setup/teardown lifecycle keywords. There turns out to be setup/teardown per test (eg <code>before</code>) and per test suite (eg <code>before all</code>). I also had to dig around to find then comparators (eg <code>should_be</code>, <code>should_not_be_null</code>). I couldn&#8217;t find any documentation.</p>



<pre>
describe('I need to read the xml and convert into object', {
  'before all': function() {
    target = {};
    $().storyq({
        url: 'data/results-01.xml', 
        load: '',
        success: function(feed) {
          target = feed
      }
    })
   
  },
  
  'should return an object': function() {
    value_of(target).should_not_be_null()
  },
  
  'should not be a function': function() {
    value_of(typeof target).should_not_be(typeof Function )
  },
  
  'should have a version': function(){
    value_of(target.version).should_be('0.1')
  },
  
  'should have items': function(){
    value_of(target.items).should_not_be_empty()
  },
  
  'should have the same value as the reference object in data/results-01.js': function(){
    value_of(reference).should_not_be_undefined()
    value_of(target).should_be(reference)
  },
  
})
</pre>



<p>Ihe output looks nice too <img src='http://blog.goneopen.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Here&#8217;s the overall code. Notice that I have also used the technique of a reference object in <code>results-01.js</code>:</p>



<pre>
&amp;lt;html&gt;
&amp;lt;head&gt;
&amp;lt;title&gt;JSSpec results&amp;lt;/title&gt;
&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../lib/jsspec/JSSpec.css&quot; /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;../lib/jsspec/JSSpec.js&quot;/&gt;

&amp;lt;script src=&quot;../lib/jquery/jquery.js&quot;/&gt;
&amp;lt;script src=&quot;../lib/jquery/jquery.cookie.js&quot; type=&quot;text/javascript&quot;/&gt;
&amp;lt;script src=&quot;../lib/treeview/jquery.treeview.js&quot; type=&quot;text/javascript&quot;/&gt;
&amp;lt;script src=&quot;../build/dist/jquery.storyq.js&quot; type=&quot;text/javascript&quot;/&gt;

&amp;lt;script type=&quot;text/javascript&quot; src=&quot;data/results-01.js&quot;/&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;specs/treeview.js&quot;/&gt;  

&amp;lt;script type=&quot;text/javascript&quot;&gt;

  describe('I need to read the xml and convert into object', {
    'before all': function() {
      target = {};
      $().storyq({
          url: 'data/results-01.xml', 
          load: '',
          success: function(feed) {
            target = feed
        }
      })

    },

    'should return an object': function() {
      value_of(target).should_not_be_null()
    },

    'should not be a function': function() {
      value_of(typeof target).should_not_be(typeof Function )
    },

    'should have a version': function(){
      value_of(target.version).should_be('0.1')
    },

    'should have items': function(){
      value_of(target.items).should_not_be_empty()
    },

    'should have the same value as the reference object in data/results-01.js': function(){
      value_of(reference).should_not_be_undefined()
      value_of(target).should_be(reference)
    },

  })
&amp;lt;/script&gt;

&amp;lt;/head&gt;
    &amp;lt;body&gt;
      &amp;lt;div style=&quot;display:none;&quot;&gt;&amp;lt;p&gt;A&amp;lt;/p&gt;&amp;lt;p&gt;B&amp;lt;/p&gt;&amp;lt;/div&gt;
    &amp;lt;/body&gt;
&amp;lt;/html&gt;
</pre>



<p><span class="caps">JSS</span>pec isn&#8217;t written using JQuery. So there are a couple of issues that I can&#8217;t pin down. When I get errors it stops the tests completely. I suspect that this is because these tests are using callbacks and they don&#8217;t return an (JQuery) object. JQuery does alot of object chaining and JsSpec isn&#8217;t cut out for it (I think).</p>

<p>Well, that&#8217;s it.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and testing &#8211; JSUnit, QUnit, JsSpec [Introduction]</title>
		<link>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-introduction/</link>
		<comments>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-introduction/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 06:32:42 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsspec]]></category>
		<category><![CDATA[jsunit]]></category>
		<category><![CDATA[qunit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test automation pyramid]]></category>
		<category><![CDATA[UnitTesting]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-introduction/</guid>
		<description><![CDATA[I had been writing a jQuery parser and then realised once I had spiked it that I hadn&#8217;t actually written any tests. So, these are some results from a spike in unit testing a jQuery plugin. Some background, the plugin is a results viewer from an xml feed from storyq. So, I have run some [...]]]></description>
			<content:encoded><![CDATA[<p>I had been writing a jQuery parser and then realised once I had spiked it that I hadn&#8217;t actually written any tests. So, these are some results from a spike in unit testing a jQuery plugin.</p>

<p>Some background, the plugin is a results viewer from an xml feed from storyq. So, I have run some tests and have results. Now I want to see them in html format. The plugin merely transforms the xml to be displayed using the treeview plugin. I wanted to avoid handing in a json feed formatted specifically for the treeview. I wanted all this to happen client side.</p>

<p>The tests have two aspects:</p>


<ul>
<li>xml loading and parsing into an object</li>
<li>rendering the object into a tree (at that point treeview takes over)<br />
 <br />
In short, I want to test the code underlying this call that returns the <code>feed</code> before populating an <code>&lt;ul id=&quot;tree&quot;&gt;</code> element:</li>
</ul>





<pre>$('#tree').storyq({
    url: 'tests/data/results-01.xml',   
    success: function(feed) {

      $(&quot;#tree&quot;).treeview(); //populate the tree
  
  }    
});
</pre>



<h2>Problem for any framework: sequencing</h2>

<p>Let&#8217;s take a look at what I want as test code. In this code, I want to populate <code>data</code> with the <code>feed</code> variable returned in the <code>success</code> callback. The test can then check for values. Take a look at the code below. When I run the code, I should (ideally) see the sequence of alerts: <code>loaded</code>, <code>start test</code>, <code>end test</code>. Of course, I don&#8217;t. I see start <code>start test</code>, <code>end test</code>, <code>loaded</code> as the sequence. That should be obvious that the callback success hasn&#8217;t been called as yet: javascript is run sequentially. Okay, nothing here is surprising. I laboured this point because any of the frameworks must deal with this problem.</p>



<pre>var data = {};

jQuery(function() {
  $().storyq({
      url: '../../xml/results-01.xml', 
      success: function(feed) {
        data = feed;
        alert('loaded')       
        }
      });
});

function testXML2Object() {
  alert('start test')
  assertEquals(data, {&quot;result&quot;}, &quot;Assume that result is a real/correct object&quot;);
  alert('end test')     
}
</pre>



<h2>Frameworks looked at</h2>

<p>I looked at three frameworks for xml loading and parsing:</p>


<ul>
<li><a href="../jquery-and-testing-jsunit-qunit-jsspec-part-1/"><span class="caps">JSU</span>nit &#8211; Part I</a></li>
<li><a href="../jquery-and-testing-jsunit-qunit-jsspec-part-2/">QUnit &#8211; Part II</a></li>
<li><a href="../jquery-and-testing-jsunit-qunit-jsspec-part-3/">JsSpec &#8211; Part <span class="caps">III</span></a></li>
</ul>



<h2>Conclusions</h2>


<ul>
<li>In short, QUnit and JsSpec are both as easy as the other. <span class="caps">JSU</span>nit seems now to be too heavy given what we now have.</li>
<li>QUnit is a <span class="caps">TDD </span>framework is used by jQuery itself. I suspect it might survive longer. There are no setup/teardown phases.</li>
<li>JsSpec is a <span class="caps">BDD </span>framework and doesn&#8217;t use jQuery at all but can easily be used with JQuery plugins. There are good setup/teardown phases for tests and suites.</li>
<li>Your choice between the two is likely to be your preference between <span class="caps">TDD </span>or <span class="caps">BDD.</span> It probably depends upon which boundaries you want to test and how you want to go about specifying.</li>
</ul>



<h2>What I didn&#8217;t do:</h2>


<ul>
<li>integration with a CI system</li>
<li>cross-browser testing</li>
<li>test with selenium or watir</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/11/jquery-and-testing-jsunit-qunit-jsspec-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery vs XSLT as REST client for XML resource in the browser</title>
		<link>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/</link>
		<comments>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 05:50:20 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/</guid>
		<description><![CDATA[This work is to try and help through thinking about XML results through REST in a browser. If we are going to view the results (in a browser) what are the options that treat the results as a GET resource? Here are the sample files. Conclusions: Parsing XML files is a no brainer to display [...]]]></description>
			<content:encoded><![CDATA[<p>This work is to try and help through thinking about <span class="caps">XML </span>results through <span class="caps">REST </span>in a browser. If we are going to view the results (in a browser) what are the options that treat the results as a <span class="caps">GET </span>resource?</p>

<p><a href="http://blog.goneopen.com/wp-content/uploads/2008/10/storyq-results.zip">Here</a> are the sample files.</p>

Conclusions:<br />
<ul>
<blockquote>
	<li>Parsing <span class="caps">XML </span>files is a no brainer to display in <span class="caps">HTML</span></li>
	<li> I&#8217;d probably avoid using the browser&#8217;s xslt engine though &#8211; so xslt through javascript is simplified</li>
</blockquote>
</ul>
<ul>
<blockquote>
	<li> JQuery is central to the real presentation functionality</li>
	<li> I&#8217;d start with option 2 personally and then add XPath as needed to target information and then if this display got more complex add in <span class="caps">XSLT</span></li>
</blockquote>
</ul>
<ul>
<blockquote>
	<li> You can get there either through (1) <span class="caps">XSLT, </span>(2) JQuery itself or (3) JQuery + <span class="caps">XSLT </span>+ XPath &#8211; you really should be familiar with them all anyway</li>
</blockquote>
</ul>
Here&#8217;s a couple of main options:<br />
<ol>
	<li> XML + <span class="caps">XSLT</span>/XPath -&gt; <span class="caps">HTML </span>+ JQuery =&gt; Display</li>
	<li><span class="caps">HTML </span>+ JQuery ++XML =&gt; Display</li>
	<li><span class="caps">HTML </span>+ JQuery +<acronym title="JS">XSLT</acronym> ++XML =&gt; Display</li>
	<li>Flex (+ <span class="caps">HTML</span>) ++XML =&gt; Display</li>
</ol>
I have looked at the first two. And that is what I will try and explain. I suspect the other two options are also good. I do have a concern that in using the <span class="caps">XSLT </span>parser within a JS plugin it is perhaps delegating too much work to JS (maintenance of enough functionality will probably become an issue). Also beyond that I was looking at is the hyperlinking of resources (my hunch is that JS or Flex will be the way to load and traverse hyperlinked resources)

<p>I think that the major concern:</p>


<ul>
<li>is a separation of concerns</li>
<li>keeping a resource as data that can be asked for and can ask for a service to act on it</li>
</ul>



<p>Separation of concerns:</p>


<ol>
<li>The <span class="caps">XML </span>needs to have a life of its own as a resource</li>
<li>The client needs to be able to act on the resource</li>
<li>The client needs to be in control of all of this and don&#8217;t want logic to be hiding at the server</li>
<li>On the client, I want to keep separate layout from content from skin</li>
<li>For development, I wouldn&#8217;t mind some intellisense; I want good debugging help</li>
</ol>



<p>Some findings:</p>


<ul>
<li>One thing to note is that for both approaches I bind a data source to a control. Here I read in <span class="caps">XML </span>and load it into an object and then bind this object to the control which then appends the table to the <span class="caps">DOM </span>object. This control can also be bound to an html table. In this case, you put a table into the <span class="caps">DOM </span>and then the control transforms the table. The later seemed to me to be a server-side solution rather than a late-binding to a resource.</li>
<li>I also did a sample <span class="caps">XSLT </span>of creating table in <span class="caps">HTML </span>from the results (results-as-html-table.xsl). The code was too long for me! I have include that file in the source for reference.<br />
<h2>Option One: <span class="caps">XML </span>+ <span class="caps">XSLT</span></h2><br />
This was my initial reaction as the way forward for this solution. Personally, I like <span class="caps">XSLT </span>and its declarative nature. But, in practice, I still find it a little slow to programme (I really do forget the syntax and have to relearn it each time &#8211; particularly if you start to heavily use namespaces).</li>
</ul>




<ul>
<li>The xslt on a browser has to have a reference to an xsl in the <span class="caps">XML </span>- this really isn&#8217;t that good as there is only one view per xml (although if you were working outside of the browser this need not be a problem)</li>
<li><span class="caps">XML </span>in many ways does act on itself because it puts an <span class="caps">XSLT </span>across it (although limited to one)</li>
<li>It was harder to debug the JS in the xslt mode and generally took longer to working in <span class="caps">XSLT</span></li>
<li>The key thing to remember is that the target platform is <span class="caps">HTML</span>/JS and <span class="caps">XSLT </span>is good for transformations from one structure to another. The problem is that while <span class="caps">XHTML </span>is <span class="caps">XML </span>we are really in a programming mode rather than a transformation mode. I think that the part that is best for the tranformation via XPath is taking the results and combining the bits of information together (that is this case would be in a cell).</li>
<li>I had add extra code to late-bind the data into the control as it wasn&#8217;t designed to be used in this way (you could rewrite the component to reduce code though)</li>
</ul>



In summary, as the transformations got larger, this might still work well. You will need to write a number of xsl files to allow for good modularisation (see DocBook if you have any doubt on this one). In doing, so you can keep alot of the javascript/JQuery work invisible to the main transformations. But I find that really if isn&#8217;t great for debugging so I write the JS in another context and then import it back in to the <span class="caps">XSL </span>file.<br />
<h2>Option Two: <span class="caps">HTML </span>+ JQuery ++XML</h2>
Having looked at the <span class="caps">XSLT </span>work, I was in the land of JQuery and was finding it hard to get good, flowing code from the <span class="caps">HTML</span>/JS perspective. So while what I want to see needs to be parsed declaratively, the way to display and have interactions with it needs to be procedural code.

<p>Note: I had to patch the flexigrid component to allow transforming data from an <span class="caps">XML </span>to <span class="caps">JSON </span>source. It assumes that the resource gotten is the object presented.</p>


<ul>
<li>The <span class="caps">HTML</span>/JS using an html container was quicker and cleaner to write. I was easier to use code samples to then customise and extend.</li>
<li>The browser&#8217;s debugging tools such as Firebug played a little more nicely in terms of error handling</li>
<li>Honestly, this approach took not more than a third of the time</li>
<li>JQuery gives me iterators and finders that makes my code not look dissimilar to the declarative <span class="caps">XSLT </span>(I would also be able to use XPath if I really wanted)</li>
<li>To keep it clean I will tend to use expected modularisation in Javascript (objects/functions)</li>
<li>I&#8217;m not convinced that the end result is necessarily any cleaner though</li>
<li>I will be able to put unit tests around it though</li>
<li>the <span class="caps">HTML </span>file is itself a resource<br />
<h2>Simiarilities</h2></li>
<li>I only need to load the xml once</li>
<li>both use the same libraries</li>
<li>both need to be improved to do a <span class="caps">DTD </span>(xsd) check?</li>
<li>the <span class="caps">REST </span>approach requires that the client transforms the <span class="caps">XML </span>to a format that can be bound to the control<br />
<h2>Where to?</h2></li>
<li>I probably stick with the <span class="caps">HTML </span>approach</li>
<li>I&#8217;d keep extending the JQuery plugin approach which allows for nice configuration of views</li>
<li>I can use either the each iterators with find in JS or use XPath to work out what data I want to (re)present</li>
<li>I would probably add another layer of abstraction between the model object and the data source &#8211; at the moment what required from the data source and format of the binding object are combined. A factory would easily create that separation &#8211; but was too much for this example</li>
<li>Alternatively, I would extend the column model so that you can use XPath configuration of data rather than need the pre processing callback in the first instance</li>
<li>go and look at options 3 and 4 above at some stage (3 is likely to end up as the alternative above)<br />
<h3>Appendix A: Reference Formats of <span class="caps">JSON </span>data format for server</h3><br />
<code>{
page: 1,
total: 239,
rows: [
{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']},
}</code></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.goneopen.com/2008/10/jquery-vs-xslt-as-rest-client-for-xml-resource-in-the-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

