You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2017/04/07 19:40:52 UTC
[03/13] cordova-test-platform git commit: added basic api and tests
added basic api and tests
Project: http://git-wip-us.apache.org/repos/asf/cordova-test-platform/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-test-platform/commit/a8bcff08
Tree: http://git-wip-us.apache.org/repos/asf/cordova-test-platform/tree/a8bcff08
Diff: http://git-wip-us.apache.org/repos/asf/cordova-test-platform/diff/a8bcff08
Branch: refs/heads/master
Commit: a8bcff08aecd3b4fb5a6275f9eb2691ea8338128
Parents: b7bdc91
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Mar 31 23:13:02 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Mar 31 23:13:02 2017 -0700
----------------------------------------------------------------------
package.json | 9 ++-
spec/create.spec.js | 104 +++++++++++++++++++++++++++++++
spec/projectApi.spec.js | 136 +++++++++++++++++++++++++++++++++++++++++
spec/support/jasmine.json | 10 +++
src/Api.js | 123 +++++++++++++++++++++++++++++++++++++
src/bin/create | 74 ++++++++++++++++++++++
6 files changed, 454 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4dc5dd0..7a5028d 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
"scripts": {
"cover": "istanbul cover --root bin/templates/cordova --print detail jasmine",
"jshint": "jshint src && jshint spec",
- "test": "npm run jshint && jasmine"
+ "jasmine": "jasmine --captureExceptions --color",
+ "test": "npm run jshint && npm run jasmine"
},
"repository": {
"type": "git",
@@ -34,7 +35,11 @@
"email": "purplecabbage@apache.org"
}
],
- "dependencies": {},
+ "dependencies": {
+ "cordova-common": "^2.0.1",
+ "nopt": "^4.0.1",
+ "shelljs": "^0.3.0"
+ },
"devDependencies": {
"jasmine": "^2.5.3",
"jshint": "^2.9.4"
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
new file mode 100644
index 0000000..b59b8c6
--- /dev/null
+++ b/spec/create.spec.js
@@ -0,0 +1,104 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+var shell = require('shelljs'),
+ spec = __dirname,
+ path = require('path'),
+ util = require('util');
+
+var cordova_bin = path.join(spec, '../src/bin');
+var tmpDir = path.join(__dirname, '../temp');
+
+function createAndBuild(projectname, projectid) {
+ var return_code = 0;
+ var command;
+
+ // remove existing folder
+ //command = path.join(tmpDir, projectname);
+ shell.rm('-rf', tmpDir);
+ shell.mkdir(tmpDir);
+
+
+ // create the project
+ command = util.format('"%s/create" "%s/%s" "%s" "%s"', cordova_bin, tmpDir, projectname, projectid, projectname);
+
+ //console.log("command = " + command);
+
+ // shell.echo(command);
+ return_code = shell.exec(command).code;
+ expect(return_code).toBe(0);
+
+ // // build the project
+ // command = util.format('"%s/cordova/build"', path.join(tmpDir, projectname));
+ // //shell.echo(command);
+ // return_code = shell.exec(command, { silent: true }).code;
+ // expect(return_code).toBe(0);
+
+ // clean-up
+ command = path.join(tmpDir, projectname);
+ shell.rm('-rf', command);
+}
+
+
+describe('create', function() {
+
+ it('create project with ascii name, no spaces', function() {
+ var projectname = 'testcreate';
+ var projectid = 'com.test.app1';
+
+ createAndBuild(projectname, projectid);
+ });
+
+ it('create project with ascii name, and spaces', function() {
+ var projectname = 'test create';
+ var projectid = 'com.test.app2';
+
+ createAndBuild(projectname, projectid);
+ });
+
+ it('create project with unicode name, no spaces', function() {
+ var projectname = '\u5fdc\u5fdc\u5fdc\u5fdc\u7528\u7528\u7528\u7528';
+ var projectid = 'com.test.app3';
+
+ createAndBuild(projectname, projectid);
+ });
+
+ it('create project with unicode name, and spaces', function() {
+ var projectname = '\u5fdc\u5fdc\u5fdc\u5fdc \u7528\u7528\u7528\u7528';
+ var projectid = 'com.test.app4';
+
+ createAndBuild(projectname, projectid);
+ });
+
+ it('create project with ascii+unicode name, no spaces', function() {
+ var projectname = '\u5fdc\u5fdc\u5fdc\u5fdchello\u7528\u7528\u7528\u7528';
+ var projectid = 'com.test.app5';
+
+ createAndBuild(projectname, projectid);
+ });
+
+ it('create project with ascii+unicode name, and spaces', function() {
+ var projectname = '\u5fdc\u5fdc\u5fdc\u5fdc hello \u7528\u7528\u7528\u7528';
+ var projectid = 'com.test.app6';
+
+ createAndBuild(projectname, projectid);
+ });
+
+});
+
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/spec/projectApi.spec.js
----------------------------------------------------------------------
diff --git a/spec/projectApi.spec.js b/spec/projectApi.spec.js
new file mode 100644
index 0000000..f05475e
--- /dev/null
+++ b/spec/projectApi.spec.js
@@ -0,0 +1,136 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+var Api = require("../src/Api");
+
+describe('can get the Api', function() {
+
+ it('should be defined', function() {
+ expect(Api).toBeDefined();
+ });
+
+ it('should export static createPlatform function', function(done) {
+ expect(Api.createPlatform).toBeDefined();
+ expect(typeof Api.createPlatform).toBe('function');
+
+// TODO: make this do something real
+ var promise = Api.createPlatform("../tmp");
+ expect(promise).toBeDefined();
+ expect(promise.then).toBeDefined();
+ promise.then(function(res) {
+ console.log('result = ' + res);
+ console.log("spec-success");
+ done();
+ },
+ function(err) {
+ console.log("spec-error " + err);
+ done();
+ });
+ });
+
+ it('should export static updatePlatform function', function() {
+ expect(Api.updatePlatform).toBeDefined();
+ expect(typeof Api.updatePlatform).toBe('function');
+ });
+
+});
+
+describe('project level Api',function() {
+
+ var testApi = new Api();
+
+ it('can be created', function() {
+ expect(testApi).toBeDefined();
+ });
+
+ it('has a requirements method', function() {
+ expect(testApi.requirements).toBeDefined();
+ expect(typeof testApi.requirements).toBe('function');
+ });
+
+ it('has a clean method', function() {
+ expect(testApi.clean).toBeDefined();
+ expect(typeof testApi.clean).toBe('function');
+ });
+
+ it('has a run method', function() {
+ expect(testApi.run).toBeDefined();
+ expect(typeof testApi.run).toBe('function');
+ });
+
+ it('has a build method', function() {
+ expect(testApi.build).toBeDefined();
+ expect(typeof testApi.build).toBe('function');
+ });
+
+ it('has a removePlugin method', function() {
+ expect(testApi.removePlugin).toBeDefined();
+ expect(typeof testApi.removePlugin).toBe('function');
+ });
+
+ it('has a addPlugin method', function() {
+ expect(testApi.addPlugin).toBeDefined();
+ expect(typeof testApi.addPlugin).toBe('function');
+ });
+
+ it('has a prepare method', function() {
+ expect(testApi.prepare).toBeDefined();
+ expect(typeof testApi.prepare).toBe('function');
+ });
+
+ it('has a getPlatformInfo method', function() {
+ expect(testApi.getPlatformInfo).toBeDefined();
+ expect(typeof testApi.getPlatformInfo).toBe('function');
+ });
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+});
+
+// Static methods
+// Static method: createPlatform
+ // returns promise fulfilled with Api
+ // emits error using provided emmitter on error
+
+// Static method: updatePlatform
+ // returns a promise fulfilled with an Api
+ // emits error using provided emmitter on error
+ //
+
+// Instance methods
+ // requirements, clean, run, build, removePlugin, addPlugin, prepare, getPlatformInfo
+
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/spec/support/jasmine.json
----------------------------------------------------------------------
diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json
new file mode 100644
index 0000000..7122dfd
--- /dev/null
+++ b/spec/support/jasmine.json
@@ -0,0 +1,10 @@
+{
+ "spec_dir": "spec",
+ "spec_files": [
+ "*[sS]pec.js"
+ ],
+ "helpers": [
+ ],
+ "stopSpecOnExpectationFailure": false,
+ "random": false
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/src/Api.js
----------------------------------------------------------------------
diff --git a/src/Api.js b/src/Api.js
new file mode 100644
index 0000000..bbafde7
--- /dev/null
+++ b/src/Api.js
@@ -0,0 +1,123 @@
+/*
+ this file is found by cordova-lib when you attempt to
+ 'cordova platform add PATH' where path is this repo.
+*/
+
+/*jslint node: true */
+
+var shell = require('shelljs');
+var path = require('path');
+
+var PLATFORM_NAME = 'testplatform';
+
+function setupEvents(externalEventEmitter) {
+ if (externalEventEmitter) {
+ // This will make the platform internal events visible outside
+ selfEvents.forwardEventsTo(externalEventEmitter);
+ return externalEventEmitter;
+ }
+
+ // There is no logger if external emitter is not present,
+ // so attach a console logger
+ CordovaLogger.get().subscribe(selfEvents);
+ return selfEvents;
+}
+
+function Api(platform, platformRootDir, events) {
+
+ this.platform = platform || PLATFORM_NAME;
+ this.root = path.resolve(__dirname, '..');
+
+ this.locations = {
+ platformRootDir: platformRootDir,
+ root: this.root,
+ www: path.join(this.root, 'assets/www'),
+ res: path.join(this.root, 'res'),
+ platformWww: path.join(this.root, 'platform_www'),
+ configXml: path.join(this.root, 'res/xml/config.xml'),
+ defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'),
+ build: path.join(this.root, 'build'),
+ // NOTE: Due to platformApi spec we need to return relative paths here
+ cordovaJs: 'bin/templates/project/assets/www/cordova.js',
+ cordovaJsSrc: 'cordova-js-src'
+ };
+
+}
+
+Api.createPlatform = function (destination, config, options, events) {
+
+ // create the destination and the standard place for our api to live
+ // platforms/platformName/cordova/Api.js
+ shell.mkdir(destination);
+ shell.mkdir(path.join(destination,'cordova'));
+
+ var apiPath = path.join(__dirname, 'Api.js'); // default value
+ // does options contain the info we desire?
+ if(options && options.platformDetails) {
+ apiPath = path.join(options.platformDetails.libDir, 'src/Api.js');
+ }
+ // move a copy of our api to the new project
+ shell.cp(apiPath, path.join(destination, 'cordova/Api.js'));
+
+ var result = Promise.resolve();
+ result.then(function(){
+ return new Api(PLATFORM_NAME,destination,events);
+ });
+ return result;
+};
+
+
+Api.updatePlatform = function (destination, options, events) {
+ // console.log("test-platform:Api:updatePlatform");
+ // todo?: create projectInstance and fulfill promise with it.
+ return Promise.resolve();
+};
+
+Api.prototype.getPlatformInfo = function () {
+ console.log("test-platform:Api:getPlatformInfo");
+ // return PlatformInfo object
+
+ return {
+ "locations":this.locations,
+ "root": this.root,
+ "name": this.platform,
+ "version": { "version" : "1.0.0" },
+ "projectConfig": this._config
+ };
+};
+
+Api.prototype.prepare = function (cordovaProject) {
+ console.log("test-platform:Api:prepare");
+ return Promise.resolve();
+};
+
+Api.prototype.addPlugin = function (plugin, installOptions) {
+ console.log("test-platform:Api:addPlugin");
+ return Promise.resolve();
+};
+
+Api.prototype.removePlugin = function (plugin, uninstallOptions) {
+ console.log("test-platform:Api:removePlugin");
+ return Promise.resolve();
+};
+
+Api.prototype.build = function (buildOptions) {
+ console.log("test-platform:Api:build");
+ return Promise.resolve();
+};
+
+Api.prototype.run = function(runOptions) {
+ console.log("test-platform:Api:run");
+};
+
+Api.prototype.clean = function(cleanOptions) {
+ console.log("test-platform:Api:clean");
+ return Promise.resolve();
+};
+
+Api.prototype.requirements = function() {
+ console.log("test-platform:Api:requirements");
+ return true;
+};
+
+module.exports = Api;
http://git-wip-us.apache.org/repos/asf/cordova-test-platform/blob/a8bcff08/src/bin/create
----------------------------------------------------------------------
diff --git a/src/bin/create b/src/bin/create
new file mode 100755
index 0000000..77bc7e2
--- /dev/null
+++ b/src/bin/create
@@ -0,0 +1,74 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+/*
+ * create a Cordova project
+ *
+ * USAGE
+ * ./create <path_to_new_project> <package_name> <project_name>
+ *
+ * EXAMPLE
+ * ./create ~/Desktop/radness org.apache.cordova.radness Radness
+ */
+
+var path = require('path');
+var ConfigParser = require('cordova-common').ConfigParser;
+var Api = require('../Api');
+
+var argv = require('nopt')({
+ 'help' : Boolean,
+ 'cli' : Boolean,
+ 'shared' : Boolean, // alias for --link
+ 'link' : Boolean
+}, { 'd' : '--verbose' });
+
+var projectPath = argv.argv.remain[0];
+
+if (argv.help || !projectPath) {
+ console.log('Usage: $0 [--link] [--cli] <path_to_new_project> <package_name> <project_name> [<project_template_dir>]');
+ console.log(' --link (optional): Link directly against the shared copy of the CordovaLib instead of a copy of it.');
+ console.log(' --cli (optional): Use the CLI-project template.');
+ console.log(' <path_to_new_project>: Path to your new Cordova iOS project');
+ console.log(' <package_name>: Package name, following reverse-domain style convention');
+ console.log(' <project_name>: Project name');
+ console.log(' <project_template_dir>: Path to project template (override).');
+ process.exit(0);
+}
+else {
+ var config = {};
+
+ // apply overrides (package and project names
+ // if (argv.argv.remain[1]) {
+ // config.setPackageName(argv.argv.remain[1]);
+ // }
+ // if (argv.argv.remain[2]) {
+ // config.setName(argv.argv.remain[2]);
+ // }
+
+ var options = {
+ cli: argv.cli,
+ link: argv.link || argv.shared,
+ customTemplate: argv.argv.remain[3],
+ };
+
+ Api.createPlatform(projectPath, config, options);
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org