From 17e3c652454be3dd8dd265745ec41fd5329067be Mon Sep 17 00:00:00 2001 From: George Taveras Date: Sun, 20 Nov 2016 21:48:33 -0500 Subject: [PATCH] Attempt to be cross platform friendly Also improved style in tests --- test/units/package-test.js | 49 +++++++++++++++++-------------------- test/units/resolver-test.js | 2 +- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/units/package-test.js b/test/units/package-test.js index eb4f9c5..3e3159c 100644 --- a/test/units/package-test.js +++ b/test/units/package-test.js @@ -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')); @@ -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')); @@ -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')); }); }); diff --git a/test/units/resolver-test.js b/test/units/resolver-test.js index 24eb5df..7031168 100644 --- a/test/units/resolver-test.js +++ b/test/units/resolver-test.js @@ -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); });