2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
import {ddescribe, describe, xdescribe, it, iit, xit, expect, beforeEach, afterEach, inject, beforeEachProviders,} from '@angular/core/testing/testing_internal';
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {IS_DART} from '../src/facade/lang';
|
|
|
|
import {Injector} from '@angular/core';
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {ComponentFactory} from '@angular/core/src/linker/component_factory';
|
2016-01-06 17:13:44 -05:00
|
|
|
import * as typed from './offline_compiler_codegen_typed';
|
|
|
|
import * as untyped from './offline_compiler_codegen_untyped';
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
import {SharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';
|
2016-01-06 17:13:44 -05:00
|
|
|
|
|
|
|
import {CompA} from './offline_compiler_util';
|
|
|
|
|
|
|
|
export function main() {
|
2016-04-13 20:05:17 -04:00
|
|
|
var typedComponentFactory = typed.CompANgFactory;
|
|
|
|
var untypedComponentFactory = untyped.CompANgFactory;
|
2016-04-30 13:52:04 -04:00
|
|
|
var fixtures: TestFixture[] = [];
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
if (IS_DART || !getDOM().supportsDOMEvents()) {
|
2016-01-06 17:13:44 -05:00
|
|
|
// Our generator only works on node.js and Dart...
|
2016-04-30 13:52:04 -04:00
|
|
|
fixtures.push(new TestFixture(typedComponentFactory, 'typed'));
|
2016-01-06 17:13:44 -05:00
|
|
|
}
|
|
|
|
if (!IS_DART) {
|
|
|
|
// Our generator only works on node.js and Dart...
|
2016-04-28 20:50:03 -04:00
|
|
|
if (!getDOM().supportsDOMEvents()) {
|
2016-04-30 13:52:04 -04:00
|
|
|
fixtures.push(new TestFixture(untypedComponentFactory, 'untyped'));
|
2016-01-06 17:13:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
describe('OfflineCompiler', () => {
|
|
|
|
var injector: Injector;
|
|
|
|
var sharedStylesHost: SharedStylesHost;
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
beforeEach(inject(
|
|
|
|
[Injector, SharedStylesHost],
|
|
|
|
(_injector: Injector, _sharedStylesHost: SharedStylesHost) => {
|
|
|
|
injector = _injector;
|
|
|
|
sharedStylesHost = _sharedStylesHost;
|
|
|
|
}));
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-04-30 13:52:04 -04:00
|
|
|
fixtures.forEach((fixture) => {
|
|
|
|
describe(`${fixture.name}`, () => {
|
2016-01-06 17:13:44 -05:00
|
|
|
it('should compile components', () => {
|
2016-04-30 13:52:04 -04:00
|
|
|
var hostEl = fixture.compFactory.create(injector);
|
|
|
|
expect(hostEl.instance).toBeAnInstanceOf(CompA);
|
2016-01-06 17:13:44 -05:00
|
|
|
var styles = sharedStylesHost.getAllStyles();
|
|
|
|
expect(styles[0]).toContain('.redStyle[_ngcontent');
|
|
|
|
expect(styles[1]).toContain('.greenStyle[_ngcontent');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-04-30 13:52:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestFixture {
|
|
|
|
constructor(public compFactory: ComponentFactory<CompA>, public name: string) {}
|
2016-04-28 20:50:03 -04:00
|
|
|
}
|