Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Schematics): Distinguish between root and feature effect arrays #718

Merged
merged 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ describe('Effect Schematic', () => {

it('should add an effect to the empty array of registered effects', () => {
const storeModule = '/src/app/store.module.ts';
const options = { ...defaultOptions, module: 'store.module.ts' };
const options = {
...defaultOptions,
root: true,
module: 'store.module.ts',
};
appTree = createAppModuleWithEffects(
appTree,
storeModule,
Expand All @@ -117,9 +121,13 @@ describe('Effect Schematic', () => {
expect(content).toMatch(/EffectsModule\.forRoot\(\[FooEffects\]\)/);
});

it('should add an effect to the existing registered effects', () => {
it('should add an effect to the existing registered root effects', () => {
const storeModule = '/src/app/store.module.ts';
const options = { ...defaultOptions, module: 'store.module.ts' };
const options = {
...defaultOptions,
root: true,
module: 'store.module.ts',
};
appTree = createAppModuleWithEffects(
appTree,
storeModule,
Expand All @@ -134,6 +142,23 @@ describe('Effect Schematic', () => {
);
});

it('should add an effect to the existing registered feature effects', () => {
const storeModule = '/src/app/store.module.ts';
const options = { ...defaultOptions, module: 'store.module.ts' };
appTree = createAppModuleWithEffects(
appTree,
storeModule,
`EffectsModule.forRoot([RootEffects])\n EffectsModule.forFeature([UserEffects])`
);

const tree = schematicRunner.runSchematic('effect', options, appTree);
const content = getFileContent(tree, '/src/app/store.module.ts');

expect(content).toMatch(
/EffectsModule\.forFeature\(\[UserEffects, FooEffects\]\)/
);
});

it('should not add an effect to registered effects defined with a variable', () => {
const storeModule = '/src/app/store.module.ts';
const options = { ...defaultOptions, module: 'store.module.ts' };
Expand Down
8 changes: 6 additions & 2 deletions modules/schematics/src/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ function _addSymbolToNgModuleMetadata(
return [];
}

const effectsModule = nodeArray.find(node =>
node.getText().includes('EffectsModule')
const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
symbolName.includes('EffectsModule.forRoot')) ||
(node.getText().includes('EffectsModule.forFeature') &&
symbolName.includes('EffectsModule.forFeature'))
);

if (effectsModule && symbolName.includes('EffectsModule')) {
Expand Down