From 543123040c961d00ec46b820b35855be18741683 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 17 Oct 2013 23:55:48 -0700 Subject: [PATCH] Initial commit --- .gitignore | 2 + .jshintrc | 14 +++ .travis.yml | 4 + Gruntfile.js | 157 +++++++++++++++++++++++++++++++ README.md | 31 ++++++ package.json | 34 +++++++ src/cylon.coffee | 12 +++ test/src/specs/cylon.spec.coffee | 36 +++++++ test/support/globals.js | 44 +++++++++ test/support/runner.js | 25 +++++ 10 files changed, 359 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 Gruntfile.js create mode 100644 README.md create mode 100644 package.json create mode 100644 src/cylon.coffee create mode 100644 test/src/specs/cylon.spec.coffee create mode 100644 test/support/globals.js create mode 100644 test/support/runner.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91fa8cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +npm-debug.log diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..8c86fc7 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,14 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "unused": true, + "boss": true, + "eqnull": true, + "node": true +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2cdacaf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - '0.10' + - '0.8' diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..74fc450 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,157 @@ +'use strict'; + +module.exports = function (grunt) { + // load all grunt tasks + require('matchdep').filterDev('grunt-*').forEach(function(contrib) { + grunt.log.ok([contrib + " is loaded"]); + grunt.loadNpmTasks(contrib); + }); + + var config = { + dist: 'dist', + src: 'src', + distTest: 'test/dist', + srcTest: 'test/src' + }; + + // Project configuration. + grunt.initConfig({ + config: config, + clean: { + dist: { + files: [ + { + dot: true, + src: [ + '<%= config.dist %>/*', + '<%= config.distTest %>/*', + '!<%= config.dist %>/.git*' + ] + } + ] + }, + }, + coffee: { + dist: { + files: [{ + expand: true, + cwd: '<%= config.src %>', + src: '{,*/}*.coffee', + dest: '<%= config.dist %>', + ext: '.js' + }] + }, + test: { + files: [{ + expand: true, + cwd: '<%= config.srcTest %>', + src: '{,*/}*.spec.coffee', + dest: '<%= config.distTest %>', + ext: '.spec.js' + }] + } + }, + jshint: { + options: { + jshintrc: '.jshintrc' + }, + gruntfile: { + src: 'Gruntfile.js' + }, + }, + watch: { + gruntfile: { + files: '<%= jshint.gruntfile.src %>', + tasks: ['jshint:gruntfile'] + }, + dist: { + files: '<%= config.src %>/*', + tasks: ['coffee:dist', 'simplemocha:backend'] + }, + test: { + files: '<%= config.srcTest %>/specs/*', + tasks: ['coffee:test', 'simplemocha:backend'] + } + }, + simplemocha: { + options: { + globals: [ + 'sinon', + 'chai', + 'should', + 'expect', + 'assert', + 'AssertionError', + ], + timeout: 3000, + ignoreLeaks: false, + // grep: '*.spec', + ui: 'bdd', + reporter: 'spec' + }, + backend: { + src: [ + // add chai and sinon globally + 'test/support/globals.js', + + // tests + 'test/dist/**/*.spec.js', + ], + }, + }, + }); + + grunt.registerTask('coverageBackend', 'Test backend files as well as code coverage.', function () { + var done = this.async(); + + var path = './test/support/runner.js'; + + var options = { + cmd: 'istanbul', + grunt: false, + args: [ + 'cover', + '--default-excludes', + '-x', 'app/**', + '--report', 'lcov', + '--dir', './coverage/backend', + path + ], + opts: { + // preserve colors for stdout in terminal + stdio: 'inherit', + }, + }; + + function doneFunction(error, result) { + if (result && result.stderr) { + process.stderr.write(result.stderr); + } + + if (result && result.stdout) { + grunt.log.writeln(result.stdout); + } + + // abort tasks in queue if there's an error + done(error); + } + + grunt.util.spawn(options, doneFunction); + }); + + + // Default task. + grunt.registerTask('default', ['coffee', 'jshint']); + + grunt.registerTask('test', [ + 'clean', + 'coffee', + 'simplemocha:backend', + ]); + + grunt.registerTask('coverage', [ + 'clean', + 'coffee', + 'coverageBackend' + ]) +}; diff --git a/README.md b/README.md new file mode 100644 index 0000000..7713d80 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# cylon [![Build Status](https://secure.travis-ci.org/deadprogram/cylon.png?branch=master)](http://travis-ci.org/deadprogram/cylon) + +A small robotics framework based on nactor + +## Getting Started +Install the module with: `npm install cylon` + +```javascript +var cylon = require('cylon'); +cylon.awesome(); // "awesome" +``` + +```coffee-script +cylon = require 'cylon' +cylon.awesome() // "awesome" +``` + +## Documentation +_(Coming soon)_ + +## Examples +_(Coming soon)_ + +## Contributing +In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). + +## Release History +_(Nothing yet)_ + +## License +Copyright (c) 2013 Ron Evans. Licensed under the Apache 2.0 license. diff --git a/package.json b/package.json new file mode 100644 index 0000000..34cc4cc --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "cylon", + "version": "0.0.0", + "main": "lib/cylon.js", + "description": "A small robotics framework based on nactor", + "homepage": "cylonjs.com", + "bugs": "https://github.com/deadprogram/cylon/issues", + "author": { + "name": "Ron Evans", + "email": "", + "url": "http://hybridgroup.com" + }, + "repository": { + "type": "git", + "url": "https://github.com/deadprogram/cylon" + }, + "licenses": [ + { + "type": "Apache 2.0" + } + ], + "devDependencies": { + "matchdep": "~0.1.1", + "grunt-contrib-jshint": "~0.6.0", + "grunt-contrib-watch": "~0.5.0", + "grunt-contrib-coffee": "~0.7.0", + "grunt-simple-mocha": "~0.4.0", + "grunt-contrib-clean": "~0.5.0", + "sinon-chai": "~2.4.0", + "chai": "~1.7.2", + "mocha": "~1.12.1", + "sinon": "~1.7.3" + } +} diff --git a/src/cylon.coffee b/src/cylon.coffee new file mode 100644 index 0000000..52b4193 --- /dev/null +++ b/src/cylon.coffee @@ -0,0 +1,12 @@ +### + * cylon + * cylonjs.com + * + * Copyright (c) 2013 Ron Evans + * Licensed under the Apache 2.0 license. +### + +'use strict'; + +exports.awesome = -> + 'awesome' diff --git a/test/src/specs/cylon.spec.coffee b/test/src/specs/cylon.spec.coffee new file mode 100644 index 0000000..8a002b2 --- /dev/null +++ b/test/src/specs/cylon.spec.coffee @@ -0,0 +1,36 @@ +'use strict'; + +cylon = source("cylon") + +describe "basic tests", -> + it "standard async test", (done) -> + bool = false + bool.should.be.false + + setTimeout -> + bool.should.be.false + bool = true + bool.should.be.true + 150 + + setTimeout -> + bool.should.be.true + done() + 300 + + it "standard sync test", -> + data = [] + obj = id: 5, name: 'test' + data.should.be.empty + data.push obj + data.should.have.length 1 + # soft equal + data[0].should.be.eql obj + # hard equal + data[0].should.be.equal obj + + # Now on to a `real` test + it "cylon should be awesome", -> + cylon.should.have.keys 'awesome' + cylon.awesome.should.be.a 'function' + cylon.awesome().should.be.equal 'awesome' \ No newline at end of file diff --git a/test/support/globals.js b/test/support/globals.js new file mode 100644 index 0000000..20945d4 --- /dev/null +++ b/test/support/globals.js @@ -0,0 +1,44 @@ +'use strict'; + +// allow production modules to expose internal +// functions and properties for testing +process.env.NODE_ENV = 'test'; + +var path = require('path'); +var chai = require('chai'); +var sinonChai = require('sinon-chai'); + +global.chai = chai; +global.should = chai.should(); +global.expect = chai.expect; +global.assert = chai.assert; +global.AssertionError = chai.AssertionError; +global.sinon = require('sinon'); + +// can be used by test modules to require production modules, +// relative to the base path (where the Gruntfile.js also lives) +global.source = function (src) { + console.log('source loading: ' + src) + var resource = path.normalize('../../dist/' + src); + + return require(resource); +}; + +// can be used when you expect a function to throw an error +global.err = function (fn, msg) { + try { + fn(); + throw new chai.AssertionError({ message: 'Expected an error' }); + } catch (err) { + if ('string' === typeof msg) { + chai.expect(err.message).to.equal(msg); + } else { + chai.expect(err.message).to.match(msg); + } + } +}; + +chai.use(sinonChai); + +// if you want a detailed error stack output +// chai.Assertion.includeStack = true; diff --git a/test/support/runner.js b/test/support/runner.js new file mode 100644 index 0000000..0cdcc21 --- /dev/null +++ b/test/support/runner.js @@ -0,0 +1,25 @@ +'use strict'; + +require('./globals'); + +var grunt = require('grunt'); +var Mocha = require('mocha'); + +var mocha = new Mocha({ reporter: 'spec', ui: 'bdd'}); + +function run(cb) { + var files = grunt.file.expand(__dirname + '/../dist/**/*.spec.js'); + console.log(files) + files.forEach(function (file) { + mocha.addFile(file); + }); + + cb(); +} + +run(function (err) { + if (err) { throw err; } + mocha.run(function (failures) { + process.exit(failures); + }); +});