|
| 1 | +import babylon from '../../babel-parser' |
| 2 | +import resolveImmediatelyExported from '../resolveImmediatelyExported' |
| 3 | + |
| 4 | +describe('resolveImmediatelyExported', () => { |
| 5 | + it('should immediately exported varibles', () => { |
| 6 | + const ast = babylon().parse('export { test } from "test/path";') |
| 7 | + const varNames = resolveImmediatelyExported(ast, ['test']) |
| 8 | + expect(varNames).toMatchObject({ |
| 9 | + test: { filePath: 'test/path', exportName: 'test' }, |
| 10 | + }) |
| 11 | + }) |
| 12 | + |
| 13 | + it('should immediately exported varibles with aliases', () => { |
| 14 | + const ast = babylon().parse('export { test as changedName } from "test/path";') |
| 15 | + const varNames = resolveImmediatelyExported(ast, ['changedName']) |
| 16 | + expect(varNames).toMatchObject({ |
| 17 | + changedName: { filePath: 'test/path', exportName: 'test' }, |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + it('should resolve immediately exported varibles in two steps', () => { |
| 22 | + const ast = babylon().parse( |
| 23 | + [ |
| 24 | + 'import { test as middleName } from "test/path";', |
| 25 | + 'export { middleName as changedName };', |
| 26 | + ].join('\n'), |
| 27 | + ) |
| 28 | + const varNames = resolveImmediatelyExported(ast, ['changedName']) |
| 29 | + expect(varNames).toMatchObject({ |
| 30 | + changedName: { filePath: 'test/path', exportName: 'test' }, |
| 31 | + }) |
| 32 | + }) |
| 33 | + |
| 34 | + it('should return immediately exported varibles in two steps with default import', () => { |
| 35 | + const ast = babylon().parse( |
| 36 | + ['import test from "test/path";', 'export { test as changedName };'].join('\n'), |
| 37 | + ) |
| 38 | + const varNames = resolveImmediatelyExported(ast, ['changedName']) |
| 39 | + expect(varNames).toMatchObject({ |
| 40 | + changedName: { filePath: 'test/path', exportName: 'default' }, |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + it('should return immediately exported varibles in two steps with default export', () => { |
| 45 | + const ast = babylon().parse( |
| 46 | + ['import { test } from "test/path";', 'export default test;'].join('\n'), |
| 47 | + ) |
| 48 | + const varNames = resolveImmediatelyExported(ast, ['default']) |
| 49 | + expect(varNames).toMatchObject({ |
| 50 | + default: { filePath: 'test/path', exportName: 'test' }, |
| 51 | + }) |
| 52 | + }) |
| 53 | +}) |
0 commit comments