Skip to content

Commit

Permalink
Attempt to be cross platform friendly
Browse files Browse the repository at this point in the history
Also improved style in tests
  • Loading branch information
GeorgeTaveras1231 committed Nov 21, 2016
1 parent 4b4fdcf commit 17e3c65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
49 changes: 22 additions & 27 deletions test/units/package-test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
var Package = require('../../lib/resolver/package');
var sinon = require('sinon');
var assert = require('assert');
var path = require('path');

describe('Package', function () {
var subject;
var Package = require('../../lib/resolver/package');

describe('Package', function () {
describe('#json', function () {
it('returns the package.json file for the package', function () {
var requireStub = sinon.stub();
var subject = new Package('test-package', requireStub);
var result;

requireStub.withArgs('test-package/package.json')
.returns('the package.json object');

subject = new Package('test-package', requireStub);

result = subject.json();

assert(requireStub.calledWith('test-package/package.json'));
Expand All @@ -24,15 +23,13 @@ describe('Package', function () {

describe('#resolve', function () {
it('resolves a path that is local to the package', function () {
var requireMock = {
resolve: sinon.stub()
};
var requireMock = { resolve: sinon.stub() };
var subject = new Package('test-package', requireMock);
var result;

requireMock.resolve.withArgs('test-package/given-path').returns('npm resolved path');

var subject = new Package('test-package', requireMock);

var result = subject.resolve('given-path');
result = subject.resolve('given-path');

assert.equal(result, 'npm resolved path');
assert(requireMock.resolve.calledWith('test-package/given-path'));
Expand All @@ -41,33 +38,31 @@ describe('Package', function () {

describe('#safeResolve', function () {
it('resolves a path that is local to the package (but does not error out if it cannot find it)', function () {
var requireMock = {
resolve: sinon.stub()
};

requireMock.resolve.withArgs('test-package/package.json').returns('/a/b/c/test-package/package.json');

var requireMock = { resolve: sinon.stub() };
var subject = new Package('test-package', requireMock);
var result;

requireMock.resolve.withArgs('test-package/package.json')
.returns(path.join('a', 'b', 'c', 'test-package', 'package.json'));

var result = subject.safeResolve('given-path');
result = subject.safeResolve('given-path');

assert.equal(result, '/a/b/c/test-package/given-path');
assert.equal(result, path.join('a', 'b', 'c', 'test-package', 'given-path'));
});
});

describe('#dir', function () {
it('returns the directory of the package', function () {
var requireMock = {
resolve: sinon.stub()
};

requireMock.resolve.withArgs('test-package/package.json').returns('/a/b/c/test-package/package.json');

var requireMock = { resolve: sinon.stub() };
var subject = new Package('test-package', requireMock);
var result;

requireMock.resolve.withArgs('test-package/package.json')
.returns(path.join('a', 'b', 'c', 'test-package', 'package.json'));

var result = subject.dir();
result = subject.dir();

assert.equal(result, '/a/b/c/test-package');
assert.equal(result, path.join('a', 'b', 'c', 'test-package'));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/units/resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('resolver', function () {
it('resolves the correct path', function () {
var resolve = resolver(fakeRequire);

var result = resolve('package-name/specific-file-in-package');
var result = resolve(path.join('package-name', 'specific-file-in-package'));

assert.equal(path.join('a', 'b', 'c', 'package-name', 'specific-file-in-package'), result);
});
Expand Down

0 comments on commit 17e3c65

Please # to comment.