Skip to content

Commit 3c8b479

Browse files
authored
Fix error when exclude/include are undefined (#32)
Fixes #30
1 parent 1c88b8d commit 3c8b479

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/lib/service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const R = require('ramda');
33

44
const makeRelative = R.replace(/[^!]+$/, R.concat('../'));
5-
const makeAllRelative = p => R.when(R.has(p), R.over(R.lensProp(p), R.map(makeRelative)));
5+
const makeAllRelative = p => R.when(R.prop(p), R.over(R.lensProp(p), R.map(makeRelative)));
66
const makePackageRelative = R.compose(makeAllRelative('include'), makeAllRelative('exclude'));
77

88
const setPackage = R.pipe(
@@ -16,7 +16,7 @@ const fnPath = R.compose(R.replace(/\.[^.]+$/, '.js'), R.prop('handler'));
1616

1717
const setFnsPackage = R.map(
1818
R.pipe(
19-
R.when(R.has('package'), R.over(R.lensProp('package'), makePackageRelative)),
19+
R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)),
2020
R.converge(
2121
R.over(R.lensPath(['package', 'include'])),
2222
[R.compose(R.append, fnPath), R.identity]

test/service.test.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@ const path = require('path');
22
const service = require('../src/lib/service');
33
const fns = require('./fns.js');
44

5+
const expectedPackage = {
6+
individually: true,
7+
exclude: ['**'],
8+
};
9+
510
test('service package when package is undefined', () => {
6-
const expectedPackage = {
7-
individually: true,
8-
exclude: ['**'],
9-
};
1011
expect(service.setPackage(undefined)).toEqual(expectedPackage);
1112
});
1213

14+
test('service package when package is an empty object', () => {
15+
expect(service.setPackage({})).toEqual(expectedPackage);
16+
});
17+
1318
test('service package with existing package and no include/exclude', () => {
1419
const existingPackage = {
1520
individually: false,
1621
};
17-
const expectedPackage = {
18-
individually: true,
19-
exclude: ['**'],
22+
expect(service.setPackage(existingPackage)).toEqual(expectedPackage);
23+
});
24+
25+
test('service package with existing package and undefined include/exclude', () => {
26+
const existingPackage = {
27+
individually: false,
28+
include: undefined,
29+
exclude: undefined,
2030
};
2131
expect(service.setPackage(existingPackage)).toEqual(expectedPackage);
2232
});
@@ -27,12 +37,12 @@ test('service package with existing package and include/exclude', () => {
2737
include: ['node_modules/**'],
2838
exclude: ['*.txt'],
2939
};
30-
const expectedPackage = {
40+
const expectedPackageIncExc = {
3141
individually: true,
3242
include: ['../node_modules/**'],
3343
exclude: ['../*.txt', '**'],
3444
};
35-
expect(service.setPackage(existingPackage)).toEqual(expectedPackage);
45+
expect(service.setPackage(existingPackage)).toEqual(expectedPackageIncExc);
3646
});
3747

3848
test('fnPath', () => {

0 commit comments

Comments
 (0)