Skip to content

Commit

Permalink
Fix error when exclude/include are undefined (#32)
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
jogold authored Jul 7, 2017
1 parent 1c88b8d commit 3c8b479
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]
Expand Down
28 changes: 19 additions & 9 deletions test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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', () => {
Expand Down

0 comments on commit 3c8b479

Please sign in to comment.