Skip to content

Commit 58aa81e

Browse files
committed
add tests
1 parent b1c8cf0 commit 58aa81e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/cubejs-schema-compiler/test/unit/transpilers.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import { parse } from '@babel/parser';
2+
import babelGenerator from '@babel/generator';
3+
import babelTraverse from '@babel/traverse';
4+
15
import { prepareCompiler } from './PrepareCompiler';
6+
import { ImportExportTranspiler } from '../../src/compiler/transpilers';
7+
import { ErrorReporter } from '../../src/compiler/ErrorReporter';
28

39
describe('Transpilers', () => {
410
it('CubeCheckDuplicatePropTranspiler', async () => {
@@ -43,4 +49,36 @@ describe('Transpilers', () => {
4349

4450
await compiler.compile();
4551
});
52+
53+
it('ImportExportTranspiler', async () => {
54+
const ieTranspiler = new ImportExportTranspiler();
55+
const errorsReport = new ErrorReporter();
56+
const code = `
57+
export const helperFunction = () => 'hello'
58+
export { helperFunction as alias }
59+
export default helperFunction
60+
`;
61+
const ast = parse(
62+
code,
63+
{
64+
sourceFilename: 'code.js',
65+
sourceType: 'module',
66+
plugins: ['objectRestSpread'],
67+
},
68+
);
69+
70+
babelTraverse(ast, ieTranspiler.traverseObject(errorsReport));
71+
const content = babelGenerator(ast, {}, code).code;
72+
73+
expect(content).toEqual(`const helperFunction = () => 'hello';
74+
addExport({
75+
helperFunction: helperFunction
76+
})
77+
addExport({
78+
alias: helperFunction
79+
});
80+
setExport(helperFunction);`);
81+
82+
errorsReport.throwIfAny(); // should not throw
83+
});
4684
});

0 commit comments

Comments
 (0)