|
| 1 | +import { |
| 2 | + addProjectConfiguration, |
| 3 | + readProjectConfiguration, |
| 4 | +} from '@nrwl/devkit'; |
| 5 | +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; |
| 6 | + |
| 7 | +import update from './rename-servertarget-to-target'; |
| 8 | + |
| 9 | +describe('Migration - rename-servertarget-to-target', () => { |
| 10 | + it('should rename serverTarget to target', async () => { |
| 11 | + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); |
| 12 | + |
| 13 | + addProjectConfiguration( |
| 14 | + tree, |
| 15 | + 'example', |
| 16 | + { |
| 17 | + root: 'apps/example', |
| 18 | + projectType: 'application', |
| 19 | + targets: { |
| 20 | + dev: { |
| 21 | + executor: 'nx-ngrok:tunnel', |
| 22 | + options: { |
| 23 | + serverTarget: 'my-app:serve', |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + true |
| 29 | + ); |
| 30 | + |
| 31 | + await update(tree); |
| 32 | + |
| 33 | + const config = readProjectConfiguration(tree, 'example'); |
| 34 | + |
| 35 | + expect(config.targets?.dev.options).not.toHaveProperty('serverTarget'); |
| 36 | + expect(config.targets?.dev.options).toHaveProperty( |
| 37 | + 'target', |
| 38 | + 'my-app:serve' |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not add target to configurations without a serverTarget', async () => { |
| 43 | + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); |
| 44 | + |
| 45 | + addProjectConfiguration( |
| 46 | + tree, |
| 47 | + 'example', |
| 48 | + { |
| 49 | + root: 'apps/example', |
| 50 | + projectType: 'application', |
| 51 | + targets: { |
| 52 | + dev: { |
| 53 | + executor: 'nx-ngrok:tunnel', |
| 54 | + options: { |
| 55 | + port: 3000, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + true |
| 61 | + ); |
| 62 | + |
| 63 | + await update(tree); |
| 64 | + |
| 65 | + const config = readProjectConfiguration(tree, 'example'); |
| 66 | + |
| 67 | + expect(config.targets?.dev.options).not.toHaveProperty('serverTarget'); |
| 68 | + expect(config.targets?.dev.options).not.toHaveProperty('target'); |
| 69 | + |
| 70 | + expect(config.targets?.dev.options).toHaveProperty('port', 3000); |
| 71 | + }); |
| 72 | +}); |
0 commit comments