From 3c8b479462f493931c59005b679f5d0dc567fe22 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 7 Jul 2017 17:28:42 +0200 Subject: [PATCH] Fix error when exclude/include are undefined (#32) Fixes #30 --- src/lib/service.js | 4 ++-- test/service.test.js | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/lib/service.js b/src/lib/service.js index 0eeb902..b9acb6f 100644 --- a/src/lib/service.js +++ b/src/lib/service.js @@ -2,7 +2,7 @@ const path = require('path'); const R = require('ramda'); const makeRelative = R.replace(/[^!]+$/, R.concat('../')); -const makeAllRelative = p => R.when(R.has(p), R.over(R.lensProp(p), R.map(makeRelative))); +const makeAllRelative = p => R.when(R.prop(p), R.over(R.lensProp(p), R.map(makeRelative))); const makePackageRelative = R.compose(makeAllRelative('include'), makeAllRelative('exclude')); const setPackage = R.pipe( @@ -16,7 +16,7 @@ const fnPath = R.compose(R.replace(/\.[^.]+$/, '.js'), R.prop('handler')); const setFnsPackage = R.map( R.pipe( - R.when(R.has('package'), R.over(R.lensProp('package'), makePackageRelative)), + R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)), R.converge( R.over(R.lensPath(['package', 'include'])), [R.compose(R.append, fnPath), R.identity] diff --git a/test/service.test.js b/test/service.test.js index aadf113..ee942f1 100644 --- a/test/service.test.js +++ b/test/service.test.js @@ -2,21 +2,31 @@ const path = require('path'); const service = require('../src/lib/service'); const fns = require('./fns.js'); +const expectedPackage = { + individually: true, + exclude: ['**'], +}; + test('service package when package is undefined', () => { - const expectedPackage = { - individually: true, - exclude: ['**'], - }; expect(service.setPackage(undefined)).toEqual(expectedPackage); }); +test('service package when package is an empty object', () => { + expect(service.setPackage({})).toEqual(expectedPackage); +}); + test('service package with existing package and no include/exclude', () => { const existingPackage = { individually: false, }; - const expectedPackage = { - individually: true, - exclude: ['**'], + expect(service.setPackage(existingPackage)).toEqual(expectedPackage); +}); + +test('service package with existing package and undefined include/exclude', () => { + const existingPackage = { + individually: false, + include: undefined, + exclude: undefined, }; expect(service.setPackage(existingPackage)).toEqual(expectedPackage); }); @@ -27,12 +37,12 @@ test('service package with existing package and include/exclude', () => { include: ['node_modules/**'], exclude: ['*.txt'], }; - const expectedPackage = { + const expectedPackageIncExc = { individually: true, include: ['../node_modules/**'], exclude: ['../*.txt', '**'], }; - expect(service.setPackage(existingPackage)).toEqual(expectedPackage); + expect(service.setPackage(existingPackage)).toEqual(expectedPackageIncExc); }); test('fnPath', () => {