Skip to content

Commit

Permalink
test(ivy): test Esm5Renderer.getSwitchableDeclarations (angular#25534)
Browse files Browse the repository at this point in the history
Also incorporates a refactoring of the tests to make them less fragile.

PR Close angular#25534
  • Loading branch information
petebacondarwin committed Sep 3, 2018
1 parent b49ece2 commit 1002b06
Showing 1 changed file with 36 additions and 0 deletions.
Expand Up @@ -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};`
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1002b06

Please sign in to comment.