Tag Archives: nodejs

Yeoman grunt-ngmin to grunt-ng-annotate save massive time on your grunt build.

Background

If you have build your skeleton app from yeoman using the angularjs-generator and you created it before August 3rd 2014  you are running ngmin task.

Ngmin has been deprecated and you are told this every time you do an npm install on the project.

Git Issue that resolves this for new generated projects from yeoman

https://github.com/yeoman/generator-angular/issues/801

Why to migrate.

ng-min is deprecated so it is no longer supported.

ng-min is slow.  For a mature medium-sized angularjs app ng-min was taking 50 seconds of the build time.  Running with ng-annotate instead it now takes only 2 seconds to do the same thing.

Now the uglify task takes the most time of the build at 8 seconds against the 2 seconds needed for the ngannotate task.

A savings of 48 seconds a build.  

Built Machine spec:

OSX 10.9.5 with 3.2 GHz with 24 GB of ram.  No modifications have been made to the memory settings for grunt or node.

Continue reading

Saving csv files from a Nodejs project

Update: package available on bower.  bower -S FileSaver.

I am requesting a csv from another service and I wanted to be able to prompt the customer to save the csv for use later.  I managed to get it to save the csv but the filename could not be set so it was not useful.  I found the following library to help out with this.

https://github.com/eligrey/FileSaver.js

 

Grunt Proxy setup for Yeoman 1.2

Purpose

I was wanting to keep my front end project separate from my backend.  This meant that the back end was on a different port than the yeoman server.  This causes cross site scripting issues with the yeoman server.  I figured out the only way around this was via a proxy.

I found this article from Mike Partridge from Jan 2014 which was a good starting point but the yeoman build has changed so this is no longer working.

http://www.hierax.org/2014/01/grunt-proxy-setup-for-yeoman.html

Tools used

  • grunt-cli v0.1.13

  • grunt v0.4.5

  • yeoman 1.2.0

  • grunt-connect-proxy 0.1.10

  • angular-generator 0.9.1

Change to instructions

The only change to the directions in the post from hierax is the following.   I just changed the things that are pushed into middleware.  Live reload no longer has a base [ ] block.

Step 3 should now look like:

livereload: {
 options: {
 open: true,
 middleware: function (connect) {
   // Setup the proxy
   var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

   middlewares.push(connect.static('.tmp'));

   middlewares.push(connect().use(
     '/bower_components',
     connect.static('./bower_components')
   ));
   middlewares.push(connect.static(appConfig.app));

   return middlewares;
 }
 }
 },

Javascript page object pattern based functional tests via the browser with Protractor and Astrolabe

Update: 26/04/14 – added example github project showing an example project with config setup and simple test.

Example project on github: https://github.com/onekilo79/protractor-astrolabe-example

Purpose

Page Object Pattern

When writing browser based tests with selenium the test can become brittle if they are too attached to the xpath of the css selector when the page look and feel changes.  To limit your exposure to changes in the styling of the page you can use the Page Object Pattern.

Library that does Page Object Pattern in Groovy

In Groovy we have the excellent Geb by Luke Daily.

Continue reading

Configure Grunt-protractor-runner to run with a global install of protractor

Purpose

The reason to install protractor globally is that if you use the inline protractor provided with grunt-protractor-runner you have a 10 second penalty of waiting for the server to spawn a java process and then attach itself to it.

With the server already started and waiting for calls it is a lot faster turnaround for your tests to run.

Install protractor

Install protractor globally

If you have installed protractor globally to do your end to end testing via:

You may have to do this as sudo if you

npm -g install protractor

Download the chromedriver by updating webdriver-manager

webdriver-manager update

Continue reading