test(ivy): test `Esm5Renderer.getSwitchableDeclarations` (#25534)

Also incorporates a refactoring of the tests to make them less fragile.

PR Close #25534
This commit is contained in:
Pete Bacon Darwin 2018-08-23 09:01:29 +01:00 committed by Misko Hevery
parent 26cd9f5433
commit e964319fe9
1 changed files with 36 additions and 0 deletions

View File

@ -58,6 +58,18 @@ var C = (function() {
return C;
}());
var compileNgModuleFactory = compileNgModuleFactory__PRE_NGCC__;
var badlyFormattedVariable = __PRE_NGCC__badlyFormattedVariable;
function compileNgModuleFactory__PRE_NGCC__(injector, options, moduleType) {
const compilerFactory = injector.get(CompilerFactory);
const compiler = compilerFactory.createCompiler([options]);
return compiler.compileModuleAsync(moduleType);
}
function compileNgModuleFactory__POST_NGCC__(injector, options, moduleType) {
ngDevMode && assertNgModuleType(moduleType);
return Promise.resolve(new R3NgModuleFactory(moduleType));
}
// Some other content
export {A, B, C};`
};
@ -95,6 +107,30 @@ var A = (function() {`);
});
});
describe('rewriteSwitchableDeclarations', () => {
it('should switch marked declaration initializers', () => {
const {renderer, program} = setup(PROGRAM);
const file = program.getSourceFile('some/file.js');
if (file === undefined) {
throw new Error(`Could not find source file`);
}
const output = new MagicString(PROGRAM.contents);
renderer.rewriteSwitchableDeclarations(output, file);
expect(output.toString())
.not.toContain(`var compileNgModuleFactory = compileNgModuleFactory__PRE_NGCC__;`);
expect(output.toString())
.toContain(`var badlyFormattedVariable = __PRE_NGCC__badlyFormattedVariable;`);
expect(output.toString())
.toContain(`var compileNgModuleFactory = compileNgModuleFactory__POST_NGCC__;`);
expect(output.toString())
.toContain(
`function compileNgModuleFactory__PRE_NGCC__(injector, options, moduleType) {`);
expect(output.toString())
.toContain(
`function compileNgModuleFactory__POST_NGCC__(injector, options, moduleType) {`);
});
});
describe('addDefinitions', () => {
it('should insert the definitions directly after the class declaration', () => {
const {analyzer, parser, program, renderer} = setup(PROGRAM);