-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): launching app on simulator with different appId than pa…
…ckageName (#2195)
- Loading branch information
Showing
4 changed files
with
136 additions
and
2 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
133 changes: 133 additions & 0 deletions
133
packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.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,133 @@ | ||
import {AndroidProjectConfig} from '@react-native-community/cli-types'; | ||
import tryLaunchAppOnDevice from '../tryLaunchAppOnDevice'; | ||
import {Flags} from '..'; | ||
import execa from 'execa'; | ||
|
||
jest.mock('execa'); | ||
jest.mock('../getAdbPath'); | ||
jest.mock('../tryLaunchEmulator'); | ||
|
||
const adbPath = 'path/to/adb'; | ||
const device = 'emulator-5554'; | ||
let args: Flags = { | ||
activeArchOnly: false, | ||
packager: true, | ||
port: 8081, | ||
terminal: 'iTerm.app', | ||
appId: '', | ||
appIdSuffix: '', | ||
listDevices: false, | ||
}; | ||
|
||
let androidProject: AndroidProjectConfig = { | ||
sourceDir: '/Users/thymikee/Developer/tmp/App73/android', | ||
appName: 'app', | ||
packageName: 'com.myapp', | ||
applicationId: 'com.myapp.custom', | ||
mainActivity: '.MainActivity', | ||
dependencyConfiguration: undefined, | ||
watchModeCommandParams: undefined, | ||
unstable_reactLegacyComponentNames: undefined, | ||
}; | ||
|
||
const shellStartCommand = ['shell', 'am', 'start']; | ||
const actionCategoryFlags = [ | ||
'-a', | ||
'android.intent.action.MAIN', | ||
'-c', | ||
'android.intent.category.LAUNCHER', | ||
]; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('launches adb shell with intent to launch com.myapp.MainActivity with different appId than packageName on a simulator', () => { | ||
tryLaunchAppOnDevice(device, androidProject, adbPath, args); | ||
|
||
expect(execa.sync).toHaveBeenCalledWith( | ||
'path/to/adb', | ||
[ | ||
'-s', | ||
'emulator-5554', | ||
...shellStartCommand, | ||
'-n', | ||
'com.myapp.custom/com.myapp.MainActivity', | ||
...actionCategoryFlags, | ||
], | ||
{stdio: 'inherit'}, | ||
); | ||
}); | ||
|
||
test('launches adb shell with intent to launch com.myapp.MainActivity with same appId as packageName on a simulator', () => { | ||
tryLaunchAppOnDevice( | ||
device, | ||
{...androidProject, applicationId: 'com.myapp'}, | ||
adbPath, | ||
args, | ||
); | ||
|
||
expect(execa.sync).toHaveBeenCalledWith( | ||
'path/to/adb', | ||
[ | ||
'-s', | ||
'emulator-5554', | ||
...shellStartCommand, | ||
'-n', | ||
'com.myapp/com.myapp.MainActivity', | ||
...actionCategoryFlags, | ||
], | ||
{stdio: 'inherit'}, | ||
); | ||
}); | ||
|
||
test('launches adb shell with intent to launch com.myapp.MainActivity with different appId than packageName on a device (without calling simulator)', () => { | ||
tryLaunchAppOnDevice(undefined, androidProject, adbPath, args); | ||
|
||
expect(execa.sync).toHaveBeenCalledWith( | ||
'path/to/adb', | ||
[ | ||
...shellStartCommand, | ||
'-n', | ||
'com.myapp.custom/com.myapp.MainActivity', | ||
...actionCategoryFlags, | ||
], | ||
{stdio: 'inherit'}, | ||
); | ||
}); | ||
|
||
test('--appId flag overwrites applicationId setting in androidProject', () => { | ||
tryLaunchAppOnDevice(undefined, androidProject, adbPath, { | ||
...args, | ||
appId: 'my.app.id', | ||
}); | ||
|
||
expect(execa.sync).toHaveBeenCalledWith( | ||
'path/to/adb', | ||
[ | ||
...shellStartCommand, | ||
'-n', | ||
'my.app.id/com.myapp.MainActivity', | ||
...actionCategoryFlags, | ||
], | ||
{stdio: 'inherit'}, | ||
); | ||
}); | ||
|
||
test('appIdSuffix Staging is appended to applicationId', () => { | ||
tryLaunchAppOnDevice(undefined, androidProject, adbPath, { | ||
...args, | ||
appIdSuffix: 'Staging', | ||
}); | ||
|
||
expect(execa.sync).toHaveBeenCalledWith( | ||
'path/to/adb', | ||
[ | ||
...shellStartCommand, | ||
'-n', | ||
'com.myapp.custom.Staging/com.myapp.MainActivity', | ||
...actionCategoryFlags, | ||
], | ||
{stdio: 'inherit'}, | ||
); | ||
}); |
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