|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -import {RecipeSpec} from "../../../src/test"; |
17 | | -import {ChangeImport, npm, packageJson, tsx, typescript} from "../../../src/javascript"; |
18 | | -import {withDir} from "tmp-promise"; |
| 16 | +import { RecipeSpec } from "../../../src/test"; |
| 17 | +import { ChangeImport, npm, packageJson, tsx, typescript } from "../../../src/javascript"; |
| 18 | +import { withDir } from "tmp-promise"; |
19 | 19 |
|
20 | 20 | describe("change-import", () => { |
21 | 21 | describe("named imports", () => { |
@@ -52,7 +52,7 @@ describe("change-import", () => { |
52 | 52 | }`) |
53 | 53 | ) |
54 | 54 | ); |
55 | | - }, {unsafeCleanup: true}); |
| 55 | + }, { unsafeCleanup: true }); |
56 | 56 | }); |
57 | 57 |
|
58 | 58 | test("changes named import with double quotes", async () => { |
@@ -88,7 +88,7 @@ describe("change-import", () => { |
88 | 88 | }`) |
89 | 89 | ) |
90 | 90 | ); |
91 | | - }, {unsafeCleanup: true}); |
| 91 | + }, { unsafeCleanup: true }); |
92 | 92 | }); |
93 | 93 |
|
94 | 94 | test("preserves other imports from the same module", async () => { |
@@ -127,7 +127,7 @@ describe("change-import", () => { |
127 | 127 | }`) |
128 | 128 | ) |
129 | 129 | ); |
130 | | - }, {unsafeCleanup: true}); |
| 130 | + }, { unsafeCleanup: true }); |
131 | 131 | }); |
132 | 132 |
|
133 | 133 | test("does not change import from different module", async () => { |
@@ -157,7 +157,7 @@ describe("change-import", () => { |
157 | 157 | }`) |
158 | 158 | ) |
159 | 159 | ); |
160 | | - }, {unsafeCleanup: true}); |
| 160 | + }, { unsafeCleanup: true }); |
161 | 161 | }); |
162 | 162 |
|
163 | 163 | test("does not change unrelated imports from the same module", async () => { |
@@ -188,7 +188,7 @@ describe("change-import", () => { |
188 | 188 | }`) |
189 | 189 | ) |
190 | 190 | ); |
191 | | - }, {unsafeCleanup: true}); |
| 191 | + }, { unsafeCleanup: true }); |
192 | 192 | }); |
193 | 193 |
|
194 | 194 | test("adds import from target module", async () => { |
@@ -228,7 +228,7 @@ describe("change-import", () => { |
228 | 228 | }`) |
229 | 229 | ) |
230 | 230 | ); |
231 | | - }, {unsafeCleanup: true}); |
| 231 | + }, { unsafeCleanup: true }); |
232 | 232 | }); |
233 | 233 |
|
234 | 234 | test("preserves aliased import", async () => { |
@@ -264,7 +264,7 @@ describe("change-import", () => { |
264 | 264 | }`) |
265 | 265 | ) |
266 | 266 | ); |
267 | | - }, {unsafeCleanup: true}); |
| 267 | + }, { unsafeCleanup: true }); |
268 | 268 | }); |
269 | 269 | }); |
270 | 270 |
|
@@ -299,7 +299,7 @@ describe("change-import", () => { |
299 | 299 | }`) |
300 | 300 | ) |
301 | 301 | ); |
302 | | - }, {unsafeCleanup: true}); |
| 302 | + }, { unsafeCleanup: true }); |
303 | 303 | }); |
304 | 304 | }); |
305 | 305 |
|
@@ -334,7 +334,7 @@ describe("change-import", () => { |
334 | 334 | }`) |
335 | 335 | ) |
336 | 336 | ); |
337 | | - }, {unsafeCleanup: true}); |
| 337 | + }, { unsafeCleanup: true }); |
338 | 338 | }); |
339 | 339 | }); |
340 | 340 |
|
@@ -370,7 +370,68 @@ describe("change-import", () => { |
370 | 370 | }`) |
371 | 371 | ) |
372 | 372 | ); |
373 | | - }, {unsafeCleanup: true}); |
| 373 | + }, { unsafeCleanup: true }); |
| 374 | + }); |
| 375 | + |
| 376 | + test("renames aliased member when changing import", async () => { |
| 377 | + const spec = new RecipeSpec(); |
| 378 | + spec.recipe = new ChangeImport({ |
| 379 | + oldModule: "lodash", |
| 380 | + oldMember: "extend", |
| 381 | + newModule: "lodash", |
| 382 | + newMember: "assign" |
| 383 | + }); |
| 384 | + |
| 385 | + await withDir(async (repo) => { |
| 386 | + await spec.rewriteRun( |
| 387 | + npm( |
| 388 | + repo.path, |
| 389 | + typescript( |
| 390 | + ` |
| 391 | + import { extend as myExtend } from 'lodash'; |
| 392 | + `, |
| 393 | + ` |
| 394 | + import { assign as myExtend } from 'lodash'; |
| 395 | + ` |
| 396 | + ), |
| 397 | + packageJson(`{ |
| 398 | + "name": "test", |
| 399 | + "dependencies": { |
| 400 | + "lodash": "^4.17.21" |
| 401 | + } |
| 402 | + }`) |
| 403 | + ) |
| 404 | + ); |
| 405 | + }, { unsafeCleanup: true }); |
| 406 | + }); |
| 407 | + |
| 408 | + test("does not rename if member is local alias only", async () => { |
| 409 | + const spec = new RecipeSpec(); |
| 410 | + spec.recipe = new ChangeImport({ |
| 411 | + oldModule: "lodash", |
| 412 | + oldMember: "extend", |
| 413 | + newModule: "lodash", |
| 414 | + newMember: "assign" |
| 415 | + }); |
| 416 | + |
| 417 | + await withDir(async (repo) => { |
| 418 | + await spec.rewriteRun( |
| 419 | + npm( |
| 420 | + repo.path, |
| 421 | + typescript( |
| 422 | + ` |
| 423 | + import { flatten as extend } from 'lodash'; |
| 424 | + ` |
| 425 | + ), |
| 426 | + packageJson(`{ |
| 427 | + "name": "test", |
| 428 | + "dependencies": { |
| 429 | + "lodash": "^4.17.21" |
| 430 | + } |
| 431 | + }`) |
| 432 | + ) |
| 433 | + ); |
| 434 | + }, { unsafeCleanup: true }); |
374 | 435 | }); |
375 | 436 | }); |
376 | 437 |
|
@@ -414,7 +475,7 @@ describe("change-import", () => { |
414 | 475 | }`) |
415 | 476 | ) |
416 | 477 | ); |
417 | | - }, {unsafeCleanup: true}); |
| 478 | + }, { unsafeCleanup: true }); |
418 | 479 | }); |
419 | 480 | }); |
420 | 481 | }); |
0 commit comments