|
5 | 5 | import { createWorkspace } from '@ngrx/schematics-core/testing';
|
6 | 6 | import { tags } from '@angular-devkit/core';
|
7 | 7 | import * as path from 'path';
|
| 8 | +import { LogEntry } from '@angular-devkit/core/src/logger'; |
8 | 9 |
|
9 | 10 | describe('Effects Migration to 18.0.0-beta', () => {
|
10 | 11 | const collectionPath = path.join(__dirname, '../migration.json');
|
@@ -121,7 +122,95 @@ export class SomeEffects {
|
121 | 122 | });
|
122 | 123 | });
|
123 | 124 |
|
124 |
| - it('should add if they are missing', async () => { |
| 125 | + it('should work with prior import from same namespace', async () => { |
| 126 | + const input = tags.stripIndent` |
| 127 | +import { Actions } from '@ngrx/effects'; |
| 128 | +import { concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; |
| 129 | +
|
| 130 | +class SomeEffects {} |
| 131 | + `; |
| 132 | + const output = tags.stripIndent` |
| 133 | +import { Actions } from '@ngrx/effects'; |
| 134 | +import { createEffect, ofType } from '@ngrx/effects'; |
| 135 | +import { concatLatestFrom } from '@ngrx/operators'; |
| 136 | +
|
| 137 | +class SomeEffects {} |
| 138 | + `; |
| 139 | + await verifySchematic(input, output); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should operate on multiple files', async () => { |
| 143 | + const inputMainOne = tags.stripIndent` |
| 144 | +import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; |
| 145 | +import { tap } from 'rxjs/operators'; |
| 146 | +
|
| 147 | +class SomeEffects {} |
| 148 | +`; |
| 149 | + |
| 150 | + const outputMainOne = tags.stripIndent` |
| 151 | +import { Actions, createEffect, ofType } from '@ngrx/effects'; |
| 152 | +import { concatLatestFrom } from '@ngrx/operators'; |
| 153 | +import { tap } from 'rxjs/operators'; |
| 154 | +
|
| 155 | +class SomeEffects {} |
| 156 | +`; |
| 157 | + |
| 158 | + const inputMainTwo = tags.stripIndent` |
| 159 | +import { provideEffects } from '@ngrx/effects'; |
| 160 | +import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; |
| 161 | +
|
| 162 | +class SomeEffects {} |
| 163 | +`; |
| 164 | + |
| 165 | + const outputMainTwo = tags.stripIndent` |
| 166 | +import { provideEffects } from '@ngrx/effects'; |
| 167 | +import { Actions, createEffect, ofType } from '@ngrx/effects'; |
| 168 | +import { concatLatestFrom } from '@ngrx/operators'; |
| 169 | +
|
| 170 | +class SomeEffects {} |
| 171 | +`; |
| 172 | + appTree.create('mainOne.ts', inputMainOne); |
| 173 | + appTree.create('mainTwo.ts', inputMainTwo); |
| 174 | + |
| 175 | + const tree = await schematicRunner.runSchematic( |
| 176 | + `ngrx-effects-migration-18-beta`, |
| 177 | + {}, |
| 178 | + appTree |
| 179 | + ); |
| 180 | + |
| 181 | + const actualMainOne = tree.readContent('mainOne.ts'); |
| 182 | + const actualMainTwo = tree.readContent('mainTwo.ts'); |
| 183 | + |
| 184 | + expect(actualMainOne).toBe(outputMainOne); |
| 185 | + expect(actualMainTwo).toBe(outputMainTwo); |
| 186 | + }); |
| 187 | + |
| 188 | + it('should report an info on multiple imports of concatLatestFrom', async () => { |
| 189 | + const input = tags.stripIndent` |
| 190 | +import { concatLatestFrom } from '@ngrx/effects'; |
| 191 | +import { concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; |
| 192 | +
|
| 193 | +class SomeEffects {} |
| 194 | + `; |
| 195 | + |
| 196 | + appTree.create('main.ts', input); |
| 197 | + const logEntries: LogEntry[] = []; |
| 198 | + schematicRunner.logger.subscribe((logEntry) => logEntries.push(logEntry)); |
| 199 | + await schematicRunner.runSchematic( |
| 200 | + `ngrx-effects-migration-18-beta`, |
| 201 | + {}, |
| 202 | + appTree |
| 203 | + ); |
| 204 | + |
| 205 | + expect(logEntries).toHaveLength(1); |
| 206 | + expect(logEntries[0]).toMatchObject({ |
| 207 | + message: |
| 208 | + '[@ngrx/effects] Skipping because of multiple `concatLatestFrom` imports', |
| 209 | + level: 'info', |
| 210 | + }); |
| 211 | + }); |
| 212 | + |
| 213 | + it('should add @ngrx/operators if they are missing', async () => { |
125 | 214 | const originalPackageJson = JSON.parse(
|
126 | 215 | appTree.readContent('/package.json')
|
127 | 216 | );
|
|
0 commit comments