Skip to content
Permalink
Browse files
added basic api and tests
  • Loading branch information
purplecabbage committed Apr 1, 2017
1 parent b7bdc91 commit a8bcff08aecd3b4fb5a6275f9eb2691ea8338128
Showing 6 changed files with 454 additions and 2 deletions.
@@ -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"
@@ -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 = '応応応応用用用用';
var projectid = 'com.test.app3';

createAndBuild(projectname, projectid);
});

it('create project with unicode name, and spaces', function() {
var projectname = '応応応応 用用用用';
var projectid = 'com.test.app4';

createAndBuild(projectname, projectid);
});

it('create project with ascii+unicode name, no spaces', function() {
var projectname = '応応応応hello用用用用';
var projectid = 'com.test.app5';

createAndBuild(projectname, projectid);
});

it('create project with ascii+unicode name, and spaces', function() {
var projectname = '応応応応 hello 用用用用';
var projectid = 'com.test.app6';

createAndBuild(projectname, projectid);
});

});

@@ -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

@@ -0,0 +1,10 @@
{
"spec_dir": "spec",
"spec_files": [
"*[sS]pec.js"
],
"helpers": [
],
"stopSpecOnExpectationFailure": false,
"random": false
}

0 comments on commit a8bcff0

Please sign in to comment.