Skip to content

Commit

Permalink
Merge pull request #23 from RobLoach/tests
Browse files Browse the repository at this point in the history
Add automated tests
  • Loading branch information
balupton committed Jan 1, 2014
2 parents cb54c92 + 240248c commit a8b6853
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 35 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@
},
"devDependencies": {
"docco": "~0.6.2",
"coffee-script": "~1.6.2"
"coffee-script": "~1.6.2",
"chai": "~1.8.1",
"joe": "~1.3.2",
"joe-reporter-console": "~1.2.1",
"safeps": "~2.2.10"
},
"main": "./out/lib/projectz.js",
"scripts": {
"test": "bin/projectz compile -p test/src",
"test": "node ./out/test/compile-test.js",
"start": "node ./node_modules/coffee-script/bin/cake watch"
},
"bin": {
Expand All @@ -67,4 +71,4 @@
"flattr": "344188/balupton-on-Flattr",
"paypal": "QB8GQPZAH84N6"
}
}
}
44 changes: 44 additions & 0 deletions src/test/compile-test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# CompileTest
safeps = require('safeps')
joe = require('joe')
pathUtil = require('path')
fs = require('fs')
{expect} = require('chai')

# -------------------------------------
# Configuration

# Paths
projectzPath = pathUtil.join(__dirname, '..', '..')
testPath = pathUtil.join(projectzPath, 'test')
srcPath = pathUtil.join(projectzPath, 'test', 'src')
expectPath = pathUtil.join(projectzPath, 'test', 'out-expected')
cliPath = pathUtil.join(projectzPath, 'bin', 'projectz')

# -------------------------------------
# Tests

joe.suite 'projectz-compile', (suite,test) ->
test 'compile', (done) ->

# Compile with Projectz using -p to switch to the source path.
command = [cliPath, 'compile', '-p', srcPath]
safeps.spawnCommand 'node', command, {output:true}, (err) ->
return done(err) if err

# Check that the compiled files match correctly.
suite 'files', (suite,test) ->
for file in fs.readdirSync(expectPath)
# Ensure the file context is kept across the asyncronous calls.
((file) ->
test file, (done) ->
# Load the expected source.
fs.readFile pathUtil.join(expectPath, file), 'utf8', (err, expected) ->
return done(err) if err
# Load the actual source.
fs.readFile pathUtil.join(srcPath, file), 'utf8', (err, actual) ->
return done(err) if err
expect(actual).to.equal(expected)
done()
)(file);
done()
103 changes: 72 additions & 31 deletions test/out-expected/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
<!-- TITLE/ -->
# Ambi
<!-- /TITLE -->
<!-- TITLE -->

<!-- BADGES/ -->
[![Build Status](https://secure.travis-ci.org/bevry/ambi.png?branch=master)](http://travis-ci.org/bevry/ambi "Check this project's build status on TravisCI")
[![NPM version](https://badge.fury.io/js/ambi.png)](https://npmjs.org/package/ambi "View this project on NPM")
[![Gittip donate button](http://badgr.co/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://www.paypalobjects.com/en_AU/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
<!-- /BADGES -->

<!-- DESCRIPTION/ -->
Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).
<!-- /DESCRIPTION -->
[![Build Status](http://img.shields.io/travis-ci/bevry/ambi.png?branch=master)](http://travis-ci.org/bevry/ambi "Check this project's build status on TravisCI")
[![Dependency Status](https://david-dm.org/bevry/ambi.png)](https://david-dm.org/bevry/ambi)
[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")

<!-- INSTALL/ -->
## Install
<!-- /BADGES -->

### [Node](http://nodejs.org/), [Browserify](http://browserify.org/)
- Use: `require('ambi')`
- Install: `npm install --save ambi`

### [Ender](http://ender.jit.su/)
- Use: `require('ambi')`
- Install: `ender add ambi`
<!-- DESCRIPTION/ -->

### [Component](http://github.com/component/component)
- Use: `require('ambi')`
- Install: `component install bevry/ambi`
Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).

### [Bower](http://bower.io/)
- Use: `require('ambi')`
- Install: `bower install ambi`
<!-- /INSTALL -->
<!-- /DESCRIPTION -->


## Usage
Expand Down Expand Up @@ -83,14 +66,72 @@ console.log(result); // setTimeout - just like normal
- Ambi can also introspect a different method than the one it fires, by passing `[methodToFire, methodToIntrospect]` as the `method` argument


<!-- INSTALL/ -->

## Install

### [Node](http://nodejs.org/)
- Use: `require('ambi')`
- Install: `npm install --save ambi`

<!-- /INSTALL -->


<!-- HISTORY/ -->

## History
[You can discover the version history inside the `History.md` file.](https://github.com/bevry/ambi/blob/master/History.md#files) file
[Discover the change history by heading on over to the `HISTORY.md` file.](https://github.com/bevry/ambi/blob/master/HISTORY.md#files)

<!-- /HISTORY -->


<!-- CONTRIBUTE/ -->

## Contribute

[Discover how you can contribute by heading on over to the `CONTRIBUTING.md` file.](https://github.com/bevry/ambi/blob/master/CONTRIBUTING.md#files)

<!-- /CONTRIBUTE -->


<!-- BACKERS/ -->

## Backers

### Maintainers

These amazing people are maintaining this project:

- Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)

### Sponsors

No sponsors yet! Will you be the first?

[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")

### Contributors

These amazing people have contributed code to this project:

- [Benjamin Lupton](https://github.com/balupton) <b@lupton.cc>[view contributions](https://github.com/bevry/ambi/commits?author=balupton)
- [sfrdmn](https://github.com/sfrdmn)[view contributions](https://github.com/bevry/ambi/commits?author=sfrdmn)

[Become a contributor!](https://github.com/bevry/ambi/blob/master/CONTRIBUTING.md#files)

<!-- /BACKERS -->


<!-- LICENSE/ -->

## License
Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
<br/>Copyright © 2013+ [Bevry Pty Ltd](http://bevry.me)
<br/>Copyright © 2011-2012 [Benjamin Arthur Lupton](http://balupton.com)

Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT license](http://creativecommons.org/licenses/MIT/)

Copyright &copy; Bevry Pty Ltd <us@bevry.me> (http://bevry.me)

<!-- /LICENSE -->


53 changes: 53 additions & 0 deletions test/out-expected/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "ambi",
"version": "2.1.4",
"description": "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).",
"homepage": "https://github.com/bevry/ambi",
"keywords": [
"sync",
"async",
"fire",
"exec",
"execute",
"ambidextrous",
"flow"
],
"author": "Bevry Pty Ltd <us@bevry.me> (http://bevry.me)",
"maintainers": [
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)"
],
"contributors": [
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)",
"sfrdmn (https://github.com/sfrdmn)"
],
"bugs": {
"url": "https://github.com/bevry/ambi/issues"
},
"repository": {
"type": "git",
"url": "http://github.com/bevry/ambi.git"
},
"license": {
"type": "MIT"
},
"engines": {
"node": ">=0.8"
},
"dependencies": {
"typechecker": "~2.0.6"
},
"devDependencies": {
"coffee-script": "~1.6.2",
"joe": "~1.3.0",
"joe-reporter-console": "~1.2.0",
"chai": "~1.7.2"
},
"directories": {
"lib": "./out/lib"
},
"scripts": {
"preinstall": "node ./cyclic.js",
"test": "node ./out/test/everything-test.js"
},
"main": "./out/lib/ambi.js"
}
1 change: 0 additions & 1 deletion test/src/.travis.yml

This file was deleted.

0 comments on commit a8b6853

Please sign in to comment.