|
1 | 1 | const t = require('@babel/types'); |
| 2 | +const { mapperFor } = require('../resources/buildConfigDefinitions'); |
2 | 3 |
|
3 | 4 | describe('buildConfigDefinitions', () => { |
4 | 5 | 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 | | - |
40 | 6 | it('should return objectParser for ObjectTypeAnnotation', () => { |
41 | 7 | const mockElement = { |
42 | 8 | type: 'ObjectTypeAnnotation', |
|
0 commit comments