-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(ng-update): hammer v9 migration should not unnecessarily set up gestures #17713
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,12 @@ describe('v9 HammerJS removal', () => { | |
import 'hammerjs'; | ||
`); | ||
|
||
await runMigration(); | ||
const {logOutput} = await runMigration(); | ||
|
||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).not.toContain('hammerjs'); | ||
expect(logOutput).toContain( | ||
'General notice: The HammerJS v9 migration for Angular components is not able to ' + | ||
'migrate tests. Please manually clean up tests in your project if they rely on HammerJS.'); | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should remove empty named import to load hammerjs', async () => { | ||
|
@@ -310,9 +313,13 @@ describe('v9 HammerJS removal', () => { | |
} | ||
`); | ||
|
||
await runMigration(); | ||
const {logOutput} = await runMigration(); | ||
|
||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`); | ||
expect(logOutput).toContain( | ||
'General notice: The HammerJS v9 migration for Angular components is not able to ' + | ||
'migrate tests. Please manually clean up tests in your project if they rely on the ' + | ||
'deprecated Angular Material gesture config.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we link them to the gesture config API or docs in case they haven't touched that part of their app in years or no one who set that up is still on the team? If you Google "Angular Material gesture config", you mostly just see docs for Angular's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message will be only printed if they explicitly reference the I'm hesitant to adding any link since our docs page is likely to change in the future and we don't even have docs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to at least mention the |
||
}); | ||
|
||
it('should ignore global reference to Hammer if not resolved to known types', async () => { | ||
|
@@ -741,70 +748,180 @@ describe('v9 HammerJS removal', () => { | |
.toBe('0.0.0'); | ||
}); | ||
|
||
it('should not remove hammerjs if no usage could be detected but custom gesture config is set up', | ||
async () => { | ||
appendContent('/projects/cdk-testing/src/main.ts', ` | ||
import 'hammerjs'; | ||
`); | ||
|
||
writeFile('/projects/cdk-testing/src/test.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {} | ||
`); | ||
|
||
writeFile('/projects/cdk-testing/src/sub.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {GestureConfig} from '@angular/material/core'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: GestureConfig | ||
}, | ||
], | ||
}) | ||
export class SubModule {} | ||
`); | ||
|
||
const {logOutput} = await runMigration(); | ||
|
||
expect(logOutput).toContain(`unable to perform the full migration for this target, but ` + | ||
`removed all references to the deprecated Angular Material gesture config.`); | ||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain('hammerjs'); | ||
expect(tree.readContent('/projects/cdk-testing/src/test.component.ts')).toContain(dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {}`); | ||
expect(tree.readContent('/projects/cdk-testing/src/sub.component.ts')).toContain(dedent` | ||
import {NgModule} from '@angular/core'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
], | ||
}) | ||
export class SubModule {}`); | ||
}); | ||
describe('with custom gesture config', () => { | ||
beforeEach(() => { | ||
addPackageToPackageJson(tree, 'hammerjs', '0.0.0'); | ||
appendContent('/projects/cdk-testing/src/main.ts', `import 'hammerjs';`); | ||
}); | ||
|
||
it('should not setup copied gesture config if hammer is used in template', async () => { | ||
writeFile('/projects/cdk-testing/src/test.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {} | ||
`); | ||
|
||
writeFile('/projects/cdk-testing/src/app/app.component.html', ` | ||
<span (longpress)="onPress()"></span> | ||
`); | ||
|
||
await runMigration(); | ||
|
||
expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(false); | ||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain('hammerjs'); | ||
expect(runner.tasks.some(t => t.name === 'node-package')).toBe(false); | ||
expect(tree.readContent('/projects/cdk-testing/src/test.component.ts')).toContain(dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {}`); | ||
}); | ||
|
||
it('should warn if hammer is used in template and references to Material gesture config ' + | ||
'were detected', async () => { | ||
writeFile('/projects/cdk-testing/src/test.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {} | ||
`); | ||
|
||
const subModuleFileContent = dedent` | ||
import {NgModule} from '@angular/core'; | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {GestureConfig} from '@angular/material/core'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: GestureConfig | ||
}, | ||
], | ||
}) | ||
export class SubModule {} | ||
`; | ||
|
||
writeFile('/projects/cdk-testing/src/sub.module.ts', subModuleFileContent); | ||
writeFile('/projects/cdk-testing/src/app/app.component.html', ` | ||
<span (longpress)="onPress()"></span> | ||
`); | ||
|
||
const {logOutput} = await runMigration(); | ||
|
||
expect(logOutput).toContain( | ||
'This target cannot be migrated completely. Please manually remove references ' + | ||
'to the deprecated Angular Material gesture config.'); | ||
expect(runner.tasks.some(t => t.name === 'node-package')).toBe(false); | ||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain('hammerjs'); | ||
expect(tree.readContent('/projects/cdk-testing/src/test.component.ts')).toContain(dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {}`); | ||
expect(tree.readContent('/projects/cdk-testing/src/sub.module.ts')) | ||
.toBe(subModuleFileContent); | ||
}); | ||
|
||
it('should not remove hammerjs if no usage could be detected', async () => { | ||
writeFile('/projects/cdk-testing/src/test.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {} | ||
`); | ||
|
||
writeFile('/projects/cdk-testing/src/sub.component.ts', dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {GestureConfig} from '@angular/material/core'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: GestureConfig | ||
}, | ||
], | ||
}) | ||
export class SubModule {} | ||
`); | ||
|
||
const {logOutput} = await runMigration(); | ||
|
||
expect(logOutput).toContain( | ||
'This target cannot be migrated completely, but all references to the ' + | ||
'deprecated Angular Material gesture have been removed.'); | ||
expect(runner.tasks.some(t => t.name === 'node-package')).toBe(false); | ||
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain('hammerjs'); | ||
expect(tree.readContent('/projects/cdk-testing/src/test.component.ts')).toContain(dedent` | ||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
import {CustomGestureConfig} from "../gesture-config"; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: HAMMER_GESTURE_CONFIG, | ||
useClass: CustomGestureConfig | ||
}, | ||
], | ||
}) | ||
export class TestModule {}`); | ||
expect(tree.readContent('/projects/cdk-testing/src/sub.component.ts')).toContain(dedent` | ||
import {NgModule} from '@angular/core'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
], | ||
}) | ||
export class SubModule {}`); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.