Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
read version from package.json + test
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Mar 9, 2012
1 parent b671bbf commit bcbdecc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/ender.js
Expand Up @@ -8,9 +8,9 @@ process.title = "Ender"

var colors = require('colors')
, fs = require('fs')
, path = require('path')
, async = require('async')
, context = null
, version = "v0.8.5"

// ENDER OBJECTS
// =============
Expand Down Expand Up @@ -195,8 +195,13 @@ var colors = require('colors')
}
}

, version: function () {
console.log('Active Version: ' + version)
, version: function (args, options, callback) {
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function (err, data) {
if (err)
throw err
console.log('Active Version: ' + JSON.parse(data).version)
callback()
})
}

, compile: function (files, options) {
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Expand Up @@ -12,6 +12,31 @@ sink.timeout = false;
// only output sink log statements
spec.setLogKey('$__sink::');

sink('ENDER - VERSION', function (test, ok, before, after, assert) {

after(function () {
O_O.removeAll(); //clear all spies after each test
});

test('exec: version', function (complete) {
fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8', function (err, contents) {
ok(!err, 'read package.json')
var expectedVersion = contents.match(/"version"\s*:\s*"([^"]+)"/)[1]
, actualVersionString
O_O(console, 'log').andCallFake(function (str) {
if (/^Active /.test(str)) {
actualVersionString = str.replace(/[^\w\:\s\.]/, '')
O_O.removeAll(); //clear all spies after each test
}
})
ender.exec('ender version', function () {
assert.equal('Active Version: ' + expectedVersion, actualVersionString , 'printed correct version string')
complete()
})
})
})
})

sink('ENDER - DEPENDENCIES', function (test, ok, before, after) {

after(function () {
Expand Down

0 comments on commit bcbdecc

Please sign in to comment.