# ----------------------------------------------------------------- | |
# .gitignore for WordPress @salcode | |
# ver 20180808 | |
# | |
# From the root of your project run | |
# curl -O https://gist.githubusercontent.com/salcode/b515f520d3f8207ecd04/raw/.gitignore | |
# to download this file | |
# | |
# By default all files are ignored. You'll need to whitelist | |
# any mu-plugins, plugins, or themes you want to include in the repo. |
If you've done much reading about angularjs you've no doubt come across mention of karma, a test runner recommended especially for use with angularjs applications. The [angular-seed][1] project is a great way to get started with the basics of angular testing using karma, but for projects of any significant size you will soon hit the cieling in terms of organizational complexity. What I want to share in this article is the approach I have taken using [Grunt][2] and the [grunt-karma][3] plugin to sustainably manage my projects' client side unit tests and run them via [TravisCI][4]. I plan to write another entry about how to approach the actual minutia of unit testing angular code in the near future.
Karma is really nothing more than a set of centralized configuration that builds a test runner for you. The advantage being that it allows you to easily execute tests in a headless browser, and output to the command line. As someone who has actually set all of that up from scratc
{ | |
"name": "my-app", | |
"version": "1.0.0", | |
"description": "My test app", | |
"main": "src/js/index.js", | |
"scripts": { | |
"jshint:dist": "jshint src/js/*.js", | |
"jshint": "npm run jshint:dist", | |
"jscs": "jscs src/*.js", | |
"browserify": "browserify -s Validating -o ./dist/js/build.js ./lib/index.js", |
//GistID:1c45ca694ad333baeddd | |
'use strict'; | |
angular.module('stateMock', []); | |
angular.module('stateMock').service("$state", function($q) { | |
this.expectedTransitions = []; | |
this.current = {}; | |
this.transitionTo = function(stateName) { | |
if (this.expectedTransitions.length > 0) { | |
var expectedState = this.expectedTransitions.shift(); |
/* The code below takes a constructor and exposes its private functions | |
Useful for unit testing (not general use). An example usage is below it. | |
Access to the private functions available through the _privMems property. */ | |
/* Original credit goes to Rob Gravelle | |
http://www.htmlgoodies.com/beyond/javascript/accessing-private-functions-in-javascript.html */ | |
var Reflection = {}; | |
Reflection.createExposedInstance = function(objectConstructor, args) | |
{ |
angular.module('stateMock',[]); | |
angular.module('stateMock').service("$state", function($q){ | |
this.expectedTransitions = []; | |
this.current = {}; | |
this.transitionTo = function(stateName){ | |
if(this.expectedTransitions.length > 0){ | |
var expectedState = this.expectedTransitions.shift(); | |
if(expectedState !== stateName){ | |
throw Error("Expected transition to state: " + expectedState + " but transitioned to " + stateName ); | |
} |
/** | |
* Simple authentication and authorization example with passport, node_acl, | |
* MongoDB and expressjs | |
* | |
* The example shown here uses local userdata and sessions to remember a | |
* logged in user. Roles are persistent all the way and applied to user | |
* after logging in. | |
* | |
* Usage: | |
* 1. Start this as server |
/** | |
* Simple node_acl example with mongoDB and expressjs | |
* | |
* Usage: | |
* 1. Start this as server | |
* 2. Play with the resoures | |
* | |
* Show all permissions (as JSON) | |
* http://localhost:3500/info | |
* |
(aka "errback" or "error first callback")
- Function that takes 2 arguments
- first argument is an error
- second argument is the result
- Never pass both
- error should be instanceof Error
- Must never excecute on the same tick of the event loop
- Must be passed as last argument to function