You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ka...@apache.org on 2014/04/15 02:33:07 UTC
[7/8] git commit: CB-6421: Move tests from e2e to spec
CB-6421: Move tests from e2e to spec
Removing the duplicate tests first as a separate commit (for better history).
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/fde755fe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/fde755fe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/fde755fe
Branch: refs/heads/master
Commit: fde755fe86b7c93b8505645567781646dc8fb572
Parents: de2500b
Author: Mark Koudritsky <ka...@gmail.com>
Authored: Tue Apr 8 17:50:44 2014 -0400
Committer: Mark Koudritsky <ka...@gmail.com>
Committed: Mon Apr 14 20:25:10 2014 -0400
----------------------------------------------------------------------
spec/create.spec.js | 152 --------------
spec/platform.spec.js | 482 ---------------------------------------------
spec/plugin.spec.js | 288 ---------------------------
3 files changed, 922 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/fde755fe/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
deleted file mode 100644
index a482f4d..0000000
--- a/spec/create.spec.js
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- 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 cordova = require('../cordova'),
- path = require('path'),
- shell = require('shelljs'),
- fs = require('fs'),
- et = require('elementtree'),
- ConfigParser = require('../src/ConfigParser'),
- util = require('../src/util'),
- config = require('../src/config'),
- lazy_load = require('../src/lazy_load'),
- xmlHelpers = require('../src/xml-helpers'),
- Q = require('q'),
- tempDir = path.join(__dirname, '..', 'temp');
-
-var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
- '<widget xmlns = "http://www.w3.org/ns/widgets"\n' +
- ' xmlns:cdv = "http://cordova.apache.org/ns/1.0"\n' +
- ' id = "io.cordova.hellocordova"\n' +
- ' version = "0.0.1">\n' +
- ' <name>Hello Cordova</name>\n' +
- ' <description>\n' +
- ' A sample Apache Cordova application that responds to the deviceready event.\n' +
- ' </description>\n' +
- ' <author href="http://cordova.io" email="dev@cordova.apache.org">\n' +
- ' Apache Cordova Team\n' +
- ' </author>\n' +
- ' <content src="index.html" />\n' +
- ' <access origin="*" />\n' +
- ' <preference name="fullscreen" value="true" />\n' +
- ' <preference name="webviewbounce" value="true" />\n' +
- '</widget>\n';
-
-describe('create command', function () {
- var mkdir, cp, config_spy, load_cordova, load_custom, exists, config_read, config_write;
- beforeEach(function() {
- shell.rm('-rf', tempDir);
- mkdir = spyOn(shell, 'mkdir');
- cp = spyOn(shell, 'cp');
- config_spy = spyOn(cordova, 'config');
- config_read = spyOn(config, 'read').andReturn({});
- config_write = spyOn(config, 'write').andReturn({});
- exists = spyOn(fs, 'existsSync').andCallFake(function(p) {
- if (p == 'lib/dir') return true;
- return false;
- });
- load_cordova = spyOn(lazy_load, 'cordova').andReturn(Q(path.join('lib','dir')));
- load_custom = spyOn(lazy_load, 'custom').andReturn(Q(path.join('lib','dir')));
- spyOn(ConfigParser.prototype, 'write');
- spyOn(xmlHelpers, 'parseElementtreeSync').andCallFake(function() {
- return new et.ElementTree(et.XML(TEST_XML));
- });
- });
-
- describe('failure', function() {
- it('should return a help message if incorrect number of parameters is used', function(done) {
- this.after(function() {
- cordova.removeAllListeners('results');
- });
- cordova.on('results', function(h) {
- expect(h).toMatch(/synopsis/gi);
- done();
- });
- cordova.raw.create();
- });
- });
-
- describe('success', function() {
- it('should create top-level directory structure appropriate for a cordova-cli project', function(done) {
- cordova.raw.create(tempDir).then(function() {
- expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'platforms'));
- expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'merges'));
- expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'plugins'));
- expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'www'));
- done();
- });
- });
- it('should create hooks directory', function(done) {
- var hooks_dir = path.join(tempDir, 'hooks');
- cordova.raw.create(tempDir).then(function() {
- expect(mkdir).toHaveBeenCalledWith(hooks_dir);
- expect(cp).toHaveBeenCalledWith(
- path.resolve(__dirname, '..', 'templates', 'hooks-README.md'),
- jasmine.any(String)
- );
- done();
- });
- });
- it('should by default use cordova-app-hello-world as www assets', function(done) {
- cordova.raw.create(tempDir).then(function() {
- expect(load_cordova).toHaveBeenCalledWith('www');
- done();
- });
- });
- it('should try to lazy load custom www location if specified', function(done) {
- var fake_config = {
- lib:{
- www:{
- id:'supercordova',
- uri:'/supacordoba',
- version:'1337'
- }
- }
- };
- config_read.andReturn(fake_config);
- config_write.andReturn(fake_config);
- cordova.raw.create(tempDir, 'some.app.id', 'SomeAppName', fake_config).then(function() {
- expect(load_custom).toHaveBeenCalledWith(fake_config.lib.www.uri, fake_config.lib.www.id, 'www', fake_config.lib.www.version);
- done();
- });
- });
- it('should add a missing www/config.xml', function(done) {
- cordova.raw.create(tempDir).then(function() {
- expect(shell.cp).toHaveBeenCalledWith(
- path.resolve(__dirname, '..', 'templates', 'config.xml'),
- jasmine.any(String)
- );
- done();
- });
- });
- it('should not replace an existing www/config.xml', function(done) {
- exists.andCallFake(function(p) {
- if (p == 'lib/dir') return true;
- if (p.indexOf('config.xml') > -1) return true;
- return false;
- });
- cordova.raw.create(tempDir).then(function() {
- expect(shell.cp).not.toHaveBeenCalledWith(
- path.resolve(__dirname, '..', 'templates', 'config.xml'),
- jasmine.any(String)
- );
- done();
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/fde755fe/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
deleted file mode 100644
index d4ad000..0000000
--- a/spec/platform.spec.js
+++ /dev/null
@@ -1,482 +0,0 @@
-/**
- 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 cordova = require('../cordova'),
- events = require('../src/events'),
- path = require('path'),
- shell = require('shelljs'),
- superspawn = require('../src/superspawn'),
- xmlHelpers = require('../src/xml-helpers'),
- et = require('elementtree'),
- plugman = require('plugman'),
- fs = require('fs'),
- util = require('../src/util'),
- config = require('../src/config'),
- hooker = require('../src/hooker'),
- lazy_load = require('../src/lazy_load'),
- Q = require('q'),
- platform = require('../src/platform'),
- platforms = require('../platforms');
-
-var cwd = process.cwd();
-var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
-var project_dir = path.join('some', 'path');
-
-var TEST_XML = '<widget xmlns = "http://www.w3.org/ns/widgets"\n' +
- ' xmlns:cdv = "http://cordova.apache.org/ns/1.0"\n' +
- ' id = "io.cordova.hellocordova"\n' +
- ' version = "0.0.1">\n' +
- ' <name>Hello Cordova</name>\n' +
- '</widget>\n';
-
-function fail(e) {
- expect('Got Error: ' + e).toBe('');
-}
-
-describe('platform command', function() {
- var is_cordova,
- cd_project_root,
- cp,
- list_platforms,
- fire,
- find_plugins,
- config_read,
- load,
- load_custom,
- rm,
- mkdir,
- existsSync,
- supports,
- spawn,
- prep_spy,
- plugman_install,
- parsers = {};
- beforeEach(function() {
- supported_platforms.forEach(function(p) {
- parsers[p] = spyOn(platforms[p], 'parser').andReturn({
- staging_dir:function(){},
- www_dir:function(){return 'pwww'}
- });
- });
- is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
- cd_project_root = spyOn(util, 'cdProjectRoot').andReturn(project_dir);
- fire = spyOn(hooker.prototype, 'fire').andReturn(Q());
- spyOn(xmlHelpers, 'parseElementtreeSync').andCallFake(function() {
- return new et.ElementTree(et.XML(TEST_XML));
- });
- find_plugins = spyOn(util, 'findPlugins').andReturn([]);
- list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
- util.libDirectory = path.join('HOMEDIR', '.cordova', 'lib');
- config_read = spyOn(config, 'read').andReturn({});
-
- fakeLazyLoad = function(id, platform, version) {
- if (platform == 'wp7' || platform == 'wp8') {
- return Q(path.join('lib', 'wp', id, version, platform));
- } else {
- return Q(path.join('lib', platform, id, version, platforms[platform] && platforms[platform].subdirectory ? platforms[platform].subdirectory : ''));
- }
- };
- lazyLoadVersion = '3.1.0';
- load = spyOn(lazy_load, 'based_on_config').andCallFake(function(root, platform) {
- return fakeLazyLoad('cordova', platform, lazyLoadVersion);
- });
- load_custom = spyOn(lazy_load, 'custom').andCallFake(function(url, id, platform, version) {
- return fakeLazyLoad(id, platform, version);
- });
-
- rm = spyOn(shell, 'rm');
- cp = spyOn(shell, 'cp');
- mkdir = spyOn(shell, 'mkdir');
- existsSync = spyOn(fs, 'existsSync').andReturn(false);
- var origReadFile = fs.readFileSync;
- spyOn(fs, 'readFileSync').andCallFake(function(path) {
- if (/VERSION$/.test(path)) {
- return '3.3.0';
- }
- return origReadFile.apply(this, arguments);
- });
- supports = spyOn(platform, 'supports').andReturn(Q());
- spawn = spyOn(superspawn, 'spawn').andCallFake(function() { return Q('3.4.0') });
- prep_spy = spyOn(cordova.raw, 'prepare').andReturn(Q());
- plugman_install = spyOn(plugman, 'install').andReturn(Q());
- });
-
- describe('failure', function() {
- function expectFailure(p, done, post) {
- p.then(function() {
- expect('this call').toBe('fail');
- }, post).fin(done);
- }
-
- it('should not run outside of a Cordova-based project by calling util.isCordova', function(done) {
- var msg = 'Dummy message about not being in a cordova dir.';
- cd_project_root.andThrow(new Error(msg));
- expectFailure(Q().then(cordova.raw.platform), done, function(err) {
- expect(cd_project_root).toHaveBeenCalled();
- expect(err.message).toEqual(msg);
- });
- });
- it('should report back an error if used with `add` and no platform is specified', function(done) {
- expectFailure(cordova.raw.platform('add'), done, function(err) {
- expect(err).toEqual(new Error('You need to qualify `add` or `remove` with one or more platforms!'));
- });
- });
- it('should report back an error if used with `rm` and no platform is specified', function(done) {
- expectFailure(cordova.raw.platform('rm'), done, function(err) {
- expect(err).toEqual(new Error('You need to qualify `add` or `remove` with one or more platforms!'));
- });
- });
- });
-
- describe('success', function() {
- it('should run inside a Cordova-based project by calling util.isCordova', function(done) {
- cordova.raw.platform().then(function() {
- expect(is_cordova).toHaveBeenCalled();
- }, fail).fin(done);
- });
-
- describe('`ls`', function() {
- afterEach(function() {
- cordova.removeAllListeners('results');
- });
- it('should list out no platforms for a fresh project', function(done) {
- list_platforms.andReturn([]);
- cordova.on('results', function(res) {
- expect(res).toMatch(/^Installed platforms:\s*Available platforms:.*$/);
- done();
- });
- cordova.raw.platform('list');
-
- });
- it('should list out added platforms in a project', function(done) {
- cordova.on('results', function(res) {
- expect(res).toMatch(RegExp("^Installed platforms: "+supported_platforms.sort().join(", ")+"\\s*Available platforms:\\s*$"));
- done();
- });
- cordova.raw.platform('list');
- });
- });
- describe('`add`', function() {
- beforeEach(function() {
- supported_platforms.forEach(function(p) {
- platforms[p].parser.check_requirements = function(){return Q();};
- });
- });
-
- it('should shell out to specified platform\'s bin/create, using the version that is specified in platforms manifest', function(done) {
- cordova.raw.platform('add', 'android').then(function() {
- expect(spawn.mostRecentCall.args.join()).toMatch(/lib.android.cordova.\d.\d.\d[\d\-\w]*.bin.create/gi);
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }).then(function() {
- return cordova.raw.platform('add', 'wp7');
- }).then(function() {
- expect(spawn.mostRecentCall.args.join()).toMatch(/lib.wp.cordova.\d.\d.\d[\d\w\-]*.wp7.*.bin.create/gi);
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }).then(function() {
- return cordova.raw.platform('add', 'wp8');
- }).then(function() {
- expect(spawn.mostRecentCall.args.join()).toMatch(/lib.wp.cordova.\d.\d.\d[\d\w\-]*.wp8.*.bin.create/gi);
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }).then(function(){
- return cordova.raw.platform('add', 'windows8');
- }).then(function(){
- expect(spawn.mostRecentCall.args.join()).toMatch(/lib.windows8.cordova.\d.\d.\d[\d\w\-]*.windows8.*.bin.create/gi);
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }, fail).fin(done);
- });
- it('should call into lazy_load.custom if there is a user-specified configruation for consuming custom libraries', function(done) {
- load.andCallThrough();
- config_read.andReturn({
- lib:{
- 'wp8':{
- uri:'haha',
- id:'phonegap',
- version:'bleeding edge'
- }
- }
- });
- cordova.raw.platform('add', 'wp8').then(function() {
- expect(load_custom).toHaveBeenCalledWith('haha', 'phonegap', 'wp8', 'bleeding edge');
- expect(spawn.mostRecentCall.args.join()).toMatch(/lib.wp.phonegap.bleeding edge.wp8.*.bin.create/gi);
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }, fail).fin(done);
- });
- it('should use a custom template directory if there is one specified in the configuration', function(done) {
- var template_dir = "/tmp/custom-template"
- load.andCallThrough();
- config_read.andReturn({
- lib: {
- android: {
- uri: "https://git-wip-us.apache.org/repos/asf?p=cordova-android.git",
- version: "3.0.0",
- id: "cordova",
- template: template_dir
- }
- }
- });
- cordova.raw.platform('add', 'android').then(function() {
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- expect(spawn.mostRecentCall.args.join()).toContain(template_dir);
- }, fail).fin(done);
- });
- it('should not use a custom template directory if there is not one specified in the configuration', function(done) {
- load.andCallThrough();
- config_read.andReturn({
- lib: {
- android: {
- uri: "https://git-wip-us.apache.org/repos/asf?p=cordova-android.git",
- version: "3.0.0",
- id: "cordova",
- }
- }
- });
- cordova.raw.platform('add', 'android').then(function() {
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }, fail).fin(done);
- });
- it('should not use a custom template directory if there is no user-defined configuration', function(done) {
- cordova.raw.platform('add', 'android').then(function() {
- expect(spawn.mostRecentCall.args.join()).toContain(project_dir);
- }, fail).fin(done);
- });
- });
- describe('`remove`',function() {
- it('should remove a supported and added platform', function(done) {
- cordova.raw.platform('remove', 'android').then(function() {
- expect(rm).toHaveBeenCalledWith('-rf', path.join(project_dir, 'platforms', 'android'));
- }, fail).fin(done);
- });
-
- it('should be able to remove multiple platforms', function(done) {
- cordova.raw.platform('remove', ['android', 'blackberry10']).then(function() {
- expect(rm).toHaveBeenCalledWith('-rf', path.join(project_dir, 'platforms', 'android'));
- expect(rm).toHaveBeenCalledWith('-rf', path.join(project_dir, 'platforms', 'blackberry10'));
- }, fail).fin(done);
- });
- });
- describe('`update`', function() {
- describe('failure', function() {
- it('should fail if no platform is specified', function(done) {
- cordova.raw.platform('update', []).then(function() {
- expect('this call').toBe('fail');
- }, function(err) {
- expect(err).toEqual(new Error('No platform provided. Please specify a platform to update.'));
- }).fin(done);
- });
- it('should fail if more than one platform is specified', function(done) {
- cordova.raw.platform('update', ['android', 'ios']).then(function() {
- expect('this call').toBe('fail');
- }, function(err) {
- expect(err).toEqual(new Error('Platform update can only be executed on one platform at a time.'));
- }).fin(done);
- });
- });
-
- // Don't run this test on windows ... iOS will fail always
- if(!require('os').platform().match(/^win/)) {
- describe('success', function() {
- it('should shell out to the platform update script', function(done) {
- var oldVersion = lazyLoadVersion;
- lazyLoadVersion = '1.0.0';
- cordova.raw.platform('update', ['ios']).then(function() {
- expect(exec).toHaveBeenCalledWith('"lib/ios/cordova/1.0.0/bin/update" "some/path/platforms/ios"', jasmine.any(Function));
- }, fail).fin(function() {
- lazyLoadVersion = oldVersion;
- done();
- });
- });
- });
- }
- });
- describe('`check`', function() {
- var real_platforms_data = {},
- synthetic_platforms_data = {
- current: {
- uri: "https://localhost",
- version: "3.3.0",
- parser: function(){}
- },
- stale: {
- uri: "https://localhost",
- version: "3.3.0",
- parser: function(){}
- },
- newer: {
- uri: "https://localhost",
- version: "3.3.0",
- parser: function(){}
- }
- };
- beforeEach(function() {
- list_platforms.andReturn(['current', 'stale', 'newer']);
- Object.keys(platforms).forEach(function (k) {
- real_platforms_data[k] = platforms[k];
- delete platforms[k];
- });
- Object.keys(synthetic_platforms_data).forEach(function (k) {
- platforms[k] = synthetic_platforms_data[k];
- });
- });
- afterEach(function() {
- list_platforms.andReturn(['current', 'stale', 'newer']);
- Object.keys(platforms).forEach(function (k) {
- delete platforms[k];
- });
- Object.keys(real_platforms_data).forEach(function (k) {
- platforms[k] = real_platforms_data[k];
- });
- });
- it('check platforms current, stale, newer', function() {
- existsSync.andCallFake(function(dir) {
- if (/cordova-platform-check.*version/.test(dir)) {
- return true;
- }
- if (/cordova-platform-check/.test(dir)) {
- return false;
- }
- return true;
- });
- var create = spyOn(cordova.raw, 'create').andCallFake(function() { return Q() });
-
- spawn.andCallFake(function(cmd) {
- var out;
- if (/cordova-platform-check/.test(cmd)) {
- out = '3.3.0';
- } else if (/current/.test(cmd)) {
- out = '3.3.0';
- } else if (/stale/.test(cmd)) {
- out = '3.2.0';
- } else {
- out = '3.4.0';
- }
- return Q(out);
- });
- var results;
- events.on('results', function(res) { results = res; });
-
- cordova.raw.platform('check');
- waitsFor(function() {
- return results;
- }, 'promise never resolved', 500);
- runs(function() {
- expect(results).toEqual("stale @ 3.2.0 could be updated to: 3.3.0");
- });
- });
- });
- });
- describe('hooks', function() {
- describe('list (ls) hooks', function(done) {
- it('should fire before hooks through the hooker module', function() {
- cordova.raw.platform().then(function() {
- expect(fire).toHaveBeenCalledWith('before_platform_ls');
- }, fail).fin(done);
- });
- it('should fire after hooks through the hooker module', function(done) {
- cordova.raw.platform().then(function() {
- expect(fire).toHaveBeenCalledWith('after_platform_ls');
- }, fail).fin(done);
- });
- });
- describe('remove (rm) hooks', function() {
- it('should fire before hooks through the hooker module', function(done) {
- cordova.raw.platform('rm', 'android').then(function() {
- expect(fire).toHaveBeenCalledWith('before_platform_rm', {platforms:['android']});
- }, fail).fin(done);
- });
- it('should fire after hooks through the hooker module', function(done) {
- cordova.raw.platform('rm', 'android').then(function() {
- expect(fire).toHaveBeenCalledWith('after_platform_rm', {platforms:['android']});
- }, fail).fin(done);
- });
- });
- describe('add hooks', function() {
- beforeEach(function() {
- supported_platforms.forEach(function(p) {
- platforms[p].parser.check_requirements = function(){return Q();};
- });
- });
-
- it('should fire before and after hooks through the hooker module', function(done) {
- cordova.raw.platform('add', 'android').then(function() {
- expect(fire).toHaveBeenCalledWith('before_platform_add', {platforms:['android']});
- expect(fire).toHaveBeenCalledWith('after_platform_add', {platforms:['android']});
- }, fail).fin(done);
- });
- });
- });
-});
-
-describe('platform.supports(name)', function() {
- var supports = {};
- beforeEach(function() {
- supported_platforms.forEach(function(p) {
- supports[p] = spyOn(platforms[p].parser, 'check_requirements').andReturn(Q());
- });
- });
-
- function expectFailure(p, done, post) {
- p.then(function() {
- expect('this call').toBe('fail');
- }, post).fin(done);
- }
-
- it('should require a platform name', function(done) {
- expectFailure(cordova.raw.platform.supports(project_dir, undefined), done, function(err) {
- expect(err).toEqual(jasmine.any(Error));
- });
- });
-
- describe('when platform is unknown', function() {
- it('should reject', function(done) {
- expectFailure(cordova.raw.platform.supports(project_dir, 'windows-3.1'), done, function(err) {
- expect(err).toEqual(jasmine.any(Error));
- done();
- });
- });
- });
-
- describe('when platform is supported', function() {
- it('should resolve', function(done) {
- cordova.raw.platform.supports(project_dir, 'android').then(function() {
- expect(1).toBe(1);
- }, fail).fin(done);
- });
- });
-
- describe('when platform is unsupported', function() {
- it('should reject', function(done) {
- supported_platforms.forEach(function(p) {
- supports[p].andReturn(Q.reject(new Error('no sdk')));
- });
- expectFailure(cordova.raw.platform.supports(project_dir, 'android'), done, function(err) {
- expect(err).toEqual(jasmine.any(Error));
- });
- });
- });
-});
-
-describe('platform parsers', function() {
- it('should be exposed on the platform module', function() {
- for (var platform in platforms) {
- expect(cordova.raw.platform[platform]).toBeDefined();
- for (var prop in platforms[platform]) {
- expect(cordova.raw.platform[platform][prop]).toBeDefined();
- }
- }
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/fde755fe/spec/plugin.spec.js
----------------------------------------------------------------------
diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js
deleted file mode 100644
index d427f00..0000000
--- a/spec/plugin.spec.js
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- 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 cordova = require('../cordova'),
- path = require('path'),
- shell = require('shelljs'),
- child_process = require('child_process'),
- plugman = require('plugman'),
- fs = require('fs'),
- util = require('../src/util'),
- config = require('../src/config'),
- hooker = require('../src/hooker'),
- Q = require('q'),
- platforms = require('../platforms');
-
-var cwd = process.cwd();
-var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; }).sort();
-var sample_plugins = ['one','two'];
-var project_dir = path.join('some','path');
-var plugins_dir = path.join(project_dir, 'plugins');
-
-describe('plugin command', function() {
- var is_cordova,
- cd_project_root,
- list_platforms,
- fire,
- find_plugins,
- rm,
- mkdir,
- existsSync,
- exec,
- prep_spy,
- plugman_install,
- plugman_fetch,
- parsers = {},
- uninstallPlatform,
- uninstallPlugin;
-
- beforeEach(function() {
- is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
- cd_project_root = spyOn(util, 'cdProjectRoot').andReturn(project_dir);
- fire = spyOn(hooker.prototype, 'fire').andReturn(Q());
- supported_platforms.forEach(function(p) {
- parsers[p] = jasmine.createSpy(p + ' update_project').andReturn(Q());
- spyOn(platforms[p], 'parser').andReturn({});
- });
- list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
- find_plugins = spyOn(util, 'findPlugins').andReturn(sample_plugins);
- rm = spyOn(shell, 'rm');
- mkdir = spyOn(shell, 'mkdir');
- existsSync = spyOn(fs, 'existsSync').andReturn(false);
- exec = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(0, '', '');
- });
- prep_spy = spyOn(cordova.raw, 'prepare').andReturn(Q());
- plugman_install = spyOn(plugman.raw, 'install').andReturn(Q());
- plugman_fetch = spyOn(plugman.raw, 'fetch').andCallFake(function(target, plugins_dir, opts) { return Q(path.join(plugins_dir, target)); });
- plugman_search = spyOn(plugman.raw, 'search').andReturn(Q());
- uninstallPlatform = spyOn(plugman.raw.uninstall, 'uninstallPlatform').andReturn(Q());
- uninstallPlugin = spyOn(plugman.raw.uninstall, 'uninstallPlugin').andReturn(Q());
- });
-
- describe('failure', function() {
- function expectFailure(p, done, post) {
- p.then(function() {
- expect('this call').toBe('fail');
- }, post).fin(done);
- }
-
- it('should not run outside of a Cordova-based project by calling util.isCordova', function(done) {
- var msg = 'Dummy message about not being in a cordova dir.';
- cd_project_root.andThrow(new Error(msg));
- is_cordova.andReturn(false);
- expectFailure(Q().then(cordova.raw.plugin), done, function(err) {
- expect(err.message).toEqual(msg);
- });
- });
- it('should report back an error if used with `add` and no plugin is specified', function(done) {
- expectFailure(cordova.raw.plugin('add'), done, function(err) {
- expect(err).toEqual(new Error('You need to qualify `add` or `remove` with one or more plugins!'));
- });
- });
- it('should report back an error if used with `rm` and no plugin is specified', function(done) {
- expectFailure(cordova.raw.plugin('rm'), done, function(err) {
- expect(err).toEqual(new Error('You need to qualify `add` or `remove` with one or more plugins!'));
- });
- });
- });
-
- describe('success', function() {
- it('should run inside a Cordova-based project by calling util.isCordova', function(done) {
- cordova.raw.plugin().then(function() {
- expect(is_cordova).toHaveBeenCalled();
- done();
- });
- });
-
- describe('`ls`', function() {
- afterEach(function() {
- cordova.removeAllListeners('results');
- });
- it('should list out no plugins for a fresh project', function(done) {
- find_plugins.andReturn([]);
- cordova.on('results', function(res) {
- expect(res).toEqual('No plugins added. Use `cordova plugin add <plugin>`.');
- done();
- });
- cordova.raw.plugin('list');
- });
- it('should list out added plugins in a project', function(done) {
- cordova.on('results', function(res) {
- expect(res).toEqual(sample_plugins);
- done();
- });
- cordova.raw.plugin('list');
- });
- it('should resolve with a list of plugins', function(done) {
- cordova.raw.plugin('list', []).then(function(plugins) {
- expect(plugins).toEqual(sample_plugins);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- describe('`add`', function() {
- it('should call plugman.fetch for each plugin', function(done) {
- cordova.raw.plugin('add', sample_plugins).then(function() {
- sample_plugins.forEach(function(p) {
- expect(plugman_fetch).toHaveBeenCalledWith(p, plugins_dir, {});
- });
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should call plugman.install, for each plugin, for every platform', function(done) {
- cordova.raw.plugin('add', sample_plugins).then(function(err) {
- sample_plugins.forEach(function(plug) {
- supported_platforms.forEach(function(plat) {
- expect(plugman_install).toHaveBeenCalledWith((plat=='blackberry'?'blackberry10':plat), path.join(project_dir, 'platforms', plat), plug, plugins_dir, jasmine.any(Object));
- });
- });
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should pass down variables into plugman', function(done) {
- cordova.raw.plugin('add', "one", "--variable", "foo=bar").then(function() {
- supported_platforms.forEach(function(plat) {
- expect(plugman_install).toHaveBeenCalledWith(
- (plat=='blackberry'?'blackberry10':plat),
- path.join(project_dir, 'platforms', plat),
- "one",
- plugins_dir,
- {cli_variables: { FOO: "bar"}}
- );
- });
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should resolve without an error', function(done) {
- cordova.raw.plugin('add', sample_plugins).then(function() {
- expect(1).toBe(1);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- describe('`search`', function() {
- it('should call plugman.search', function(done) {
- cordova.raw.plugin('search', sample_plugins).then(function() {
- expect(plugman_search).toHaveBeenCalledWith(sample_plugins);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- describe('`remove`',function() {
- var plugin_parser;
- var subset = ['android', 'wp7'];
- beforeEach(function() {
- plugin_parser = spyOn(util, 'plugin_parser').andReturn({
- platforms:subset
- });
- });
- it('should throw if plugin is not installed', function(done) {
- cordova.raw.plugin('rm', 'somethingrandom').then(function() {
- expect('this call').toBe('fail');
- }, function(err) {
- expect(err).toEqual(new Error('Plugin "somethingrandom" not added to project.'));
- }).fin(done);
- });
-
- it('should call plugman.uninstall.uninstallPlatform for every matching installedplugin-supportedplatform pair', function(done) {
- cordova.raw.plugin('rm', sample_plugins).then(function() {
- sample_plugins.forEach(function(plug) {
- subset.forEach(function(plat) {
- expect(uninstallPlatform).toHaveBeenCalledWith(plat, path.join(project_dir, 'platforms', plat), plug, plugins_dir);
- });
- });
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should call plugman.uninstall.uninstallPlugin once for every removed plugin', function(done) {
- uninstallPlugin.reset();
- cordova.raw.plugin('rm', sample_plugins).then(function() {
- expect(uninstallPlugin.callCount).toBe(2);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should resolve without an error', function(done) {
- cordova.raw.plugin('rm', sample_plugins).then(function() {
- expect(1).toBe(1);
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(done);
- });
- });
- });
- describe('hooks', function() {
- var plugin_parser;
- beforeEach(function() {
- plugin_parser = spyOn(util, 'plugin_parser').andReturn({
- platforms:supported_platforms
- });
- });
- describe('list (ls) hooks', function() {
- it('should fire before hooks through the hooker module', function(done) {
- cordova.raw.plugin().then(function() {
- expect(fire).toHaveBeenCalledWith('before_plugin_ls');
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should fire after hooks through the hooker module', function(done) {
- cordova.raw.plugin().then(function() {
- expect(fire).toHaveBeenCalledWith('after_plugin_ls');
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- describe('remove (rm) hooks', function() {
- it('should fire before hooks through the hooker module', function(done) {
- cordova.raw.plugin('rm', 'two').then(function() {
- expect(fire).toHaveBeenCalledWith('before_plugin_rm', {plugins:['two'], options: []});
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should fire after hooks through the hooker module', function(done) {
- cordova.raw.plugin('rm', 'one').then(function() {
- expect(fire).toHaveBeenCalledWith('after_plugin_rm', {plugins:['one'], options:[]});
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- describe('add hooks', function() {
- it('should fire before and after hooks through the hooker module', function(done) {
- cordova.raw.plugin('add', 'android').then(function() {
- expect(fire).toHaveBeenCalledWith('before_plugin_add', {plugins:['android'], options: []});
- expect(fire).toHaveBeenCalledWith('after_plugin_add', {plugins:['android'], options: []});
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- });
- });
-});