Skip to content

Commit 8224a93

Browse files
committed
feat: Export mapperFor function for testing purposes
1 parent 69875a2 commit 8224a93

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

resources/buildConfigDefinitions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,6 @@ const res = babel.transformFileSync('./src/Options/index.js', {
383383
});
384384
require('fs').writeFileSync('./src/Options/Definitions.js', res.code + '\n');
385385
require('fs').writeFileSync('./src/Options/docs.js', docs);
386+
387+
// Export mapperFor for testing
388+
module.exports = { mapperFor };

spec/buildConfigDefinitions.spec.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,8 @@
11
const t = require('@babel/types');
2+
const { mapperFor } = require('../resources/buildConfigDefinitions');
23

34
describe('buildConfigDefinitions', () => {
45
describe('mapperFor', () => {
5-
// Recreate the mapperFor function for testing
6-
function mapperFor(elt, t) {
7-
const p = t.identifier('parsers');
8-
const wrap = identifier => t.memberExpression(p, identifier);
9-
10-
if (t.isNumberTypeAnnotation(elt)) {
11-
return t.callExpression(wrap(t.identifier('numberParser')), [t.stringLiteral(elt.name)]);
12-
} else if (t.isArrayTypeAnnotation(elt)) {
13-
return wrap(t.identifier('arrayParser'));
14-
} else if (t.isAnyTypeAnnotation(elt)) {
15-
return wrap(t.identifier('objectParser'));
16-
} else if (t.isBooleanTypeAnnotation(elt)) {
17-
return wrap(t.identifier('booleanParser'));
18-
} else if (t.isObjectTypeAnnotation(elt)) {
19-
return wrap(t.identifier('objectParser'));
20-
} else if (t.isGenericTypeAnnotation(elt)) {
21-
const type = elt.typeAnnotation.id.name;
22-
if (type == 'Adapter') {
23-
return wrap(t.identifier('moduleOrObjectParser'));
24-
}
25-
if (type == 'NumberOrBoolean') {
26-
return wrap(t.identifier('numberOrBooleanParser'));
27-
}
28-
if (type == 'NumberOrString') {
29-
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [
30-
t.stringLiteral(elt.name),
31-
]);
32-
}
33-
if (type === 'StringOrStringArray') {
34-
return wrap(t.identifier('arrayParser'));
35-
}
36-
return wrap(t.identifier('objectParser'));
37-
}
38-
}
39-
406
it('should return objectParser for ObjectTypeAnnotation', () => {
417
const mockElement = {
428
type: 'ObjectTypeAnnotation',

0 commit comments

Comments
 (0)