Skip to content

Commit

Permalink
node 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Llamas committed May 1, 2015
1 parent 477e3ca commit 257459f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
after_script: "npm install coveralls && npm run-script test-lcov | ./node_modules/.bin/coveralls"
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.1.2 (01 May 2015)
Minimum Node.js v0.12.
Minor bugfixes.

v0.1.2 (06 Feb 2015)
Updated package.json.

Expand Down
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ var callerDirname = function () {
return path.dirname(callSites()[2].getFileName());
};

var isAbsolute = function (pathname) {
return path.resolve(pathname) === path.normalize(pathname);
};

module.exports = function (options) {
options = options || {};
var rootDir = options.rootDir || callerDirname();

if (!isAbsolute(rootDir)) {
var rootDir = options.rootDir
? path.normalize(options.rootDir)
: callerDirname();

if (!path.isAbsolute(rootDir)) {
throw new Error('The root directory must be an absolute path');
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "groot",
"version": "0.1.2",
"version": "1.0.0",
"description": "Module loader with global variables",
"keywords": [
"require",
Expand All @@ -13,7 +13,7 @@
"author": "Gabriel Llamas <gagle@outlook.com>",
"repository": "git://github.com/gagle/node-groot.git",
"engines": {
"node": ">=0.10"
"node": ">=0.12"
},
"devDependencies": {
"code": "^1.3.0",
Expand Down
30 changes: 9 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
'use strict';

var path = require('path');
var code = require('code');
var lab = module.exports.lab = require('lab').script();

var expect = code.expect;
var describe = lab.describe;
var it = lab.it;
var after = lab.after;
var afterEach = lab.afterEach;

var groot = require('../lib');

describe('groot', function () {
after(function (done) {
delete global.__root;
delete global.__require;
done();
});

it('sets global vars', function (done) {
groot({ requireVar: '__require', rootVar: '__root', rootDir: __dirname });

Expand All @@ -26,13 +20,6 @@ describe('groot', function () {

done();
});
});

describe('groot', function () {
afterEach(function (done) {
delete global.__require;
done();
});

it('calls the original require function', function (done) {
groot({ requireVar: '__require' });
Expand All @@ -59,13 +46,6 @@ describe('groot', function () {

done();
});
});

describe('groot', function () {
after(function (done) {
delete global.__base;
done();
});

it('does not do anything if no options are passed', function (done) {
var globalKeys = Object.keys(global).length;
Expand Down Expand Up @@ -93,4 +73,12 @@ describe('groot', function () {

done();
});

it('the root path is normalized', function (done) {
groot({ rootVar: '__root', rootDir: '/a/b/..' });

expect(__root).to.be.equal(path.normalize('/a'));

done();
});
});

0 comments on commit 257459f

Please sign in to comment.