Skip to content

Commit

Permalink
Fix/missing get single spa extra providers (#210)
Browse files Browse the repository at this point in the history
* Include getSingleSpaExtraProviders in template

* Remove extraneous routing check

* Add test for including getSingleSpaExtraProviders if routing is enabled
  • Loading branch information
filoxo authored Jun 4, 2020
1 parent fd72066 commit 142b7bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/schematics/ng-add/_files/src/main.single-spa.ts.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<% if (!atLeastAngular8) { %>import 'core-js/es7/reflect';<% } %>
<% if (routing) { %>import { enableProdMode, NgZone } from '@angular/core';<% } %>
<% if (!routing) { %>import { enableProdMode, NgZone } from '@angular/core';<% } %>
import { enableProdMode, NgZone } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';<% if (routing) { %>
import { Router } from '@angular/router';<% } if (usingBrowserAnimationsModule) { %>
import { ɵAnimationEngine as AnimationEngine } from '@angular/animations/browser'; <% } %>
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import singleSpaAngular from 'single-spa-angular';
import singleSpaAngular<% if (routing) { %>, { getSingleSpaExtraProviders }<% } %> from 'single-spa-angular';
import { singleSpaPropsSubject } from './single-spa/single-spa-props';

if (environment.production) {
Expand All @@ -16,7 +15,7 @@ if (environment.production) {
const lifecycles = singleSpaAngular({
bootstrapFunction: singleSpaProps => {
singleSpaPropsSubject.next(singleSpaProps);
return platformBrowserDynamic().bootstrapModule(AppModule);
return platformBrowserDynamic(<% if (routing) { %>getSingleSpaExtraProviders()<% } %>).bootstrapModule(AppModule);
},
template: '<<%= prefix %>-root />',<% if (routing) { %>
Router,<% } %>
Expand Down
6 changes: 6 additions & 0 deletions src/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('ng-add', () => {
expect(mainModuleContent.indexOf('@angular/router')).toBeGreaterThan(-1);
});

test('should include getSingleSpaExtraProviders if routing is enabled', () => {
const tree = testRunner.runSchematic<NgAddOptions>('ng-add', { routing: true }, defaultAppTree);
const mainModuleContent = getFileContent(tree, '/projects/ss-angular-cli-app/src/main.single-spa.ts');
expect(mainModuleContent.indexOf('getSingleSpaExtraProviders()')).toBeGreaterThan(-1);
});

test('should modify angular.json', () => {
const tree = testRunner.runSchematic<NgAddOptions>('ng-add', { routing: true, project: 'ss-angular-cli-app' }, defaultAppTree);
const angularJSON = JSON.parse(getFileContent(tree, '/angular.json'));
Expand Down

0 comments on commit 142b7bb

Please sign in to comment.