mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
CB-12895 : fixed eslint errors
This commit is contained in:
@@ -16,12 +16,13 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var actions = require('./helpers/projectActions.js');
|
||||
|
||||
var CREATE_TIMEOUT = 180000;
|
||||
|
||||
function createAndBuild(projectname, projectid, done) {
|
||||
function createAndBuild (projectname, projectid, done) {
|
||||
actions.createProject(projectname, projectid, function (error) {
|
||||
expect(error).toBe(null);
|
||||
actions.buildProject(projectid, function (error) {
|
||||
@@ -32,45 +33,44 @@ function createAndBuild(projectname, projectid, done) {
|
||||
});
|
||||
}
|
||||
|
||||
describe('create', function () {
|
||||
|
||||
describe('create', function() {
|
||||
|
||||
it('Test#001 : create project with ascii name, no spaces', function(done) {
|
||||
it('Test#001 : create project with ascii name, no spaces', function (done) {
|
||||
var projectname = 'testcreate';
|
||||
var projectid = 'com.test.create.app1';
|
||||
|
||||
createAndBuild(projectname, projectid, done);
|
||||
}, CREATE_TIMEOUT);
|
||||
|
||||
it('Test#002 : create project with ascii name, and spaces', function(done) {
|
||||
it('Test#002 : create project with ascii name, and spaces', function (done) {
|
||||
var projectname = 'test create';
|
||||
var projectid = 'com.test.create.app2';
|
||||
|
||||
createAndBuild(projectname, projectid, done);
|
||||
}, CREATE_TIMEOUT);
|
||||
|
||||
it('Test#003 : create project with unicode name, no spaces', function(done) {
|
||||
it('Test#003 : create project with unicode name, no spaces', function (done) {
|
||||
var projectname = '応応応応用用用用';
|
||||
var projectid = 'com.test.create.app3';
|
||||
|
||||
createAndBuild(projectname, projectid, done);
|
||||
}, CREATE_TIMEOUT);
|
||||
|
||||
it('Test#004 : create project with unicode name, and spaces', function(done) {
|
||||
it('Test#004 : create project with unicode name, and spaces', function (done) {
|
||||
var projectname = '応応応応 用用用用';
|
||||
var projectid = 'com.test.create.app4';
|
||||
|
||||
createAndBuild(projectname, projectid, done);
|
||||
}, CREATE_TIMEOUT);
|
||||
|
||||
it('Test#005 : create project with ascii+unicode name, no spaces', function(done) {
|
||||
it('Test#005 : create project with ascii+unicode name, no spaces', function (done) {
|
||||
var projectname = '応応応応hello用用用用';
|
||||
var projectid = 'com.test.create.app5';
|
||||
|
||||
createAndBuild(projectname, projectid, done);
|
||||
}, CREATE_TIMEOUT);
|
||||
|
||||
it('Test#006 : create project with ascii+unicode name, and spaces', function(done) {
|
||||
it('Test#006 : create project with ascii+unicode name, and spaces', function (done) {
|
||||
var projectname = '応応応応 hello 用用用用';
|
||||
var projectid = 'com.test.create.app6';
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
var PluginInfoProvider = require('cordova-common').PluginInfoProvider,
|
||||
shell = require('shelljs'),
|
||||
cp = require('child_process'),
|
||||
path = require('path'),
|
||||
util = require('util');
|
||||
var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
|
||||
var shell = require('shelljs');
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
|
||||
var cordova_bin = path.join(__dirname, '../../../bin');
|
||||
|
||||
@@ -70,7 +70,7 @@ module.exports.updateProject = function (projectid, platformpath, callback) {
|
||||
var projectDirName = getDirName(projectid);
|
||||
var updateScriptPath = platformpath ? path.join(platformpath, 'bin/update') : path.join(cordova_bin, 'update');
|
||||
var command = util.format('%s %s', updateScriptPath, projectDirName);
|
||||
|
||||
|
||||
cp.exec(command, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
console.log(stdout);
|
||||
@@ -78,7 +78,7 @@ module.exports.updateProject = function (projectid, platformpath, callback) {
|
||||
}
|
||||
callback(error);
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ module.exports.removeProject = function (projectid) {
|
||||
* @param {function} callback - function which is called (without arguments) when the plugin is added or (with error object) when error occurs
|
||||
*/
|
||||
module.exports.addPlugin = function (projectid, plugindir, callback) {
|
||||
var projectDirName = getDirName(projectid);
|
||||
var projectDirName = getDirName(projectid);
|
||||
var pip = new PluginInfoProvider();
|
||||
var pluginInfo = pip.get(plugindir);
|
||||
var Api = require(path.join(__dirname, '../../..', projectDirName, 'cordova', 'Api.js'));
|
||||
@@ -126,7 +126,7 @@ module.exports.addPlugin = function (projectid, plugindir, callback) {
|
||||
}, function (error) {
|
||||
console.error(error);
|
||||
callback(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -136,7 +136,7 @@ module.exports.addPlugin = function (projectid, plugindir, callback) {
|
||||
*/
|
||||
module.exports.getPlatformVersion = function (projectid, callback) {
|
||||
var command = path.join(getDirName(projectid), 'cordova/version');
|
||||
|
||||
|
||||
cp.exec(command, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
console.log(stdout);
|
||||
@@ -146,6 +146,6 @@ module.exports.getPlatformVersion = function (projectid, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
function getDirName(projectid) {
|
||||
function getDirName (projectid) {
|
||||
return 'test-' + projectid;
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var path = require('path'),
|
||||
actions = require('./helpers/projectActions.js');
|
||||
var path = require('path');
|
||||
var actions = require('./helpers/projectActions.js');
|
||||
|
||||
var PLUGIN_ADD_TIMEOUT = 90000;
|
||||
|
||||
describe('plugin add', function() {
|
||||
describe('plugin add', function () {
|
||||
|
||||
it('Test#001 : create project and add a plugin with framework', function(done) {
|
||||
it('Test#001 : create project and add a plugin with framework', function (done) {
|
||||
var projectname = 'testpluginframework';
|
||||
var projectid = 'com.test.plugin.framework';
|
||||
var fakePluginPath = path.join(__dirname, 'fixtures/cordova-plugin-fake');
|
||||
|
||||
+15
-14
@@ -16,23 +16,24 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var actions = require('./helpers/projectActions.js'),
|
||||
shell = require('shelljs'),
|
||||
fs = require('fs'),
|
||||
util = require('util'),
|
||||
platformOld = { version: '4.0.0', path: 'cordova-android-old' },
|
||||
platformEdge = { version: getCurrentVersion(), path: '.' };
|
||||
var actions = require('./helpers/projectActions.js');
|
||||
var shell = require('shelljs');
|
||||
var fs = require('fs');
|
||||
var util = require('util');
|
||||
var platformOld = { version: '4.0.0', path: 'cordova-android-old' };
|
||||
var platformEdge = { version: getCurrentVersion(), path: '.' };
|
||||
|
||||
var DOWNLOAD_TIMEOUT = 2 * 60 * 1000,
|
||||
UPDATE_TIMEOUT = 90 * 1000,
|
||||
PLATFORM_GIT_URL = 'https://github.com/apache/cordova-android';
|
||||
var DOWNLOAD_TIMEOUT = 2 * 60 * 1000;
|
||||
var UPDATE_TIMEOUT = 90 * 1000;
|
||||
var PLATFORM_GIT_URL = 'https://github.com/apache/cordova-android';
|
||||
|
||||
function getCurrentVersion() {
|
||||
function getCurrentVersion () {
|
||||
return fs.readFileSync('VERSION').toString().trim();
|
||||
}
|
||||
|
||||
function testUpdate(projectname, projectid, createfrom, updatefrom, doBuild, done) {
|
||||
function testUpdate (projectname, projectid, createfrom, updatefrom, doBuild, done) {
|
||||
actions.createProject(projectname, projectid, createfrom.path, function (error) {
|
||||
expect(error).toBe(null);
|
||||
actions.updateProject(projectid, updatefrom.path, function (error) {
|
||||
@@ -68,9 +69,9 @@ describe('preparing fixtures', function () {
|
||||
|
||||
});
|
||||
|
||||
describe('update', function() {
|
||||
describe('update', function () {
|
||||
|
||||
it('Test#002 : should update major version and build the project', function(done) {
|
||||
it('Test#002 : should update major version and build the project', function (done) {
|
||||
var projectname = 'testupdate';
|
||||
var projectid = 'com.test.update.app1';
|
||||
|
||||
@@ -82,7 +83,7 @@ describe('update', function() {
|
||||
|
||||
describe('cleanup', function () {
|
||||
|
||||
it('Test#004 : remove cloned old platform', function() {
|
||||
it('Test#004 : remove cloned old platform', function () {
|
||||
shell.rm('-rf', platformOld.path);
|
||||
});
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
./org.test.plugins.dummyplugin/www/dummyplugin.js
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var path = require('path');
|
||||
var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
|
||||
var android_project = path.join(__dirname, '../fixtures/android_project');
|
||||
|
||||
describe('AndroidProject class', function() {
|
||||
describe('getPackageName method', function() {
|
||||
it('Test#001 : should return an android project\'s proper package name', function() {
|
||||
describe('AndroidProject class', function () {
|
||||
describe('getPackageName method', function () {
|
||||
it('Test#001 : should return an android project\'s proper package name', function () {
|
||||
expect(AndroidProject.getProjectFile(android_project).getPackageName())
|
||||
.toEqual('com.alunny.childapp');
|
||||
});
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
|
||||
/* eslint-env jasmine */
|
||||
var path = require('path');
|
||||
var AndroidStudio = require('../../bin/templates/cordova/lib/AndroidStudio');
|
||||
|
||||
|
||||
describe('AndroidStudio module', function () {
|
||||
it('should return true for Android Studio project', function() {
|
||||
var root = path.join(__dirname,'../fixtures/android_studio_project/');
|
||||
var isAndStud = AndroidStudio.isAndroidStudioProject(root);
|
||||
expect(isAndStud).toBe(true);
|
||||
it('should return true for Android Studio project', function () {
|
||||
var root = path.join(__dirname, '../fixtures/android_studio_project/');
|
||||
var isAndStud = AndroidStudio.isAndroidStudioProject(root);
|
||||
expect(isAndStud).toBe(true);
|
||||
});
|
||||
it('should return false non Android Studio project', function() {
|
||||
var root = path.join(__dirname,'../fixtures/android_project/');
|
||||
var isAndStud = AndroidStudio.isAndroidStudioProject(root);
|
||||
expect(isAndStud).toBe(false);
|
||||
it('should return false non Android Studio project', function () {
|
||||
var root = path.join(__dirname, '../fixtures/android_project/');
|
||||
var isAndStud = AndroidStudio.isAndroidStudioProject(root);
|
||||
expect(isAndStud).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
/* jshint node:true */
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var Q = require('q');
|
||||
var os = require('os');
|
||||
@@ -37,7 +38,7 @@ describe('addPlugin method', function () {
|
||||
var api, fail, gradleBuilder, oldClean;
|
||||
var Api = rewire('../../bin/templates/cordova/Api');
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
var pluginManager = jasmine.createSpyObj('pluginManager', ['addPlugin']);
|
||||
pluginManager.addPlugin.and.returnValue(Q());
|
||||
spyOn(common.PluginManager, 'get').and.returnValue(pluginManager);
|
||||
@@ -58,20 +59,16 @@ describe('addPlugin method', function () {
|
||||
Api.__set__('Api.prototype.clean', oldClean);
|
||||
});
|
||||
|
||||
it('Test#001 : should call gradleBuilder.prepBuildFiles for every plugin with frameworks', function(done) {
|
||||
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake')))
|
||||
.catch(fail)
|
||||
.fin(function () {
|
||||
it('Test#001 : should call gradleBuilder.prepBuildFiles for every plugin with frameworks', function (done) {
|
||||
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake'))).catch(fail).fin(function () {
|
||||
expect(fail).not.toHaveBeenCalled();
|
||||
expect(gradleBuilder.prepBuildFiles).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Test#002 : shouldn\'t trigger gradleBuilder.prepBuildFiles for plugins without android frameworks', function(done) {
|
||||
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake-ios-frameworks')))
|
||||
.catch(fail)
|
||||
.fin(function () {
|
||||
it('Test#002 : shouldn\'t trigger gradleBuilder.prepBuildFiles for plugins without android frameworks', function (done) {
|
||||
api.addPlugin(new PluginInfo(path.join(FIXTURES, 'cordova-plugin-fake-ios-frameworks'))).catch(fail).fin(function () {
|
||||
expect(fail).not.toHaveBeenCalled();
|
||||
expect(gradleBuilder.prepBuildFiles).not.toHaveBeenCalled();
|
||||
done();
|
||||
|
||||
@@ -17,114 +17,108 @@
|
||||
under the License.
|
||||
*/
|
||||
/* jshint laxcomma:true */
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var android_sdk = require("../../bin/templates/cordova/lib/android_sdk");
|
||||
var superspawn = require("cordova-common").superspawn;
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
|
||||
var superspawn = require('cordova-common').superspawn;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
|
||||
describe("android_sdk", function () {
|
||||
describe("list_targets_with_android", function() {
|
||||
it("should invoke `android` with the `list target` command and _not_ the `list targets` command, as the plural form is not supported in some Android SDK Tools versions", function() {
|
||||
describe('android_sdk', function () {
|
||||
describe('list_targets_with_android', function () {
|
||||
it('should invoke `android` with the `list target` command and _not_ the `list targets` command, as the plural form is not supported in some Android SDK Tools versions', function () {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
android_sdk.list_targets_with_android();
|
||||
expect(superspawn.spawn).toHaveBeenCalledWith("android", ["list", "target"]);
|
||||
expect(superspawn.spawn).toHaveBeenCalledWith('android', ['list', 'target']);
|
||||
});
|
||||
it("should parse and return results from `android list targets` command", function(done) {
|
||||
it('should parse and return results from `android list targets` command', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.2-android_list_targets.txt"), "utf-8"));
|
||||
return android_sdk.list_targets_with_android()
|
||||
.then(function(list) {
|
||||
[ "Google Inc.:Google APIs:23",
|
||||
"Google Inc.:Google APIs:22",
|
||||
"Google Inc.:Google APIs:21",
|
||||
"android-25",
|
||||
"android-24",
|
||||
"android-N",
|
||||
"android-23",
|
||||
"android-MNC",
|
||||
"android-22",
|
||||
"android-21",
|
||||
"android-20" ].forEach(function(target) {
|
||||
expect(list).toContain(target);
|
||||
});
|
||||
}).fail(function(err) {
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.2-android_list_targets.txt'), 'utf-8'));
|
||||
return android_sdk.list_targets_with_android().then(function (list) {
|
||||
[ 'Google Inc.:Google APIs:23',
|
||||
'Google Inc.:Google APIs:22',
|
||||
'Google Inc.:Google APIs:21',
|
||||
'android-25',
|
||||
'android-24',
|
||||
'android-N',
|
||||
'android-23',
|
||||
'android-MNC',
|
||||
'android-22',
|
||||
'android-21',
|
||||
'android-20' ].forEach(function (target) { expect(list).toContain(target); });
|
||||
}).fail(function (err) {
|
||||
console.log(err);
|
||||
expect(err).toBeUndefined();
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("list_targets_with_avdmanager", function() {
|
||||
it("should parse and return results from `avdmanager list target` command", function(done) {
|
||||
describe('list_targets_with_avdmanager', function () {
|
||||
it('should parse and return results from `avdmanager list target` command', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.3-avdmanager_list_target.txt"), "utf-8"));
|
||||
return android_sdk.list_targets_with_avdmanager()
|
||||
.then(function(list) {
|
||||
expect(list).toContain("android-25");
|
||||
}).fail(function(err) {
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.3-avdmanager_list_target.txt'), 'utf-8'));
|
||||
return android_sdk.list_targets_with_avdmanager().then(function (list) {
|
||||
expect(list).toContain('android-25');
|
||||
}).fail(function (err) {
|
||||
console.log(err);
|
||||
expect(err).toBeUndefined();
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("list_targets", function() {
|
||||
it("should parse Android SDK installed target information with `avdmanager` command first", function() {
|
||||
describe('list_targets', function () {
|
||||
it('should parse Android SDK installed target information with `avdmanager` command first', function () {
|
||||
var deferred = Q.defer();
|
||||
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||
var avdmanager_spy = spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(deferred.promise);
|
||||
android_sdk.list_targets();
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
});
|
||||
it("should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with ENOENT", function(done) {
|
||||
it('should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with ENOENT', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(deferred.promise);
|
||||
deferred.reject({
|
||||
code: "ENOENT"
|
||||
code: 'ENOENT'
|
||||
});
|
||||
var twoferred = Q.defer();
|
||||
twoferred.resolve(["target1"]);
|
||||
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_android").and.returnValue(twoferred.promise);
|
||||
return android_sdk.list_targets()
|
||||
.then(function(targets) {
|
||||
twoferred.resolve(['target1']);
|
||||
var avdmanager_spy = spyOn(android_sdk, 'list_targets_with_android').and.returnValue(twoferred.promise);
|
||||
return android_sdk.list_targets().then(function (targets) {
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
expect(targets[0]).toEqual("target1");
|
||||
expect(targets[0]).toEqual('target1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with not-recognized error (Windows)", function(done) {
|
||||
it('should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with not-recognized error (Windows)', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(deferred.promise);
|
||||
deferred.reject({
|
||||
code: 1,
|
||||
stderr: "'avdmanager' is not recognized as an internal or external commmand,\r\noperable program or batch file.\r\n"
|
||||
});
|
||||
var twoferred = Q.defer();
|
||||
twoferred.resolve(["target1"]);
|
||||
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_android").and.returnValue(twoferred.promise);
|
||||
return android_sdk.list_targets()
|
||||
.then(function(targets) {
|
||||
twoferred.resolve(['target1']);
|
||||
var avdmanager_spy = spyOn(android_sdk, 'list_targets_with_android').and.returnValue(twoferred.promise);
|
||||
return android_sdk.list_targets().then(function (targets) {
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
expect(targets[0]).toEqual("target1");
|
||||
expect(targets[0]).toEqual('target1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should throw an error if no Android targets were found.", function(done) {
|
||||
it('should throw an error if no Android targets were found.', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(deferred.promise);
|
||||
deferred.resolve([]);
|
||||
return android_sdk.list_targets()
|
||||
.then(function(targets) {
|
||||
return android_sdk.list_targets().then(function (targets) {
|
||||
done.fail();
|
||||
}).catch(function(err) {
|
||||
}).catch(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("No android targets (SDKs) installed!");
|
||||
expect(err.message).toContain('No android targets (SDKs) installed!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
var gradle_builder = require('../../../bin/templates/cordova/lib/builders/GradleBuilder.js');
|
||||
/* eslint-env jasmine */
|
||||
var Gradle_builder = require('../../../bin/templates/cordova/lib/builders/GradleBuilder.js');
|
||||
var fs = require('fs');
|
||||
var superspawn = require('cordova-common').superspawn;
|
||||
var builder;
|
||||
|
||||
describe('Gradle Builder', function() {
|
||||
beforeEach(function() {
|
||||
describe('Gradle Builder', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
builder = new gradle_builder('/root');
|
||||
builder = new Gradle_builder('/root');
|
||||
spyOn(superspawn, 'spawn');
|
||||
});
|
||||
|
||||
describe('runGradleWrapper method', function() {
|
||||
it('should run the provided gradle command if a gradle wrapper does not already exist', function() {
|
||||
describe('runGradleWrapper method', function () {
|
||||
it('should run the provided gradle command if a gradle wrapper does not already exist', function () {
|
||||
fs.existsSync.and.returnValue(false);
|
||||
builder.runGradleWrapper('/my/sweet/gradle');
|
||||
expect(superspawn.spawn).toHaveBeenCalledWith('/my/sweet/gradle', jasmine.any(Array), jasmine.any(Object));
|
||||
});
|
||||
it('should do nothing if a gradle wrapper exists in the project directory', function() {
|
||||
it('should do nothing if a gradle wrapper exists in the project directory', function () {
|
||||
fs.existsSync.and.returnValue(true);
|
||||
builder.runGradleWrapper('/my/sweet/gradle');
|
||||
expect(superspawn.spawn).not.toHaveBeenCalledWith('/my/sweet/gradle', jasmine.any(Array), jasmine.any(Object));
|
||||
|
||||
+109
-119
@@ -17,233 +17,223 @@
|
||||
under the License.
|
||||
*/
|
||||
/* jshint laxcomma:true */
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var check_reqs = require("../../bin/templates/cordova/lib/check_reqs");
|
||||
var android_sdk = require("../../bin/templates/cordova/lib/android_sdk");
|
||||
var shelljs = require("shelljs");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var check_reqs = require('../../bin/templates/cordova/lib/check_reqs');
|
||||
var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
|
||||
var shelljs = require('shelljs');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
|
||||
describe("check_reqs", function () {
|
||||
describe('check_reqs', function () {
|
||||
var original_env;
|
||||
beforeAll(function() {
|
||||
beforeAll(function () {
|
||||
original_env = Object.create(process.env);
|
||||
});
|
||||
afterEach(function() {
|
||||
Object.keys(original_env).forEach(function(k) {
|
||||
afterEach(function () {
|
||||
Object.keys(original_env).forEach(function (k) {
|
||||
process.env[k] = original_env[k];
|
||||
});
|
||||
});
|
||||
describe("check_android", function() {
|
||||
describe("set ANDROID_HOME if not set", function() {
|
||||
beforeEach(function() {
|
||||
describe('check_android', function () {
|
||||
describe('set ANDROID_HOME if not set', function () {
|
||||
beforeEach(function () {
|
||||
delete process.env.ANDROID_HOME;
|
||||
});
|
||||
describe("even if no Android binaries are on the PATH", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(shelljs, "which").and.returnValue(null);
|
||||
spyOn(fs, "existsSync").and.returnValue(true);
|
||||
describe('even if no Android binaries are on the PATH', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(shelljs, 'which').and.returnValue(null);
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
});
|
||||
it("it should set ANDROID_HOME on Windows", function(done) {
|
||||
spyOn(check_reqs, "isWindows").and.returnValue(true);
|
||||
process.env.LOCALAPPDATA = "windows-local-app-data";
|
||||
process.env.ProgramFiles = "windows-program-files";
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.ANDROID_HOME).toContain("windows-local-app-data");
|
||||
}).fail(function(err) {
|
||||
it('it should set ANDROID_HOME on Windows', function (done) {
|
||||
spyOn(check_reqs, 'isWindows').and.returnValue(true);
|
||||
process.env.LOCALAPPDATA = 'windows-local-app-data';
|
||||
process.env.ProgramFiles = 'windows-program-files';
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_HOME).toContain('windows-local-app-data');
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
delete process.env.LOCALAPPDATA;
|
||||
delete process.env.ProgramFiles;
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("it should set ANDROID_HOME on Darwin", function(done) {
|
||||
spyOn(check_reqs, "isWindows").and.returnValue(false);
|
||||
spyOn(check_reqs, "isDarwin").and.returnValue(true);
|
||||
process.env.HOME = "home is where the heart is";
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.ANDROID_HOME).toContain("home is where the heart is");
|
||||
}).fail(function(err) {
|
||||
it('it should set ANDROID_HOME on Darwin', function (done) {
|
||||
spyOn(check_reqs, 'isWindows').and.returnValue(false);
|
||||
spyOn(check_reqs, 'isDarwin').and.returnValue(true);
|
||||
process.env.HOME = 'home is where the heart is';
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_HOME).toContain('home is where the heart is');
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
delete process.env.HOME;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("if some Android tooling exists on the PATH", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(fs, "realpathSync").and.callFake(function(path) {
|
||||
describe('if some Android tooling exists on the PATH', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(fs, 'realpathSync').and.callFake(function (path) {
|
||||
return path;
|
||||
});
|
||||
});
|
||||
it("should set ANDROID_HOME based on `android` command if command exists in a SDK-like directory structure", function(done) {
|
||||
spyOn(fs, "existsSync").and.returnValue(true);
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "android") {
|
||||
return "/android/sdk/tools/android";
|
||||
it('should set ANDROID_HOME based on `android` command if command exists in a SDK-like directory structure', function (done) {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'android') {
|
||||
return '/android/sdk/tools/android';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_HOME).toEqual('/android/sdk');
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
it("should error out if `android` command exists in a non-SDK-like directory structure", function(done) {
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "android") {
|
||||
return "/just/some/random/path/android";
|
||||
it('should error out if `android` command exists in a non-SDK-like directory structure', function (done) {
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'android') {
|
||||
return '/just/some/random/path/android';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
return check_reqs.check_android().then(function () {
|
||||
done.fail();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("update your PATH to include valid path");
|
||||
expect(err.message).toContain('update your PATH to include valid path');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should set ANDROID_HOME based on `adb` command if command exists in a SDK-like directory structure", function(done) {
|
||||
spyOn(fs, "existsSync").and.returnValue(true);
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "adb") {
|
||||
return "/android/sdk/platform-tools/adb";
|
||||
it('should set ANDROID_HOME based on `adb` command if command exists in a SDK-like directory structure', function (done) {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'adb') {
|
||||
return '/android/sdk/platform-tools/adb';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_HOME).toEqual('/android/sdk');
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
it("should error out if `adb` command exists in a non-SDK-like directory structure", function(done) {
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "adb") {
|
||||
return "/just/some/random/path/adb";
|
||||
it('should error out if `adb` command exists in a non-SDK-like directory structure', function (done) {
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'adb') {
|
||||
return '/just/some/random/path/adb';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
return check_reqs.check_android().then(function () {
|
||||
done.fail();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("update your PATH to include valid path");
|
||||
expect(err.message).toContain('update your PATH to include valid path');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should set ANDROID_HOME based on `avdmanager` command if command exists in a SDK-like directory structure", function(done) {
|
||||
spyOn(fs, "existsSync").and.returnValue(true);
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "avdmanager") {
|
||||
return "/android/sdk/tools/bin/avdmanager";
|
||||
it('should set ANDROID_HOME based on `avdmanager` command if command exists in a SDK-like directory structure', function (done) {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'avdmanager') {
|
||||
return '/android/sdk/tools/bin/avdmanager';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_HOME).toEqual('/android/sdk');
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
it("should error out if `avdmanager` command exists in a non-SDK-like directory structure", function(done) {
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "avdmanager") {
|
||||
return "/just/some/random/path/avdmanager";
|
||||
it('should error out if `avdmanager` command exists in a non-SDK-like directory structure', function (done) {
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'avdmanager') {
|
||||
return '/just/some/random/path/avdmanager';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
return check_reqs.check_android().then(function () {
|
||||
done.fail();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("update your PATH to include valid path");
|
||||
expect(err.message).toContain('update your PATH to include valid path');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("set PATH for various Android binaries if not available", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(shelljs, "which").and.returnValue(null);
|
||||
process.env.ANDROID_HOME = "let the children play";
|
||||
spyOn(fs, "existsSync").and.returnValue(true);
|
||||
describe('set PATH for various Android binaries if not available', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(shelljs, 'which').and.returnValue(null);
|
||||
process.env.ANDROID_HOME = 'let the children play';
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
delete process.env.ANDROID_HOME;
|
||||
});
|
||||
it("should add tools/bin,tools,platform-tools to PATH if `avdmanager`,`android`,`adb` is not found", function(done) {
|
||||
return check_reqs.check_android()
|
||||
.then(function() {
|
||||
expect(process.env.PATH).toContain("let the children play" + path.sep + "tools");
|
||||
expect(process.env.PATH).toContain("let the children play" + path.sep + "platform-tools");
|
||||
expect(process.env.PATH).toContain("let the children play" + path.sep + "tools" + path.sep + "bin");
|
||||
it('should add tools/bin,tools,platform-tools to PATH if `avdmanager`,`android`,`adb` is not found', function (done) {
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.PATH).toContain('let the children play' + path.sep + 'tools');
|
||||
expect(process.env.PATH).toContain('let the children play' + path.sep + 'platform-tools');
|
||||
expect(process.env.PATH).toContain('let the children play' + path.sep + 'tools' + path.sep + 'bin');
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("get_target", function() {
|
||||
it("should retrieve target from framework project.properties file", function() {
|
||||
describe('get_target', function () {
|
||||
it('should retrieve target from framework project.properties file', function () {
|
||||
var target = check_reqs.get_target();
|
||||
expect(target).toBeDefined();
|
||||
expect(target).toContain("android-");
|
||||
expect(target).toContain('android-');
|
||||
});
|
||||
});
|
||||
describe("check_android_target", function() {
|
||||
it("should should return full list of supported targets if there is a match to ideal api level", function(done) {
|
||||
describe('check_android_target', function () {
|
||||
it('should should return full list of supported targets if there is a match to ideal api level', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(android_sdk, "list_targets").and.returnValue(deferred.promise);
|
||||
var fake_targets = ["you are my fire", "my one desire"];
|
||||
spyOn(android_sdk, 'list_targets').and.returnValue(deferred.promise);
|
||||
var fake_targets = ['you are my fire', 'my one desire'];
|
||||
deferred.resolve(fake_targets);
|
||||
spyOn(check_reqs, "get_target").and.returnValue("you are my fire");
|
||||
return check_reqs.check_android_target()
|
||||
.then(function(targets) {
|
||||
spyOn(check_reqs, 'get_target').and.returnValue('you are my fire');
|
||||
return check_reqs.check_android_target().then(function (targets) {
|
||||
expect(targets).toBeDefined();
|
||||
expect(targets).toEqual(fake_targets);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should error out if there is no match between ideal api level and installed targets", function(done) {
|
||||
it('should error out if there is no match between ideal api level and installed targets', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(android_sdk, "list_targets").and.returnValue(deferred.promise);
|
||||
var fake_targets = ["you are my fire", "my one desire"];
|
||||
spyOn(android_sdk, 'list_targets').and.returnValue(deferred.promise);
|
||||
var fake_targets = ['you are my fire', 'my one desire'];
|
||||
deferred.resolve(fake_targets);
|
||||
spyOn(check_reqs, "get_target").and.returnValue("and i knowwwwwwwwwwww");
|
||||
return check_reqs.check_android_target()
|
||||
.catch(function(err) {
|
||||
spyOn(check_reqs, 'get_target').and.returnValue('and i knowwwwwwwwwwww');
|
||||
return check_reqs.check_android_target().catch(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("Please install Android target");
|
||||
expect(err.message).toContain('Please install Android target');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
+76
-80
@@ -17,96 +17,92 @@
|
||||
under the License.
|
||||
*/
|
||||
/* jshint laxcomma:true */
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var create = require("../../bin/lib/create");
|
||||
var create = require('../../bin/lib/create');
|
||||
|
||||
describe("create", function () {
|
||||
describe("validatePackageName", function() {
|
||||
var valid = [
|
||||
"org.apache.mobilespec"
|
||||
, "com.example"
|
||||
, "com.floors42.package"
|
||||
, "ball8.ball8.ball8ball"
|
||||
];
|
||||
var invalid = [
|
||||
""
|
||||
, "com.class.is.bad"
|
||||
, "0com.example.mobilespec"
|
||||
, "c-m.e@a!p%e.mobilespec"
|
||||
, "notenoughdots"
|
||||
, ".starts.with.a.dot"
|
||||
, "ends.with.a.dot."
|
||||
, "_underscore.anything"
|
||||
, "underscore._something"
|
||||
, "_underscore._all._the._things"
|
||||
, "8.ball"
|
||||
, "8ball.ball"
|
||||
, "ball8.8ball"
|
||||
, "ball8.com.8ball"
|
||||
];
|
||||
describe('create', function () {
|
||||
describe('validatePackageName', function () {
|
||||
var valid = [
|
||||
'org.apache.mobilespec',
|
||||
'com.example',
|
||||
'com.floors42.package',
|
||||
'ball8.ball8.ball8ball'
|
||||
];
|
||||
var invalid = [
|
||||
'',
|
||||
'com.class.is.bad',
|
||||
'0com.example.mobilespec',
|
||||
'c-m.e@a!p%e.mobilespec',
|
||||
'notenoughdots',
|
||||
'.starts.with.a.dot',
|
||||
'ends.with.a.dot.',
|
||||
'_underscore.anything',
|
||||
'underscore._something',
|
||||
'_underscore._all._the._things',
|
||||
'8.ball',
|
||||
'8ball.ball',
|
||||
'ball8.8ball',
|
||||
'ball8.com.8ball'
|
||||
];
|
||||
|
||||
valid.forEach(function(package_name) {
|
||||
it("Test#001 : should accept " + package_name, function(done) {
|
||||
return create.validatePackageName(package_name)
|
||||
.then(function() {
|
||||
//resolved
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
expect(err).toBeUndefined();
|
||||
valid.forEach(function (package_name) {
|
||||
it('Test#001 : should accept ' + package_name, function (done) {
|
||||
return create.validatePackageName(package_name).then(function () {
|
||||
// resolved
|
||||
done();
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
invalid.forEach(function(package_name) {
|
||||
it("Test#002 : should reject " + package_name, function(done) {
|
||||
return create.validatePackageName(package_name)
|
||||
.then(function() {
|
||||
//shouldn't be here
|
||||
expect(true).toBe(false);
|
||||
}).fail(function(err) {
|
||||
expect(err).toBeDefined();
|
||||
done();
|
||||
invalid.forEach(function (package_name) {
|
||||
it('Test#002 : should reject ' + package_name, function (done) {
|
||||
return create.validatePackageName(package_name).then(function () {
|
||||
// shouldn't be here
|
||||
expect(true).toBe(false);
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("validateProjectName", function() {
|
||||
var valid = [
|
||||
"mobilespec"
|
||||
, "package_name"
|
||||
, "PackageName"
|
||||
, "CordovaLib"
|
||||
];
|
||||
var invalid = [
|
||||
""
|
||||
, "0startswithdigit"
|
||||
, "CordovaActivity"
|
||||
];
|
||||
describe('validateProjectName', function () {
|
||||
var valid = [
|
||||
'mobilespec',
|
||||
'package_name',
|
||||
'PackageName',
|
||||
'CordovaLib'
|
||||
];
|
||||
var invalid = [
|
||||
'',
|
||||
'0startswithdigit',
|
||||
'CordovaActivity'
|
||||
];
|
||||
|
||||
valid.forEach(function(project_name) {
|
||||
it("Test#003 : should accept " + project_name, function(done) {
|
||||
return create.validateProjectName(project_name)
|
||||
.then(function() {
|
||||
//resolved
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
expect(err).toBeUndefined();
|
||||
valid.forEach(function (project_name) {
|
||||
it('Test#003 : should accept ' + project_name, function (done) {
|
||||
return create.validateProjectName(project_name).then(function () {
|
||||
// resolved
|
||||
done();
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
invalid.forEach(function(project_name) {
|
||||
it("Test#004 : should reject " + project_name, function(done) {
|
||||
return create.validateProjectName(project_name)
|
||||
.then(function() {
|
||||
//shouldn't be here
|
||||
expect(true).toBe(false);
|
||||
}).fail(function(err) {
|
||||
expect(err).toBeDefined();
|
||||
done();
|
||||
invalid.forEach(function (project_name) {
|
||||
it('Test#004 : should reject ' + project_name, function (done) {
|
||||
return create.validateProjectName(project_name).then(function () {
|
||||
// shouldn't be here
|
||||
expect(true).toBe(false);
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+51
-52
@@ -16,96 +16,95 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
var emu = require("../../bin/templates/cordova/lib/emulator");
|
||||
var superspawn = require("cordova-common").superspawn;
|
||||
var Q = require("q");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var shelljs = require("shelljs");
|
||||
/* eslint-env jasmine */
|
||||
|
||||
describe("emulator", function () {
|
||||
describe("list_images_using_avdmanager", function() {
|
||||
it("should properly parse details of SDK Tools 25.3.1 `avdmanager` output", function(done) {
|
||||
var emu = require('../../bin/templates/cordova/lib/emulator');
|
||||
var superspawn = require('cordova-common').superspawn;
|
||||
var Q = require('q');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var shelljs = require('shelljs');
|
||||
|
||||
describe('emulator', function () {
|
||||
describe('list_images_using_avdmanager', function () {
|
||||
it('should properly parse details of SDK Tools 25.3.1 `avdmanager` output', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.3-avdmanager_list_avd.txt"), "utf-8"));
|
||||
return emu.list_images_using_avdmanager()
|
||||
.then(function(list) {
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.3-avdmanager_list_avd.txt'), 'utf-8'));
|
||||
return emu.list_images_using_avdmanager().then(function (list) {
|
||||
expect(list).toBeDefined();
|
||||
expect(list[0].name).toEqual("nexus5-5.1");
|
||||
expect(list[0].target).toEqual("Android 5.1 (API level 22)");
|
||||
expect(list[1].device).toEqual("pixel (Google)");
|
||||
expect(list[2].abi).toEqual("default/x86_64");
|
||||
}).fail(function(err) {
|
||||
expect(list[0].name).toEqual('nexus5-5.1');
|
||||
expect(list[0].target).toEqual('Android 5.1 (API level 22)');
|
||||
expect(list[1].device).toEqual('pixel (Google)');
|
||||
expect(list[2].abi).toEqual('default/x86_64');
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("list_images_using_android", function() {
|
||||
it("should invoke `android` with the `list avd` command and _not_ the `list avds` command, as the plural form is not supported in some Android SDK Tools versions", function() {
|
||||
describe('list_images_using_android', function () {
|
||||
it('should invoke `android` with the `list avd` command and _not_ the `list avds` command, as the plural form is not supported in some Android SDK Tools versions', function () {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
emu.list_images_using_android();
|
||||
expect(superspawn.spawn).toHaveBeenCalledWith("android", ["list", "avd"]);
|
||||
expect(superspawn.spawn).toHaveBeenCalledWith('android', ['list', 'avd']);
|
||||
});
|
||||
it("should properly parse details of SDK Tools pre-25.3.1 `android list avd` output", function(done) {
|
||||
it('should properly parse details of SDK Tools pre-25.3.1 `android list avd` output', function (done) {
|
||||
var deferred = Q.defer();
|
||||
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.2-android_list_avd.txt"), "utf-8"));
|
||||
return emu.list_images_using_android()
|
||||
.then(function(list) {
|
||||
spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
|
||||
deferred.resolve(fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.2-android_list_avd.txt'), 'utf-8'));
|
||||
return emu.list_images_using_android().then(function (list) {
|
||||
expect(list).toBeDefined();
|
||||
expect(list[0].name).toEqual("QWR");
|
||||
expect(list[0].device).toEqual("Nexus 5 (Google)");
|
||||
expect(list[0].path).toEqual("/Users/shazron/.android/avd/QWR.avd");
|
||||
expect(list[0].target).toEqual("Android 7.1.1 (API level 25)");
|
||||
expect(list[0].abi).toEqual("google_apis/x86_64");
|
||||
expect(list[0].skin).toEqual("1080x1920");
|
||||
}).fail(function(err) {
|
||||
expect(list[0].name).toEqual('QWR');
|
||||
expect(list[0].device).toEqual('Nexus 5 (Google)');
|
||||
expect(list[0].path).toEqual('/Users/shazron/.android/avd/QWR.avd');
|
||||
expect(list[0].target).toEqual('Android 7.1.1 (API level 25)');
|
||||
expect(list[0].abi).toEqual('google_apis/x86_64');
|
||||
expect(list[0].skin).toEqual('1080x1920');
|
||||
}).fail(function (err) {
|
||||
expect(err).toBeUndefined();
|
||||
}).fin(function() {
|
||||
}).fin(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("list_images", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(fs, "realpathSync").and.callFake(function(cmd) {
|
||||
describe('list_images', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(fs, 'realpathSync').and.callFake(function (cmd) {
|
||||
return cmd;
|
||||
});
|
||||
});
|
||||
it("should try to parse AVD information using `avdmanager` first", function() {
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "avdmanager") {
|
||||
it('should try to parse AVD information using `avdmanager` first', function () {
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'avdmanager') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var avdmanager_spy = spyOn(emu, "list_images_using_avdmanager").and.returnValue({catch:function(){}});
|
||||
var avdmanager_spy = spyOn(emu, 'list_images_using_avdmanager').and.returnValue({catch: function () {}});
|
||||
emu.list_images();
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
});
|
||||
it("should delegate to `android` if `avdmanager` cant be found and `android` can", function() {
|
||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||
if (cmd == "avdmanager") {
|
||||
it('should delegate to `android` if `avdmanager` cant be found and `android` can', function () {
|
||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||
if (cmd === 'avdmanager') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
var android_spy = spyOn(emu, "list_images_using_android");
|
||||
var android_spy = spyOn(emu, 'list_images_using_android');
|
||||
emu.list_images();
|
||||
expect(android_spy).toHaveBeenCalled();
|
||||
});
|
||||
it("should throw an error if neither `avdmanager` nor `android` are able to be found", function(done) {
|
||||
spyOn(shelljs, "which").and.returnValue(false);
|
||||
return emu.list_images()
|
||||
.catch(function(err) {
|
||||
it('should throw an error if neither `avdmanager` nor `android` are able to be found', function (done) {
|
||||
spyOn(shelljs, 'which').and.returnValue(false);
|
||||
return emu.list_images().catch(function (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain("Could not find either `android` or `avdmanager`");
|
||||
expect(err.message).toContain('Could not find either `android` or `avdmanager`');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var rewire = require('rewire');
|
||||
var common = rewire('../../../bin/templates/cordova/lib/pluginHandlers');
|
||||
@@ -35,25 +36,25 @@ var copyFile = common.__get__('copyFile');
|
||||
var deleteJava = common.__get__('deleteJava');
|
||||
var copyNewFile = common.__get__('copyNewFile');
|
||||
|
||||
describe('common platform handler', function() {
|
||||
describe('common platform handler', function () {
|
||||
|
||||
describe('copyFile', function() {
|
||||
it('Test#001 : should throw if source path not found', function(){
|
||||
describe('copyFile', function () {
|
||||
it('Test#001 : should throw if source path not found', function () {
|
||||
shell.rm('-rf', src);
|
||||
expect(function(){copyFile(test_dir, src, project_dir, dest);})
|
||||
expect(function () { copyFile(test_dir, src, project_dir, dest); })
|
||||
.toThrow(new Error('"' + src + '" not found!'));
|
||||
});
|
||||
|
||||
it('Test#002 : should throw if src not in plugin directory', function(){
|
||||
it('Test#002 : should throw if src not in plugin directory', function () {
|
||||
shell.mkdir('-p', project_dir);
|
||||
fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
|
||||
var outside_file = '../non_plugin_file';
|
||||
expect(function(){copyFile(test_dir, outside_file, project_dir, dest);}).
|
||||
toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
expect(function () { copyFile(test_dir, outside_file, project_dir, dest); })
|
||||
.toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
shell.rm('-rf', test_dir);
|
||||
});
|
||||
|
||||
it('Test#003 : should allow symlink src, if inside plugin', function(){
|
||||
it('Test#003 : should allow symlink src, if inside plugin', function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
|
||||
@@ -66,7 +67,7 @@ describe('common platform handler', function() {
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
it('Test#004 : should throw if symlink is linked to a file outside the plugin', function(){
|
||||
it('Test#004 : should throw if symlink is linked to a file outside the plugin', function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
|
||||
|
||||
@@ -75,20 +76,20 @@ describe('common platform handler', function() {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(function(){copyFile(test_dir, symlink_file, project_dir, dest);}).
|
||||
toThrow(new Error('File "' + path.resolve(test_dir, symlink_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
expect(function () { copyFile(test_dir, symlink_file, project_dir, dest); })
|
||||
.toThrow(new Error('File "' + path.resolve(test_dir, symlink_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
it('Test#005 : should throw if dest is outside the project directory', function(){
|
||||
it('Test#005 : should throw if dest is outside the project directory', function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
expect(function(){copyFile(test_dir, java_file, project_dir, non_plugin_file);}).
|
||||
toThrow(new Error('Destination "' + path.resolve(project_dir, non_plugin_file) + '" for source file "' + path.resolve(test_dir, java_file) + '" is located outside the project'));
|
||||
expect(function () { copyFile(test_dir, java_file, project_dir, non_plugin_file); })
|
||||
.toThrow(new Error('Destination "' + path.resolve(project_dir, non_plugin_file) + '" for source file "' + path.resolve(test_dir, java_file) + '" is located outside the project'));
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
it('Test#006 : should call mkdir -p on target path', function(){
|
||||
it('Test#006 : should call mkdir -p on target path', function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
|
||||
@@ -102,7 +103,7 @@ describe('common platform handler', function() {
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
it('Test#007 : should call cp source/dest paths', function(){
|
||||
it('Test#007 : should call cp source/dest paths', function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
|
||||
@@ -119,46 +120,46 @@ describe('common platform handler', function() {
|
||||
});
|
||||
|
||||
describe('copyNewFile', function () {
|
||||
it('Test#008 : should throw if target path exists', function(){
|
||||
it('Test#008 : should throw if target path exists', function () {
|
||||
shell.mkdir('-p', dest);
|
||||
expect(function(){copyNewFile(test_dir, src, project_dir, dest);}).
|
||||
toThrow(new Error('"' + dest + '" already exists!'));
|
||||
expect(function () { copyNewFile(test_dir, src, project_dir, dest); })
|
||||
.toThrow(new Error('"' + dest + '" already exists!'));
|
||||
shell.rm('-rf', dest);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteJava', function() {
|
||||
beforeEach(function() {
|
||||
describe('deleteJava', function () {
|
||||
beforeEach(function () {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
shell.rm('-rf', java_dir);
|
||||
});
|
||||
|
||||
it('Test#009 : should call fs.unlinkSync on the provided paths', function(){
|
||||
it('Test#009 : should call fs.unlinkSync on the provided paths', function () {
|
||||
var s = spyOn(fs, 'unlinkSync').and.callThrough();
|
||||
deleteJava(project_dir, java_file);
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(path.resolve(project_dir, java_file));
|
||||
});
|
||||
|
||||
it('Test#010 : should delete empty directories after removing source code in a java src path hierarchy', function(){
|
||||
it('Test#010 : should delete empty directories after removing source code in a java src path hierarchy', function () {
|
||||
deleteJava(project_dir, java_file);
|
||||
expect(fs.existsSync(java_file)).not.toBe(true);
|
||||
expect(fs.existsSync(java_dir)).not.toBe(true);
|
||||
expect(fs.existsSync(path.join(src,'one'))).not.toBe(true);
|
||||
expect(fs.existsSync(path.join(src, 'one'))).not.toBe(true);
|
||||
});
|
||||
|
||||
it('Test#011 : should never delete the top-level src directory, even if all plugins added were removed', function(){
|
||||
it('Test#011 : should never delete the top-level src directory, even if all plugins added were removed', function () {
|
||||
deleteJava(project_dir, java_file);
|
||||
expect(fs.existsSync(src)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function ignoreEPERMonWin32(symlink_src, symlink_dest) {
|
||||
function ignoreEPERMonWin32 (symlink_src, symlink_dest) {
|
||||
try {
|
||||
fs.symlinkSync(symlink_src, symlink_dest);
|
||||
} catch (e) {
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var rewire = require('rewire');
|
||||
var common = rewire('../../../bin/templates/cordova/lib/pluginHandlers');
|
||||
var common = rewire('../../../bin/templates/cordova/lib/pluginHandlers');
|
||||
var android = common.__get__('handlers');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var shell = require('shelljs');
|
||||
var os = require('os');
|
||||
var temp = path.join(os.tmpdir(), 'plugman');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var shell = require('shelljs');
|
||||
var os = require('os');
|
||||
var temp = path.join(os.tmpdir(), 'plugman');
|
||||
var plugins_dir = path.join(temp, 'cordova/plugins');
|
||||
var dummyplugin = path.join(__dirname, '../../fixtures/org.test.plugins.dummyplugin');
|
||||
var faultyplugin = path.join(__dirname, '../../fixtures/org.test.plugins.faultyplugin');
|
||||
@@ -34,32 +35,32 @@ var PluginInfo = require('cordova-common').PluginInfo;
|
||||
var AndroidProject = require('../../../bin/templates/cordova/lib/AndroidProject');
|
||||
|
||||
var dummyPluginInfo = new PluginInfo(dummyplugin);
|
||||
var valid_source = dummyPluginInfo.getSourceFiles('android'),
|
||||
valid_resources = dummyPluginInfo.getResourceFiles('android'),
|
||||
valid_libs = dummyPluginInfo.getLibFiles('android');
|
||||
var valid_source = dummyPluginInfo.getSourceFiles('android');
|
||||
var valid_resources = dummyPluginInfo.getResourceFiles('android');
|
||||
var valid_libs = dummyPluginInfo.getLibFiles('android');
|
||||
|
||||
var faultyPluginInfo = new PluginInfo(faultyplugin);
|
||||
var invalid_source = faultyPluginInfo.getSourceFiles('android');
|
||||
|
||||
describe('android project handler', function() {
|
||||
describe('installation', function() {
|
||||
describe('android project handler', function () {
|
||||
describe('installation', function () {
|
||||
var copyFileOrig = common.__get__('copyFile');
|
||||
var copyFileSpy = jasmine.createSpy('copyFile');
|
||||
var dummyProject;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
shell.mkdir('-p', temp);
|
||||
dummyProject = AndroidProject.getProjectFile(temp);
|
||||
copyFileSpy.calls.reset();
|
||||
common.__set__('copyFile', copyFileSpy);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
shell.rm('-rf', temp);
|
||||
common.__set__('copyFile', copyFileOrig);
|
||||
});
|
||||
|
||||
describe('of <lib-file> elements', function() {
|
||||
describe('of <lib-file> elements', function () {
|
||||
it('Test#001 : should copy files', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/TestLib.jar', temp, path.join('libs', 'TestLib.jar'), false);
|
||||
@@ -70,58 +71,58 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <resource-file> elements', function() {
|
||||
describe('of <resource-file> elements', function () {
|
||||
it('Test#003 : should copy files', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'android-resource.xml', temp, path.join('res', 'xml', 'dummy.xml'), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <source-file> elements', function() {
|
||||
beforeEach(function() {
|
||||
describe('of <source-file> elements', function () {
|
||||
beforeEach(function () {
|
||||
shell.cp('-rf', android_project, temp);
|
||||
});
|
||||
|
||||
it('Test#004 : should copy stuff from one location to another by calling common.copyFile', function() {
|
||||
it('Test#004 : 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#005 : should install source files to the right location for Android Studio projects', function() {
|
||||
it('Test#005 : 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);
|
||||
});
|
||||
|
||||
it('Test#006 : should throw if source file cannot be found', function() {
|
||||
it('Test#006 : should throw if source file cannot be found', function () {
|
||||
common.__set__('copyFile', copyFileOrig);
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
android['source-file'].install(invalid_source[0], faultyPluginInfo, dummyProject);
|
||||
}).toThrow(new Error('"' + path.resolve(faultyplugin, 'src/android/NotHere.java') + '" not found!'));
|
||||
});
|
||||
|
||||
it('Test#007 : should throw if target file already exists', function() {
|
||||
it('Test#007 : should throw if target file already exists', function () {
|
||||
// write out a file
|
||||
var target = path.resolve(temp, 'src/com/phonegap/plugins/dummyplugin');
|
||||
shell.mkdir('-p', target);
|
||||
target = path.join(target, 'DummyPlugin.java');
|
||||
fs.writeFileSync(target, 'some bs', 'utf-8');
|
||||
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
}).toThrow(new Error ('"' + target + '" already exists!'));
|
||||
}).toThrow(new Error('"' + target + '" already exists!'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <framework> elements', function() {
|
||||
describe('of <framework> elements', function () {
|
||||
|
||||
var someString = jasmine.any(String);
|
||||
|
||||
var copyNewFileOrig = common.__get__('copyNewFile');
|
||||
var copyNewFileSpy = jasmine.createSpy('copyNewFile');
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
shell.cp('-rf', android_project, temp);
|
||||
|
||||
spyOn(dummyProject, 'addSystemLibrary');
|
||||
@@ -130,27 +131,27 @@ describe('android project handler', function() {
|
||||
common.__set__('copyNewFile', copyNewFileSpy);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
common.__set__('copyNewFile', copyNewFileOrig);
|
||||
});
|
||||
|
||||
it('Test#008 : should throw if framework doesn\'t have "src" attribute', function() {
|
||||
expect(function() { android.framework.install({}, dummyPluginInfo, dummyProject); }).toThrow();
|
||||
it('Test#008 : should throw if framework doesn\'t have "src" attribute', function () {
|
||||
expect(function () { android.framework.install({}, dummyPluginInfo, dummyProject); }).toThrow();
|
||||
});
|
||||
|
||||
it('Test#009 : should install framework without "parent" attribute into project root', function() {
|
||||
it('Test#009 : should install framework without "parent" attribute into project root', function () {
|
||||
var framework = {src: 'plugin-lib'};
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.addSystemLibrary).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
});
|
||||
|
||||
it('Test#010 : should install framework with "parent" attribute into parent framework dir', function() {
|
||||
it('Test#010 : should install framework with "parent" attribute into parent framework dir', function () {
|
||||
var childFramework = {src: 'plugin-lib2', parent: 'plugin-lib'};
|
||||
android.framework.install(childFramework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.addSystemLibrary).toHaveBeenCalledWith(path.resolve(dummyProject.projectDir, childFramework.parent), someString);
|
||||
});
|
||||
|
||||
it('Test#011 : should not copy anything if "custom" attribute is not set', function() {
|
||||
it('Test#011 : should not copy anything if "custom" attribute is not set', function () {
|
||||
var framework = {src: 'plugin-lib'};
|
||||
var cpSpy = spyOn(shell, 'cp');
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
@@ -158,14 +159,14 @@ describe('android project handler', function() {
|
||||
expect(cpSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('Test#012 : should copy framework sources if "custom" attribute is set', function() {
|
||||
it('Test#012 : should copy framework sources if "custom" attribute is set', function () {
|
||||
var framework = {src: 'plugin-lib', custom: true};
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.addSubProject).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
expect(copyNewFileSpy).toHaveBeenCalledWith(dummyPluginInfo.dir, framework.src, dummyProject.projectDir, someString, false);
|
||||
});
|
||||
|
||||
it('Test#013 : should install gradleReference using project.addGradleReference', function() {
|
||||
it('Test#013 : should install gradleReference using project.addGradleReference', function () {
|
||||
var framework = {src: 'plugin-lib', custom: true, type: 'gradleReference'};
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
expect(copyNewFileSpy).toHaveBeenCalledWith(dummyPluginInfo.dir, framework.src, dummyProject.projectDir, someString, false);
|
||||
@@ -173,7 +174,7 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <js-module> elements', function() {
|
||||
describe('of <js-module> elements', function () {
|
||||
var jsModule = {src: 'www/dummyplugin.js'};
|
||||
var wwwDest, platformWwwDest;
|
||||
|
||||
@@ -196,9 +197,10 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <asset> elements', function() {
|
||||
describe('of <asset> elements', function () {
|
||||
var asset = {src: 'www/dummyPlugin.js', target: 'foo/dummy.js'};
|
||||
var wwwDest, platformWwwDest;
|
||||
var wwwDest; /* eslint no-unused-vars: "off" */
|
||||
var platformWwwDest; /* eslint no-unused-vars: "off" */
|
||||
|
||||
beforeEach(function () {
|
||||
wwwDest = path.resolve(dummyProject.www, asset.target);
|
||||
@@ -219,7 +221,7 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('uninstallation', function() {
|
||||
describe('uninstallation', function () {
|
||||
|
||||
var removeFileOrig = common.__get__('removeFile');
|
||||
var deleteJavaOrig = common.__get__('deleteJava');
|
||||
@@ -228,7 +230,7 @@ describe('android project handler', function() {
|
||||
var deleteJavaSpy = jasmine.createSpy('deleteJava');
|
||||
var dummyProject;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
shell.mkdir('-p', temp);
|
||||
shell.mkdir('-p', plugins_dir);
|
||||
shell.cp('-rf', android_project, temp);
|
||||
@@ -238,26 +240,26 @@ describe('android project handler', function() {
|
||||
common.__set__('deleteJava', deleteJavaSpy);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
shell.rm('-rf', temp);
|
||||
common.__set__('removeFile', removeFileOrig);
|
||||
common.__set__('deleteJava', deleteJavaOrig);
|
||||
});
|
||||
|
||||
describe('of <lib-file> elements', function() {
|
||||
describe('of <lib-file> elements', function () {
|
||||
it('Test#018 : should remove jar files', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('libs/TestLib.jar'));
|
||||
});
|
||||
it('Test#019 : 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_studio: true});
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestLib.jar'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <resource-file> elements', function() {
|
||||
describe('of <resource-file> elements', function () {
|
||||
it('Test#020 : should remove files', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
android['resource-file'].uninstall(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
@@ -265,24 +267,24 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <source-file> elements', function() {
|
||||
it('Test#021 : should remove stuff by calling common.deleteJava', function() {
|
||||
describe('of <source-file> elements', function () {
|
||||
it('Test#021 : should remove stuff by calling common.deleteJava', function () {
|
||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
android['source-file'].uninstall(valid_source[0], dummyPluginInfo, dummyProject);
|
||||
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('src/com/phonegap/plugins/dummyplugin/DummyPlugin.java'));
|
||||
});
|
||||
it('Test#022 : 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});
|
||||
it('Test#022 : 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});
|
||||
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <framework> elements', function() {
|
||||
describe('of <framework> elements', function () {
|
||||
|
||||
var someString = jasmine.any(String);
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
shell.mkdir(path.join(dummyProject.projectDir, dummyPluginInfo.id));
|
||||
|
||||
spyOn(dummyProject, 'removeSystemLibrary');
|
||||
@@ -290,30 +292,30 @@ describe('android project handler', function() {
|
||||
spyOn(dummyProject, 'removeGradleReference');
|
||||
});
|
||||
|
||||
it('Test#023 : should throw if framework doesn\'t have "src" attribute', function() {
|
||||
expect(function() { android.framework.uninstall({}, dummyPluginInfo, dummyProject); }).toThrow();
|
||||
it('Test#023 : should throw if framework doesn\'t have "src" attribute', function () {
|
||||
expect(function () { android.framework.uninstall({}, dummyPluginInfo, dummyProject); }).toThrow();
|
||||
});
|
||||
|
||||
it('Test#024 : should uninstall framework without "parent" attribute into project root', function() {
|
||||
it('Test#024 : should uninstall framework without "parent" attribute into project root', function () {
|
||||
var framework = {src: 'plugin-lib'};
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.removeSystemLibrary).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
});
|
||||
|
||||
it('Test#025 : should uninstall framework with "parent" attribute into parent framework dir', function() {
|
||||
it('Test#025 : should uninstall framework with "parent" attribute into parent framework dir', function () {
|
||||
var childFramework = {src: 'plugin-lib2', parent: 'plugin-lib'};
|
||||
android.framework.uninstall(childFramework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.removeSystemLibrary).toHaveBeenCalledWith(path.resolve(dummyProject.projectDir, childFramework.parent), someString);
|
||||
});
|
||||
|
||||
it('Test#026 : should remove framework sources if "custom" attribute is set', function() {
|
||||
it('Test#026 : should remove framework sources if "custom" attribute is set', function () {
|
||||
var framework = {src: 'plugin-lib', custom: true};
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.removeSubProject).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
});
|
||||
|
||||
it('Test#27 : should install gradleReference using project.removeGradleReference', function() {
|
||||
it('Test#27 : should install gradleReference using project.removeGradleReference', function () {
|
||||
var framework = {src: 'plugin-lib', custom: true, type: 'gradleReference'};
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(removeFileSpy).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
@@ -321,10 +323,10 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('of <js-module> elements', function() {
|
||||
describe('of <js-module> elements', function () {
|
||||
var jsModule = {src: 'www/dummyPlugin.js'};
|
||||
var wwwDest, platformWwwDest;
|
||||
var wwwDest;
|
||||
var platformWwwDest;
|
||||
|
||||
beforeEach(function () {
|
||||
wwwDest = path.resolve(dummyProject.www, 'plugins', dummyPluginInfo.id, jsModule.src);
|
||||
@@ -334,7 +336,7 @@ describe('android project handler', function() {
|
||||
|
||||
var existsSyncOrig = fs.existsSync;
|
||||
spyOn(fs, 'existsSync').and.callFake(function (file) {
|
||||
if ([wwwDest, platformWwwDest].indexOf(file) >= 0 ) return true;
|
||||
if ([wwwDest, platformWwwDest].indexOf(file) >= 0) return true;
|
||||
return existsSyncOrig.call(fs, file);
|
||||
});
|
||||
});
|
||||
@@ -352,7 +354,7 @@ describe('android project handler', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <asset> elements', function() {
|
||||
describe('of <asset> elements', function () {
|
||||
var asset = {src: 'www/dummyPlugin.js', target: 'foo/dummy.js'};
|
||||
var wwwDest, platformWwwDest;
|
||||
|
||||
@@ -364,7 +366,7 @@ describe('android project handler', function() {
|
||||
|
||||
var existsSyncOrig = fs.existsSync;
|
||||
spyOn(fs, 'existsSync').and.callFake(function (file) {
|
||||
if ([wwwDest, platformWwwDest].indexOf(file) >= 0 ) return true;
|
||||
if ([wwwDest, platformWwwDest].indexOf(file) >= 0) return true;
|
||||
return existsSyncOrig.call(fs, file);
|
||||
});
|
||||
});
|
||||
|
||||
+16
-15
@@ -16,23 +16,24 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint-env jasmine */
|
||||
|
||||
var rewire = require("rewire");
|
||||
var run = rewire("../../bin/templates/cordova/lib/run");
|
||||
var getInstallTarget = run.__get__("getInstallTarget");
|
||||
var rewire = require('rewire');
|
||||
var run = rewire('../../bin/templates/cordova/lib/run');
|
||||
var getInstallTarget = run.__get__('getInstallTarget');
|
||||
|
||||
describe("run", function () {
|
||||
describe("getInstallTarget", function() {
|
||||
var targetOpts = { target: "emu" };
|
||||
var deviceOpts = { device: true };
|
||||
var emulatorOpts = { emulator: true };
|
||||
var emptyOpts = {};
|
||||
describe('run', function () {
|
||||
describe('getInstallTarget', function () {
|
||||
var targetOpts = { target: 'emu' };
|
||||
var deviceOpts = { device: true };
|
||||
var emulatorOpts = { emulator: true };
|
||||
var emptyOpts = {};
|
||||
|
||||
it("Test#001 : should select correct target based on the run opts", function() {
|
||||
expect(getInstallTarget(targetOpts)).toBe("emu");
|
||||
expect(getInstallTarget(deviceOpts)).toBe("--device");
|
||||
expect(getInstallTarget(emulatorOpts)).toBe("--emulator");
|
||||
expect(getInstallTarget(emptyOpts)).toBeUndefined();
|
||||
it('Test#001 : should select correct target based on the run opts', function () {
|
||||
expect(getInstallTarget(targetOpts)).toBe('emu');
|
||||
expect(getInstallTarget(deviceOpts)).toBe('--device');
|
||||
expect(getInstallTarget(emulatorOpts)).toBe('--emulator');
|
||||
expect(getInstallTarget(emptyOpts)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user