From 7da8696cf3ce61e53da797a604f1039d9da89589 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sat, 5 Oct 2019 19:27:10 +0530 Subject: [PATCH 1/5] [FEAT] Test deprecate-router-events codemod --- src/index.js | 2 +- .../latest-node/my-app/app/routes/index.js | 22 +++++++++++++++++++ .../codemod/local/my-app/app/routes/index.js | 21 ++++++++++++++++++ .../min-node/my-app/app/routes/index.js | 22 +++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/codemod/latest-node/my-app/app/routes/index.js create mode 100644 test/fixtures/codemod/local/my-app/app/routes/index.js create mode 100644 test/fixtures/codemod/min-node/my-app/app/routes/index.js diff --git a/src/index.js b/src/index.js index 61a9656f4..8c3c6f4e8 100644 --- a/src/index.js +++ b/src/index.js @@ -196,7 +196,7 @@ All blueprints are up-to-date!`; statsOnly, listCodemods, runCodemods, - codemodsUrl: 'https://raw.githubusercontent.com/ember-cli/ember-cli-update-codemods-manifest/v3/manifest.json', + codemodsUrl: 'https://raw.githubusercontent.com/rajasegar/ember-cli-update-codemods-manifest/deprecate-router-events/manifest.json', createCustomDiff, ignoredFiles: [await getBlueprintFilePath(cwd)], wasRunAsExecutable diff --git a/test/fixtures/codemod/latest-node/my-app/app/routes/index.js b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js new file mode 100644 index 000000000..7848de62f --- /dev/null +++ b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js @@ -0,0 +1,22 @@ +import Router from '@ember/routing/router'; +import { inject as service } from '@ember/service'; + +export default Router.extend({ + currentUser: service('current-user'), + + init() { + this._super(...arguments); + this.on('routeWillChange', transition => { + if (!this.currentUser.isLoggedIn) { + transition.abort(); + this.transitionTo('login'); + } + }); + + this.on('routeDidChange', transition => { + ga.send('pageView', { + pageName: transition.to.name + }); + }); + } +}); diff --git a/test/fixtures/codemod/local/my-app/app/routes/index.js b/test/fixtures/codemod/local/my-app/app/routes/index.js new file mode 100644 index 000000000..6d1caa466 --- /dev/null +++ b/test/fixtures/codemod/local/my-app/app/routes/index.js @@ -0,0 +1,21 @@ +import Router from '@ember/routing/router'; +import { inject as service } from '@ember/service'; + +export default Router.extend({ + currentUser: service('current-user'), + + willTransition(transition) { + this._super(...arguments); + if (!this.currentUser.isLoggedIn) { + transition.abort(); + this.transitionTo('login'); + } + }, + + didTransition(privateInfos) { + this._super(...arguments); + ga.send('pageView', { + pageName: privateInfos.name + }); + } +}); diff --git a/test/fixtures/codemod/min-node/my-app/app/routes/index.js b/test/fixtures/codemod/min-node/my-app/app/routes/index.js new file mode 100644 index 000000000..7848de62f --- /dev/null +++ b/test/fixtures/codemod/min-node/my-app/app/routes/index.js @@ -0,0 +1,22 @@ +import Router from '@ember/routing/router'; +import { inject as service } from '@ember/service'; + +export default Router.extend({ + currentUser: service('current-user'), + + init() { + this._super(...arguments); + this.on('routeWillChange', transition => { + if (!this.currentUser.isLoggedIn) { + transition.abort(); + this.transitionTo('login'); + } + }); + + this.on('routeDidChange', transition => { + ga.send('pageView', { + pageName: transition.to.name + }); + }); + } +}); From e8ff3db3d6b48a566cd9b38442075413c5300fb0 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Thu, 10 Oct 2019 16:04:20 +0530 Subject: [PATCH 2/5] [TESTS] Change output fixtures Since the codemod doesn't change the function body, changing the fixtures to reflect the same. --- test/fixtures/codemod/latest-node/my-app/app/routes/index.js | 2 +- test/fixtures/codemod/min-node/my-app/app/routes/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/codemod/latest-node/my-app/app/routes/index.js b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js index 7848de62f..a67fcc4fe 100644 --- a/test/fixtures/codemod/latest-node/my-app/app/routes/index.js +++ b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js @@ -15,7 +15,7 @@ export default Router.extend({ this.on('routeDidChange', transition => { ga.send('pageView', { - pageName: transition.to.name + pageName: privateInfos.name }); }); } diff --git a/test/fixtures/codemod/min-node/my-app/app/routes/index.js b/test/fixtures/codemod/min-node/my-app/app/routes/index.js index 7848de62f..a67fcc4fe 100644 --- a/test/fixtures/codemod/min-node/my-app/app/routes/index.js +++ b/test/fixtures/codemod/min-node/my-app/app/routes/index.js @@ -15,7 +15,7 @@ export default Router.extend({ this.on('routeDidChange', transition => { ga.send('pageView', { - pageName: transition.to.name + pageName: privateInfos.name }); }); } From 5da57f0ea68fc0cc3aa8ca65dae9efb6741f3d18 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Thu, 10 Oct 2019 16:44:59 +0530 Subject: [PATCH 3/5] [BUGFIX] Adding missing newline to output fixtures --- test/fixtures/codemod/latest-node/my-app/app/routes/index.js | 1 + test/fixtures/codemod/min-node/my-app/app/routes/index.js | 1 + 2 files changed, 2 insertions(+) diff --git a/test/fixtures/codemod/latest-node/my-app/app/routes/index.js b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js index a67fcc4fe..9a48cfaa3 100644 --- a/test/fixtures/codemod/latest-node/my-app/app/routes/index.js +++ b/test/fixtures/codemod/latest-node/my-app/app/routes/index.js @@ -6,6 +6,7 @@ export default Router.extend({ init() { this._super(...arguments); + this.on('routeWillChange', transition => { if (!this.currentUser.isLoggedIn) { transition.abort(); diff --git a/test/fixtures/codemod/min-node/my-app/app/routes/index.js b/test/fixtures/codemod/min-node/my-app/app/routes/index.js index a67fcc4fe..9a48cfaa3 100644 --- a/test/fixtures/codemod/min-node/my-app/app/routes/index.js +++ b/test/fixtures/codemod/min-node/my-app/app/routes/index.js @@ -6,6 +6,7 @@ export default Router.extend({ init() { this._super(...arguments); + this.on('routeWillChange', transition => { if (!this.currentUser.isLoggedIn) { transition.abort(); From 337c0bc1263968abed554e9b8c21604cf3382bfe Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Thu, 10 Oct 2019 15:07:32 +0100 Subject: [PATCH 4/5] newline --- test/fixtures/codemod/local/my-app/app/routes/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixtures/codemod/local/my-app/app/routes/index.js b/test/fixtures/codemod/local/my-app/app/routes/index.js index 6d1caa466..5bee25154 100644 --- a/test/fixtures/codemod/local/my-app/app/routes/index.js +++ b/test/fixtures/codemod/local/my-app/app/routes/index.js @@ -6,6 +6,7 @@ export default Router.extend({ willTransition(transition) { this._super(...arguments); + if (!this.currentUser.isLoggedIn) { transition.abort(); this.transitionTo('login'); @@ -14,6 +15,7 @@ export default Router.extend({ didTransition(privateInfos) { this._super(...arguments); + ga.send('pageView', { pageName: privateInfos.name }); From 0e612b0088c1a2332379191433b15d86837fa4bb Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Thu, 10 Oct 2019 15:07:44 +0100 Subject: [PATCH 5/5] revert fork --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 8c3c6f4e8..61a9656f4 100644 --- a/src/index.js +++ b/src/index.js @@ -196,7 +196,7 @@ All blueprints are up-to-date!`; statsOnly, listCodemods, runCodemods, - codemodsUrl: 'https://raw.githubusercontent.com/rajasegar/ember-cli-update-codemods-manifest/deprecate-router-events/manifest.json', + codemodsUrl: 'https://raw.githubusercontent.com/ember-cli/ember-cli-update-codemods-manifest/v3/manifest.json', createCustomDiff, ignoredFiles: [await getBlueprintFilePath(cwd)], wasRunAsExecutable