Download - Quality assurance for javascript
Outline
Server Side Javascript Environment Preparation Static Check & Unit Test
NodeJs
Javascript is a frontend programming language, but things have changed...
Server Side Javascript
Server Side Javascript needs: Package management and Modular Task Management Tools, like maven in java; Quality Assurance Utilities
− Static Check − Unit Test
Writing Modular JavaScript
Modularity AMD: Asynchronous Module Definition
define(
module_id /*optional*/,
[dependencies] /*optional*/,
definition function /*function for instantiating the module or object*/
);
Package Management
NPM is short for Node Packaged Modules.
Grunt.js
Why a build tool is needed for CI ? Why Grunt.js
Basic Grunt.js tasks
init Generate project scaffolding from a predefined template
lint validate files with jshint
min minify files with UglifyJS
server Start a static node web server
test Run unit tests with nodeunit. (Jasmine support)
Outline
Server Side Javascript Environment Preparation Static Check & Unit Test
Install NodeJs
Install via source code Download from
nodejs.org/download ./configure & make & make install
Install via package manager su -c 'yum install npm'
Dependencies V8 Javascript Engine
Install Related Modules
npm install -g grunt-cli npm install -g grunt-contrib-jshint npm install -g grunt-mocha-
phantomjs
Grunt Configuration
Outline
Server Side Javascript Environment Preparation Static Check & Unit Test
Static Check via JSHint
mpt comes from
Gruntfile.js
Unit Test via
Mocha
Feature Rich Runs on node + the browser Simplifies async testing Growl notifications Choose your own assertion library
Chai
BDD / TDD For node + the browser Three assertion styles
should - foo.should.be.a('string') expect - expect(foo).to.be.a('string') assert - assert.typeOf(foo,'string')
Sample: TableRender.html
Sample: TableRender.js (1)
Sample: TableRender.js (2)
Unit Tests via Grunt
Reference
http://addyosmani.com/writing-modular-js/ http://www.slideshare.net/FabienDoiron/grunt-js http://www.slideshare.net/jamescryer/javascript-
testing-mocha-chai http://visionmedia.github.io/mocha/ http://chaijs.com/