-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router-store): add migration to add the default serializer (#2291)
- Loading branch information
1 parent
b8a769a
commit b742a8c
Showing
32 changed files
with
797 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { | ||
SchematicTestRunner, | ||
UnitTestTree, | ||
} from '@angular-devkit/schematics/testing'; | ||
import * as path from 'path'; | ||
import { createPackageJson } from '../../../schematics-core/testing/create-package'; | ||
|
||
describe('Router Store Migration 9_0_0', () => { | ||
let appTree: UnitTestTree; | ||
const collectionPath = path.join(__dirname, '../migration.json'); | ||
const pkgName = 'router-store'; | ||
|
||
beforeEach(() => { | ||
appTree = new UnitTestTree(Tree.empty()); | ||
appTree.create( | ||
'/tsconfig.json', | ||
` | ||
{ | ||
"include": [**./*.ts"] | ||
} | ||
` | ||
); | ||
createPackageJson('', pkgName, appTree); | ||
}); | ||
|
||
describe('Adds the default serializer when none is set', () => { | ||
it(`should use the default serializer if none was present (empty)`, () => { | ||
const input = ` | ||
import { StoreRouterConnectingModule } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot(), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
const expected = ` | ||
import { StoreRouterConnectingModule, DefaultRouterStateSerializer } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot({ serializer: DefaultRouterStateSerializer }), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
|
||
test(input, expected); | ||
}); | ||
|
||
it(`should use the default serializer if none was present (with props)`, () => { | ||
const input = ` | ||
import { StoreRouterConnectingModule } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot({ key: 'router' }), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
const expected = ` | ||
import { StoreRouterConnectingModule, DefaultRouterStateSerializer } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot({ serializer: DefaultRouterStateSerializer, key: 'router' }), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
|
||
test(input, expected); | ||
}); | ||
|
||
it(`should not run the migration if there was a serializer set`, () => { | ||
const input = ` | ||
import { StoreRouterConnectingModule } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot({ serializer: CustomSerializer }), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
const expected = input; | ||
|
||
test(input, expected); | ||
}); | ||
|
||
it(`should not run the migration if there was a routerState set`, () => { | ||
const input = ` | ||
import { StoreRouterConnectingModule, RouterState } from '@ngrx/router-store'; | ||
@NgModule({ | ||
imports: [ | ||
AuthModule, | ||
AppRoutingModule, | ||
StoreRouterConnectingModule.forRoot({ routerState: RouterState.Minimal }), | ||
CoreModule, | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} | ||
`; | ||
const expected = input; | ||
|
||
test(input, expected); | ||
}); | ||
|
||
function test(input: string, expected: string) { | ||
appTree.create('./app.module.ts', input); | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
|
||
const newTree = runner.runSchematic( | ||
`ngrx-${pkgName}-migration-03`, | ||
{}, | ||
appTree | ||
); | ||
const file = newTree.readContent('app.module.ts'); | ||
|
||
expect(file).toBe(expected); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.