test(ngcc): add missing `UmdReflectionHost#getExportsOfModule()` tests (#35312)

Support for re-exports in UMD were added in e9fb5fdb8. This commit adds
some tests for re-exports (similar to the ones used for
`CommonJsReflectionHost`).

PR Close #35312
This commit is contained in:
George Kalpakas 2020-02-10 20:49:03 +02:00 committed by Kara Erickson
parent dcb8d6740e
commit 5f57376899
1 changed files with 57 additions and 11 deletions

View File

@ -1919,6 +1919,63 @@ runInEachFileSystem(() => {
]);
});
it('should handle wildcard re-exports of other modules (with emitted helpers)', () => {
loadFakeCore(getFileSystem());
loadTestFiles(EXPORTS_FILES);
const bundle = makeTestBundleProgram(_('/index.js'));
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
const file = getSourceFileOrError(bundle.program, _('/wildcard_reexports.js'));
const exportDeclarations = host.getExportsOfModule(file);
expect(exportDeclarations).not.toBe(null);
expect(Array.from(exportDeclarations !.entries())
.map(entry => [entry[0], entry[1].node !.getText(), entry[1].viaModule]))
.toEqual([
['Directive', `Directive: FnWithArg<(clazz: any) => any>`, _('/b_module')],
['a', `a = 'a'`, _('/b_module')],
['b', `b = a_module.a`, _('/b_module')],
['c', `a = 'a'`, _('/b_module')],
['d', `b = a_module.a`, _('/b_module')],
['e', `e = 'e'`, _('/b_module')],
['DirectiveX', `Directive: FnWithArg<(clazz: any) => any>`, _('/b_module')],
[
'SomeClass',
`SomeClass = (function() {\n function SomeClass() {}\n return SomeClass;\n }())`,
_('/b_module')
],
['xtra1', `xtra1 = 'xtra1'`, _('/xtra_module')],
['xtra2', `xtra2 = 'xtra2'`, _('/xtra_module')],
]);
});
it('should handle wildcard re-exports of other modules (with imported helpers)', () => {
loadFakeCore(getFileSystem());
loadTestFiles(EXPORTS_FILES);
const bundle = makeTestBundleProgram(_('/index.js'));
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
const file =
getSourceFileOrError(bundle.program, _('/wildcard_reexports_imported_helpers.js'));
const exportDeclarations = host.getExportsOfModule(file);
expect(exportDeclarations).not.toBe(null);
expect(Array.from(exportDeclarations !.entries())
.map(entry => [entry[0], entry[1].node !.getText(), entry[1].viaModule]))
.toEqual([
['Directive', `Directive: FnWithArg<(clazz: any) => any>`, _('/b_module')],
['a', `a = 'a'`, _('/b_module')],
['b', `b = a_module.a`, _('/b_module')],
['c', `a = 'a'`, _('/b_module')],
['d', `b = a_module.a`, _('/b_module')],
['e', `e = 'e'`, _('/b_module')],
['DirectiveX', `Directive: FnWithArg<(clazz: any) => any>`, _('/b_module')],
[
'SomeClass',
`SomeClass = (function() {\n function SomeClass() {}\n return SomeClass;\n }())`,
_('/b_module')
],
['xtra1', `xtra1 = 'xtra1'`, _('/xtra_module')],
['xtra2', `xtra2 = 'xtra2'`, _('/xtra_module')],
]);
});
it('should handle inline exports', () => {
loadFakeCore(getFileSystem());
loadTestFiles([INLINE_EXPORT_FILE]);
@ -1932,17 +1989,6 @@ runInEachFileSystem(() => {
expect(decl.node).toBeNull();
expect(decl.expression).toBeDefined();
});
// Currently we do not support UMD versions of `export * from 'x';`
// because it gets compiled to something like:
//
// __export(m) {
// for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
// }
// __export(x);
//
// So far all UMD formatted entry-points are flat so this should not occur.
// If it does later then we should implement parsing.
});
describe('getClassSymbol()', () => {