mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
This commit is contained in:
@@ -38,16 +38,7 @@ describe('AndroidProject', () => {
|
||||
expect(project.projectDir).toBe(PROJECT_DIR);
|
||||
});
|
||||
|
||||
it('should set www folder correctly if not Android Studio project', () => {
|
||||
AndroidStudioSpy.isAndroidStudioProject.and.returnValue(false);
|
||||
|
||||
const project = new AndroidProject(PROJECT_DIR);
|
||||
expect(project.www).toBe(path.join(PROJECT_DIR, 'assets/www'));
|
||||
});
|
||||
|
||||
it('should set www folder correctly if it is an Android Studio project', () => {
|
||||
AndroidStudioSpy.isAndroidStudioProject.and.returnValue(true);
|
||||
|
||||
const project = new AndroidProject(PROJECT_DIR);
|
||||
expect(project.www).toBe(path.join(PROJECT_DIR, 'app/src/main/assets/www'));
|
||||
});
|
||||
@@ -108,19 +99,8 @@ describe('AndroidProject', () => {
|
||||
androidProject = new AndroidProject(PROJECT_DIR);
|
||||
});
|
||||
|
||||
it('should get the package name from the project root manifest', () => {
|
||||
AndroidStudioSpy.isAndroidStudioProject.and.returnValue(false);
|
||||
|
||||
it('should get the package name AndroidManifest', () => {
|
||||
androidProject.getPackageName();
|
||||
|
||||
expect(AndroidManifestSpy).toHaveBeenCalledWith(path.join(PROJECT_DIR, 'AndroidManifest.xml'));
|
||||
});
|
||||
|
||||
it('should get the package name from the Android Studio manifest', () => {
|
||||
AndroidStudioSpy.isAndroidStudioProject.and.returnValue(true);
|
||||
|
||||
androidProject.getPackageName();
|
||||
|
||||
expect(AndroidManifestSpy).toHaveBeenCalledWith(path.join(PROJECT_DIR, 'app/src/main/AndroidManifest.xml'));
|
||||
});
|
||||
|
||||
|
||||
@@ -31,24 +31,15 @@ describe('builders', () => {
|
||||
|
||||
describe('getBuilder', () => {
|
||||
it('should return an instance of ProjectBuilder when gradle is requested', () => {
|
||||
const newBuilder = builders.getBuilder('gradle');
|
||||
const newBuilder = builders.getBuilder();
|
||||
expect(newBuilder).toEqual(jasmine.any(ProjectBuilder));
|
||||
});
|
||||
|
||||
it('should return an instance of ProjectBuilder when studio is requested', () => {
|
||||
const newBuilder = builders.getBuilder('studio');
|
||||
expect(newBuilder).toEqual(jasmine.any(ProjectBuilder));
|
||||
});
|
||||
|
||||
it('should throw an error if the selected builder does not exist', () => {
|
||||
expect(() => builders.getBuilder('NonExistentBuilder')).toThrow(jasmine.any(CordovaError));
|
||||
});
|
||||
|
||||
it('should throw an error if a builder cannot be instantiated', () => {
|
||||
const requireSpy = jasmine.createSpy('require').and.throwError();
|
||||
builders.__set__('require', requireSpy);
|
||||
|
||||
expect(() => builders.getBuilder('gradle')).toThrow(jasmine.any(CordovaError));
|
||||
expect(() => builders.getBuilder()).toThrow(jasmine.any(CordovaError));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -274,7 +274,7 @@ describe('create', function () {
|
||||
});
|
||||
it('should prepare build files', function (done) {
|
||||
create.create(project_path, config_mock, {}, events_mock).then(function () {
|
||||
expect(create.prepBuildFiles).toHaveBeenCalledWith(project_path, 'studio');
|
||||
expect(create.prepBuildFiles).toHaveBeenCalledWith(project_path);
|
||||
}).fail(fail).done(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -61,14 +61,14 @@ describe('android project handler', function () {
|
||||
|
||||
describe('of <lib-file> elements', function () {
|
||||
it('Test#001 : should copy files for Android Studio projects', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/TestLib.jar', temp, path.join('app', 'libs', 'TestLib.jar'), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <resource-file> elements', function () {
|
||||
it('Test#002 : should copy files to the correct location on an Android Studio project', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'android-resource.xml', temp, path.join('app', 'src', 'main', 'res', 'xml', 'dummy.xml'), false);
|
||||
});
|
||||
});
|
||||
@@ -81,13 +81,7 @@ describe('android project handler', function () {
|
||||
it('Test#003 : should copy stuff from one location to another by calling common.copyFile', function () {
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
expect(copyFileSpy)
|
||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin.java', temp, path.join('src/com/phonegap/plugins/dummyplugin/DummyPlugin.java'), false);
|
||||
});
|
||||
|
||||
it('Test#004 : should install source files to the right location for Android Studio projects', function () {
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
expect(copyFileSpy)
|
||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin.java', temp, path.join('app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java'), false);
|
||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin.java', temp, path.join('app', 'src', 'main', 'java', 'com', 'phonegap', 'plugins', 'dummyplugin', 'DummyPlugin.java'), false);
|
||||
});
|
||||
|
||||
it('Test#005 : should throw if source file cannot be found', function () {
|
||||
@@ -99,7 +93,7 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#006 : should throw if target file already exists', function () {
|
||||
// write out a file
|
||||
var target = path.resolve(temp, 'src/com/phonegap/plugins/dummyplugin');
|
||||
let target = path.resolve(temp, 'app', 'src', 'main', 'java', 'com', 'phonegap', 'plugins', 'dummyplugin');
|
||||
shell.mkdir('-p', target);
|
||||
target = path.join(target, 'DummyPlugin.java');
|
||||
fs.writeFileSync(target, 'some bs', 'utf-8');
|
||||
@@ -243,24 +237,24 @@ describe('android project handler', function () {
|
||||
|
||||
describe('of <lib-file> elements', function () {
|
||||
it('Test#017 : should remove jar files for Android Studio projects', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestLib.jar'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <resource-file> elements', function () {
|
||||
it('Test#018 : should remove files for Android Studio projects', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['resource-file'].uninstall(valid_resources[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/res/xml/dummy.xml'));
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
android['resource-file'].uninstall(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app', 'src', 'main', 'res', 'xml', 'dummy.xml'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <source-file> elements', function () {
|
||||
it('Test#019 : should remove stuff by calling common.deleteJava for Android Studio projects', function () {
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['source-file'].uninstall(valid_source[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
android['source-file'].uninstall(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java'));
|
||||
});
|
||||
});
|
||||
|
||||
+2
-16
@@ -42,23 +42,18 @@ describe('run', () => {
|
||||
});
|
||||
|
||||
describe('run method', () => {
|
||||
let buildSpyObj;
|
||||
let deviceSpyObj;
|
||||
let emulatorSpyObj;
|
||||
let eventsSpyObj;
|
||||
let getInstallTargetSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
buildSpyObj = jasmine.createSpyObj('buildSpy', ['run']);
|
||||
deviceSpyObj = jasmine.createSpyObj('deviceSpy', ['install', 'list', 'resolveTarget']);
|
||||
emulatorSpyObj = jasmine.createSpyObj('emulatorSpy', ['install', 'list_images', 'list_started', 'resolveTarget', 'start', 'wait_for_boot']);
|
||||
eventsSpyObj = jasmine.createSpyObj('eventsSpy', ['emit']);
|
||||
getInstallTargetSpy = jasmine.createSpy('getInstallTargetSpy');
|
||||
|
||||
buildSpyObj.run.and.returnValue(Promise.resolve());
|
||||
|
||||
run.__set__({
|
||||
build: buildSpyObj,
|
||||
device: deviceSpyObj,
|
||||
emulator: emulatorSpyObj,
|
||||
events: eventsSpyObj,
|
||||
@@ -180,22 +175,13 @@ describe('run', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should build the app if a target has been found', () => {
|
||||
getInstallTargetSpy.and.returnValue('--device');
|
||||
deviceSpyObj.resolveTarget.and.returnValue({ target: 'device1', isEmulator: false });
|
||||
|
||||
return run.run().then(() => {
|
||||
expect(buildSpyObj.run).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should install on device after build', () => {
|
||||
const deviceTarget = { target: 'device1', isEmulator: false };
|
||||
getInstallTargetSpy.and.returnValue('--device');
|
||||
deviceSpyObj.resolveTarget.and.returnValue(deviceTarget);
|
||||
|
||||
return run.run().then(() => {
|
||||
expect(deviceSpyObj.install).toHaveBeenCalledWith(deviceTarget, undefined);
|
||||
expect(deviceSpyObj.install).toHaveBeenCalledWith(deviceTarget, {apkPaths: [], buildType: 'debug'});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -207,7 +193,7 @@ describe('run', () => {
|
||||
emulatorSpyObj.wait_for_boot.and.returnValue(Promise.resolve());
|
||||
|
||||
return run.run().then(() => {
|
||||
expect(emulatorSpyObj.install).toHaveBeenCalledWith(emulatorTarget, undefined);
|
||||
expect(emulatorSpyObj.install).toHaveBeenCalledWith(emulatorTarget, {apkPaths: [], buildType: 'debug'});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user