Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0D4B51016E for ; Wed, 27 Nov 2013 18:33:38 +0000 (UTC) Received: (qmail 17507 invoked by uid 500); 27 Nov 2013 18:33:17 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 17455 invoked by uid 500); 27 Nov 2013 18:33:15 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 16682 invoked by uid 99); 27 Nov 2013 18:33:07 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Nov 2013 18:33:07 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 830E090EB16; Wed, 27 Nov 2013 18:33:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mmocny@apache.org To: commits@cordova.apache.org Date: Wed, 27 Nov 2013 18:33:13 -0000 Message-Id: <372f239161024c6c93a1cb881951d5ea@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [08/12] git commit: Add test for "create" command. Add test for "create" command. Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/6ca954be Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/6ca954be Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/6ca954be Branch: refs/heads/master Commit: 6ca954be8565a2c09b13116805883977590147bc Parents: bcfec84 Author: Mark Koudritsky Authored: Mon Nov 11 17:00:47 2013 -0500 Committer: Mark Koudritsky Committed: Mon Nov 11 17:49:47 2013 -0500 ---------------------------------------------------------------------- e2e/create.spec.js | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6ca954be/e2e/create.spec.js ---------------------------------------------------------------------- diff --git a/e2e/create.spec.js b/e2e/create.spec.js new file mode 100644 index 0000000..9f8def4 --- /dev/null +++ b/e2e/create.spec.js @@ -0,0 +1,101 @@ +var helpers = require('./helpers'), + path = require('path'), + fs = require('fs'), + shell = require('shelljs'), + Q = require('q'), + config = require('../src/config'), + events = require('../src/events'), + util = require('../src/util'), + cordova = require('../cordova'); + + +// TODO (kamrik): what's the right place for such utility funcs? Is this an ok way to do this in JS? +// crossConcat(['x', 'y'], ['1', '2', '3']) +// -> [ 'x1', 'x2', 'x3', 'y1', 'y2', 'y3'] +var crossConcat = function(a, b, delimiter){ + var result = []; + if (typeof delimiter == 'undefined') { + delimiter = ''; + } + for (var i = 0; i < a.length; i++) { + for (var j = 0; j < b.length; j++) { + result.push(a[i] + delimiter + b[j]); + } + } + return result; +}; + + +var tmpDir = helpers.tmpDir(); +var appName = 'TestCreate'; +var appId = 'io.cordova.' + appName.toLocaleLowerCase(); +var project = path.join(tmpDir, appName); +var cordovaDir = path.join(project, '.cordova'); +var extraConfig = { + lib: { + www: { + uri: path.join(__dirname, 'fixtures', 'base', 'www'), + version: "testCordovaCreate", + id: appName + } + } + }; + +describe('create end-to-end', function() { + + beforeEach(function() { + shell.rm('-rf', path.join(tmpDir, '*')); + }); + afterEach(function() { + shell.rm('-rf', path.join(tmpDir, '*')); + }); + + var results; + events.on('results', function(res) { results = res; }); + + it('should successfully run', function(done) { + console.log(process.cwd()); + // Call cordova create with no args, should return help. + cordova.raw.create().then(function() { + expect(results).toMatch(/synopsis/gi); + }).then(function() { + // Create a real project + return cordova.raw.create(project, appId, appName, extraConfig); + }).then(function() { + // Check if top level dirs exist. + var dirs = ['.cordova', 'platforms', 'merges', 'plugins', 'www']; + dirs.forEach(function(d) { + expect(path.join(project, d)).toExist(); + }); + + // Check if hook dirs exist. + var hooksDir = path.join(project, '.cordova', 'hooks'); + dirs = crossConcat(['platform', 'plugin'], ['add', 'rm', 'ls'], '_'); + dirs = dirs.concat(['build', 'compile', 'docs', 'emulate', 'prepare', 'run']); + dirs = crossConcat(['before', 'after'], dirs, '_'); + dirs.forEach(function(d) { + expect(path.join(hooksDir, d)).toExist(); + }); + + // Check if config files exist. + expect(path.join(cordovaDir, 'config.json')).toExist(); + expect(path.join(project, 'www', 'config.xml')).toExist(); + + // Check contents of config.json + var cfg = config.read(project); + expect(cfg.id).toEqual(appId); + expect(cfg.name).toEqual(appName); + expect(cfg.lib.www.id).toEqual(appName); + + // Check that www/config.xml was updated. + var configXml = new util.config_parser(path.join(project, 'www', 'config.xml')); + expect(configXml.packageName()).toEqual(appId); + + // TODO (kamrik): check somehow that we got the right config.cml from the fixture and not some place else. + // expect(configXml.name()).toEqual('TestBase'); + }).fail(function(err) { + console.log(err); + expect(err).toBeUndefined(); + }).fin(done); + }); +});