From bb141a70e89cf7826fb1699085df33aac597a688 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Tue, 24 Jun 2014 13:50:00 -0400 Subject: [PATCH] CB-5971: Add unit tests to cordova-android --- bin/lib/create.js | 4 +++ package.json | 7 ++++ spec/create.spec.js | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 spec/create.spec.js diff --git a/bin/lib/create.js b/bin/lib/create.js index 8a908276..a31604a4 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -288,3 +288,7 @@ exports.updateProject = function(projectPath) { }); }; + +// For testing +exports.validatePackageName = validatePackageName; +exports.validateProjectName = validateProjectName; diff --git a/package.json b/package.json index 0d203c92..ed01458a 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,17 @@ "cordova", "apache" ], + "scripts": { + "test": "jasmine-node --color spec" + }, "author": "Apache Software Foundation", "license": "Apache version 2.0", "dependencies": { "q": "^0.9.0", "shelljs": "^0.2.6" + }, + "devDependencies": { + "jasmine-node": "~1", + "promise-matchers": "~0" } } diff --git a/spec/create.spec.js b/spec/create.spec.js new file mode 100644 index 00000000..8e08793f --- /dev/null +++ b/spec/create.spec.js @@ -0,0 +1,82 @@ +/** + 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. +*/ +/* jshint laxcomma:true */ + +require("promise-matchers"); + +var create = require("../bin/lib/create"); + +describe("create", function () { + describe("validatePackageName", function() { + var valid = [ + "org.apache.mobilespec" + , "com.example" + , "com.42floors.package" + ]; + 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" + ]; + + valid.forEach(function(package_name) { + it("should accept " + package_name, function(done) { + expect(create.validatePackageName(package_name)).toHaveBeenResolved(done); + }); + }); + + invalid.forEach(function(package_name) { + it("should reject " + package_name, function(done) { + expect(create.validatePackageName(package_name)).toHaveBeenRejected(done); + }); + }); + }); + describe("validateProjectName", function() { + var valid = [ + "mobilespec" + , "package_name" + , "PackageName" + , "CordovaLib" + ]; + var invalid = [ + "" + , "0startswithdigit" + , "CordovaActivity" + ]; + + valid.forEach(function(project_name) { + it("should accept " + project_name, function(done) { + expect(create.validateProjectName(project_name)).toHaveBeenResolved(done); + }); + }); + + invalid.forEach(function(project_name) { + it("should reject " + project_name, function(done) { + expect(create.validateProjectName(project_name)).toHaveBeenRejected(done); + }); + }); + }); +});