Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Using Karma AutoWatch: True in Gulp-Angular Generator

4/20/2016

0 Comments

 
If you've been reading some of my other AngularJS posts you may have noticed that Gulp-Angular is by far my favorite Angular Yeoman generator. Being the huge TDD and unit testing fan that I am, I wanted to have my test runner automatically rerun the tests when I change a files (similar to browserSync in gulp serve, but for unit tests). This wasn't totally straightforward, and I'll explain how I got it to work below.

Hint 1: You Don't Use Karma.conf.js

When you go to the karma documentation they will tell you that in order to turn on "autoWatch" (the feature I'm looking for here) you must go into the karma.conf.js file and change this property to true:
autoWatch: false,
However, for this particular generator it doesn't work! Even when this property is set to true the tests only run once! 

Hint 2: You Use Gulp to Do It

The trick is that the handy gulp scripts are set up to do this for you. Instead of the usual gulp test you need to tack ":auto" onto the end of it. So back in your command line you'd type: 
gulp test:auto

See! It turns out that it's super easy after all. The gulp script isn't even dependent on whether karma.conf.js's autoWatch property is set to true. Running gulp test:auto will still run in auto-watch mode even if you have it set to false so don't even think about that anymore. If you are wondering about protractor tests, there is absolutely a similar gulp protractor:auto that runs protractor tests in auto watch mode. So there you have it! The moral of the story here is that you should not be fighting against your workflow tools. Instead you should get to know them well, take them out on fancy dates, and if the mood is right they might even let you cop a feel. Wait, what?! 
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021