-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): update ngrx packages to v16
- Loading branch information
1 parent
54eb7be
commit 4fdb3ec
Showing
6 changed files
with
539 additions
and
25 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
309 changes: 309 additions & 0 deletions
309
...ions/update-16-1-4/switch-data-persistence-operators-imports-to-ngrx-router-store.spec.ts
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,309 @@ | ||
import { ProjectGraph, Tree, addProjectConfiguration } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import migration from './switch-data-persistence-operators-imports-to-ngrx-router-store'; | ||
|
||
let projectGraph: ProjectGraph; | ||
jest.mock('@nx/devkit', () => ({ | ||
...jest.requireActual('@nx/devkit'), | ||
createProjectGraphAsync: jest | ||
.fn() | ||
.mockImplementation(async () => projectGraph), | ||
})); | ||
|
||
describe('switch-data-persistence-operators-imports-to-ngrx-router-store migration', () => { | ||
let tree: Tree; | ||
const file = 'apps/app1/src/app/+state/users.effects.ts'; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
addProjectConfiguration(tree, 'app1', { root: 'apps/app1' }); | ||
projectGraph = { | ||
dependencies: { | ||
app1: [{ source: 'app1', target: 'npm:@nx/angular', type: 'static' }], | ||
}, | ||
nodes: { | ||
app1: { | ||
data: { | ||
files: [ | ||
{ | ||
file, | ||
hash: '', | ||
dependencies: [ | ||
{ | ||
source: 'app1', | ||
target: 'npm:@nx/angular', | ||
type: 'static', | ||
}, | ||
], | ||
}, | ||
], | ||
root: 'apps/app1', | ||
}, | ||
name: 'app1', | ||
type: 'app', | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
it('should do nothing when there are no imports from the angular plugin', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should not replace the import path when no operator is imported', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { foo } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { foo } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should not match imports from angular plugin secondary entry points', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@nx/angular/mf'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@nx/angular/mf'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should replace the import path in-place when it is importing an operator', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should match imports using @nrwl/angular', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@nrwl/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should support multiple operators imports', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch, navigation } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch, navigation } from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should add a separate import statement when there are operator and non-operator imports', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch, foo, navigation } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch, navigation } from '@ngrx/router-store/data-persistence'; | ||
import { foo } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should support multiple import statements and import paths', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@nx/angular'; | ||
import { navigation } from '@nrwl/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch } from '@ngrx/router-store/data-persistence'; | ||
import { navigation } from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should support renamed import symbols', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch as customFetch } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch as customFetch } from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should support multiple imports with renamed and non-renamed symbols', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch as customFetch, navigation } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { | ||
fetch as customFetch, | ||
navigation, | ||
} from '@ngrx/router-store/data-persistence'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
|
||
it('should add a separate import statement even with renamed symbols', async () => { | ||
tree.write( | ||
file, | ||
`import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { fetch as customFetch, foo, navigation } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
` | ||
); | ||
|
||
await migration(tree); | ||
|
||
expect(tree.read(file, 'utf-8')).toMatchInlineSnapshot(` | ||
"import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { | ||
fetch as customFetch, | ||
navigation, | ||
} from '@ngrx/router-store/data-persistence'; | ||
import { foo } from '@nx/angular'; | ||
@Injectable() | ||
class UsersEffects {} | ||
" | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.