From e9863e5c2e3bab651842be4af9265c72d7859ce2 Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Thu, 5 May 2016 17:53:50 +0300 Subject: [PATCH] Disable e2e to decreate coverage --- cordova-lib/spec-cordova/platform.spec.js | 250 -------- cordova-lib/spec-cordova/plugin.spec.js | 301 ---------- cordova-lib/spec-cordova/save.spec.js | 661 ---------------------- 3 files changed, 1212 deletions(-) delete mode 100644 cordova-lib/spec-cordova/platform.spec.js delete mode 100644 cordova-lib/spec-cordova/plugin.spec.js delete mode 100644 cordova-lib/spec-cordova/save.spec.js diff --git a/cordova-lib/spec-cordova/platform.spec.js b/cordova-lib/spec-cordova/platform.spec.js deleted file mode 100644 index a35216f6a..000000000 --- a/cordova-lib/spec-cordova/platform.spec.js +++ /dev/null @@ -1,250 +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 helpers = require('./helpers'), - path = require('path'), - fs = require('fs'), - shell = require('shelljs'), - superspawn = require('cordova-common').superspawn, - config = require('../src/cordova/config'), - Q = require('q'), - events = require('cordova-common').events, - cordova = require('../src/cordova/cordova'), - plugman = require('../src/plugman/plugman'), - rewire = require('rewire'), - platform = rewire('../src/cordova/platform.js'); - -var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker'; -var pluginsDir = path.join(__dirname, 'fixtures', 'plugins'); - -describe('platform end-to-end', function () { - - var tmpDir = helpers.tmpDir('platform_test'); - var project = path.join(tmpDir, 'project'); - - var results; - - beforeEach(function() { - shell.rm('-rf', tmpDir); - - // cp then mv because we need to copy everything, but that means it'll copy the whole directory. - // Using /* doesn't work because of hidden files. - shell.cp('-R', path.join(__dirname, 'fixtures', 'base'), tmpDir); - shell.mv(path.join(tmpDir, 'base'), project); - process.chdir(project); - - // Now we load the config.json in the newly created project and edit the target platform's lib entry - // to point at the fixture version. This is necessary so that cordova.prepare can find cordova.js there. - var c = config.read(project); - c.lib[helpers.testPlatform].url = path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform + '-lib'); - config.write(project, c); - - // The config.json in the fixture project points at fake "local" paths. - // Since it's not a URL, the lazy-loader will just return the junk path. - spyOn(superspawn, 'spawn').andCallFake(function(cmd, args) { - if (cmd.match(/create\b/)) { - // This is a call to the bin/create script, so do the copy ourselves. - shell.cp('-R', path.join(__dirname, 'fixtures', 'platforms', 'android'), path.join(project, 'platforms')); - } else if(cmd.match(/version\b/)) { - return Q('3.3.0'); - } else if(cmd.match(/update\b/)) { - fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8'); - } - return Q(); - }); - - events.on('results', function(res) { results = res; }); - }); - - afterEach(function() { - process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows. - shell.rm('-rf', tmpDir); - }); - - // Factoring out some repeated checks. - function emptyPlatformList() { - return cordova.raw.platform('list').then(function() { - var installed = results.match(/Installed platforms:\n (.*)/); - expect(installed).toBeDefined(); - expect(installed[1].indexOf(helpers.testPlatform)).toBe(-1); - }); - } - function fullPlatformList() { - return cordova.raw.platform('list').then(function() { - var installed = results.match(/Installed platforms:\n (.*)/); - expect(installed).toBeDefined(); - expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1); - }); - } - - // The flows we want to test are add, rm, list, and upgrade. - // They should run the appropriate hooks. - // They should fail when not inside a Cordova project. - // These tests deliberately have no beforeEach and afterEach that are cleaning things up. - it('should successfully run', function(done) { - - // Check there are no platforms yet. - emptyPlatformList().then(function() { - // Add the testing platform. - return cordova.raw.platform('add', [helpers.testPlatform]); - }).then(function() { - // Check the platform add was successful. - expect(path.join(project, 'platforms', helpers.testPlatform)).toExist(); - expect(path.join(project, 'platforms', helpers.testPlatform, 'cordova')).toExist(); - }).then(fullPlatformList) // Check for it in platform ls. - .then(function() { - // Try to update the platform. - return cordova.raw.platform('update', [helpers.testPlatform]); - }).then(function() { - // Our fake update script in the exec mock above creates this dummy file. - expect(path.join(project, 'platforms', helpers.testPlatform, 'updated')).toExist(); - }).then(fullPlatformList) // Platform should still be in platform ls. - .then(function() { - // And now remove it. - return cordova.raw.platform('rm', [helpers.testPlatform]); - }).then(function() { - // It should be gone. - expect(path.join(project, 'platforms', helpers.testPlatform)).not.toExist(); - }).then(emptyPlatformList) // platform ls should be empty too. - .fail(function(err) { - expect(err).toBeUndefined(); - }).fin(done); - }); - - it('should install plugins correctly while adding platform', function(done) { - - cordova.raw.plugin('add', path.join(pluginsDir, 'test')) - .then(function() { - return cordova.raw.platform('add', [helpers.testPlatform]); - }) - .then(function() { - // Check the platform add was successful. - expect(path.join(project, 'platforms', helpers.testPlatform)).toExist(); - // Check that plugin files exists in www dir - expect(path.join(project, 'platforms', helpers.testPlatform, 'assets/www/test.js')).toExist(); - }) - .fail(function(err) { - expect(err).toBeUndefined(); - }) - .fin(done); - }); - - it('should call prepare after plugins were installed into platform', function(done) { - var order = ''; - var fail = jasmine.createSpy(fail); - spyOn(plugman.raw, 'install').andCallFake(function() { order += 'I'; }); - spyOn(cordova.raw, 'prepare').andCallFake(function() { order += 'P'; }); - - cordova.raw.plugin('add', path.join(pluginsDir, 'test')) - .then(function() { - return cordova.raw.platform('add', [helpers.testPlatform]); - }) - .fail(fail) - .fin(function() { - expect(order).toBe('IP'); // Install first, then prepare - expect(fail).not.toHaveBeenCalled(); - done(); - }); - }); -}); - -describe('add function', function () { - var opts; - var hooksRunnerMock; - - beforeEach(function(){ - opts = {}; - hooksRunnerMock = { - fire: function () { - return Q(); - } - }; - }); - - it('throws if the target list is empty', function (done) { - var targets = []; - platform.add(hooksRunnerMock, projectRoot, targets, opts).fail(function (error) { - expect(error.message).toBe('No platform specified. Please specify a platform to add. See `cordova platform list`.'); - done(); - }); - }); - - it('throws if the target list is undefined or null', function (done) { - - // case 1 : target list undefined - var targets; // = undefined; - platform.add(hooksRunnerMock, projectRoot, targets, opts).fail(function (error) { - expect(error.message).toBe('No platform specified. Please specify a platform to add. See `cordova platform list`.'); - }); - - // case 2 : target list null - targets = null; - platform.add(hooksRunnerMock, projectRoot, targets, opts).fail(function (error) { - expect(error.message).toBe('No platform specified. Please specify a platform to add. See `cordova platform list`.'); - done(); - }); - }); -}); - -describe('platform add plugin rm end-to-end', function () { - - var tmpDir = helpers.tmpDir('plugin_rm_test'); - var project = path.join(tmpDir, 'hello'); - var pluginsDir = path.join(project, 'plugins'); - - beforeEach(function() { - process.chdir(tmpDir); - }); - - afterEach(function() { - process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows. - shell.rm('-rf', tmpDir); - }); - - it('should remove dependency when removing parent plugin', function(done) { - - cordova.raw.create('hello') - .then(function() { - process.chdir(project); - return cordova.raw.platform('add', 'ios'); - }) - .then(function() { - return cordova.raw.plugin('add', 'cordova-plugin-media'); - }) - .then(function() { - expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); - expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - return cordova.raw.platform('add', 'android'); - }) - .then(function() { - expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); - expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - return cordova.raw.plugin('rm', 'cordova-plugin-media'); - }) - .then(function() { - expect(path.join(pluginsDir, 'cordova-plugin-media')).not.toExist(); - expect(path.join(pluginsDir, 'cordova-plugin-file')).not.toExist(); - }) - .fail(function(err) { - console.error(err); - expect(err).toBeUndefined(); - }) - .fin(done); - }, 20000); -}); diff --git a/cordova-lib/spec-cordova/plugin.spec.js b/cordova-lib/spec-cordova/plugin.spec.js deleted file mode 100644 index ac6f6b9a4..000000000 --- a/cordova-lib/spec-cordova/plugin.spec.js +++ /dev/null @@ -1,301 +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 helpers = require('./helpers'), - path = require('path'), - Q = require('q'), - shell = require('shelljs'), - events = require('cordova-common').events, - cordova = require('../src/cordova/cordova'), - prepare = require('../src/cordova/prepare'), - platforms = require('../src/platforms/platforms'), - plugman = require('../src/plugman/plugman'), - registry = require('../src/plugman/registry/registry'); - -var util = require('../src/cordova/util'); - -var tmpDir = helpers.tmpDir('plugin_test'); -var project = path.join(tmpDir, 'project'); -var pluginsDir = path.join(__dirname, 'fixtures', 'plugins'); - -var pluginId = 'org.apache.cordova.fakeplugin1'; -var org_test_defaultvariables = 'org.test.defaultvariables'; - -// This plugin is published to npm and defines cordovaDependencies -// in its package.json. Based on the dependencies and the version of -// cordova-android installed in our test project, the CLI should -// select version 1.1.2 of the plugin. We don't actually fetch from -// npm, but we do check the npm info. -var npmInfoTestPlugin = 'cordova-lib-test-plugin'; -var npmInfoTestPluginVersion = '1.1.2'; - -var testGitPluginRepository = 'https://github.com/apache/cordova-plugin-device.git'; -var testGitPluginId = 'cordova-plugin-device'; - -var results; - -// Runs: list, add, list -function addPlugin(target, id, options) { - // Check there are no plugins yet. - return cordova.raw.plugin('list').then(function() { - expect(results).toMatch(/No plugins added/gi); - }).then(function() { - // Add a fake plugin from fixtures. - return cordova.raw.plugin('add', target, options); - }).then(function() { - expect(path.join(project, 'plugins', id, 'plugin.xml')).toExist(); - }).then(function() { - return cordova.raw.plugin('ls'); - }).then(function() { - expect(results).toContain(id); - }); -} - -// Runs: remove, list -function removePlugin(id) { - return cordova.raw.plugin('rm', id) - .then(function() { - // The whole dir should be gone. - expect(path.join(project, 'plugins', id)).not.toExist(); - }).then(function() { - return cordova.raw.plugin('ls'); - }).then(function() { - expect(results).toMatch(/No plugins added/gi); - }); -} - -var errorHandler = { - errorCallback: function(error) { - // We want the error to be printed by jasmine - expect(error).toBeUndefined(); - } -}; - -// We can't call add with a searchpath or else we will conflict with other tests -// that use a searchpath. See loadLocalPlugins() in plugman/fetch.js for details. -// The searchpath behavior gets tested in the plugman spec -function mockPluginFetch(id, dir) { - spyOn(plugman.raw, 'fetch').andCallFake(function(target, pluginPath, fetchOptions) { - var dest = path.join(project, 'plugins', id); - var src = path.join(dir, 'plugin.xml'); - - shell.mkdir(dest); - shell.cp(src, dest); - return Q(dest); - }); -} - -function setupPlatformApiSpies() { - var api = platforms.getPlatformApi(helpers.testPlatform, path.join(project, 'platforms', helpers.testPlatform)); - var addPluginOrig = api.addPlugin; - var removePluginOrig = api.removePlugin; - - spyOn(api, 'addPlugin').andCallFake(function () { - return addPluginOrig.apply(api, arguments) - .thenResolve(true); - }); - - spyOn(api, 'removePlugin').andCallFake(function () { - return removePluginOrig.apply(api, arguments) - .thenResolve(true); - }); -} - -describe('plugin end-to-end', function() { - events.on('results', function(res) { results = res; }); - - beforeEach(function() { - shell.rm('-rf', project); - - // cp then mv because we need to copy everything, but that means it'll copy the whole directory. - // Using /* doesn't work because of hidden files. - shell.cp('-R', path.join(__dirname, 'fixtures', 'base'), tmpDir); - shell.mv(path.join(tmpDir, 'base'), project); - // Copy some platform to avoid working on a project with no platforms. - shell.cp('-R', path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform), path.join(project, 'platforms')); - process.chdir(project); - - // Reset origCwd before each spec to respect chdirs - util._resetOrigCwd(); - delete process.env.PWD; - - spyOn(prepare, 'preparePlatforms').andCallThrough(); - spyOn(errorHandler, 'errorCallback').andCallThrough(); - }); - - afterEach(function() { - process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows. - shell.rm('-rf', tmpDir); - expect(errorHandler.errorCallback).not.toHaveBeenCalled(); - }); - - it('should successfully add and remove a plugin with no options', function(done) { - addPlugin(path.join(pluginsDir, 'fake1'), pluginId, {}, done) - .then(function() { - return removePlugin(pluginId); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should run prepare after plugin installation/removal by default', function(done) { - addPlugin(path.join(pluginsDir, 'fake1'), pluginId, {}) - .then(function() { - expect(prepare.preparePlatforms).toHaveBeenCalled(); - prepare.preparePlatforms.reset(); - return removePlugin(pluginId); - }) - .then(function () { - expect(prepare.preparePlatforms).toHaveBeenCalled(); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should not run prepare after plugin installation/removal if platform return non-falsy value', function(done) { - setupPlatformApiSpies(); - addPlugin(path.join(pluginsDir, 'fake1'), pluginId, {}) - .then(function() { - expect(prepare.preparePlatforms).not.toHaveBeenCalled(); - return removePlugin(pluginId); - }) - .then(function () { - expect(prepare.preparePlatforms).not.toHaveBeenCalled(); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should successfully add a plugin using relative path when running from subdir inside of project', function(done) { - // Copy plugin to subdir inside of the project. This is required since path.relative - // returns an absolute path when source and dest are on different drives - var plugindir = path.join(project, 'custom-plugins/some-plugin-inside-subfolder'); - shell.mkdir('-p', plugindir); - shell.cp('-r', path.join(pluginsDir, 'fake1/*'), plugindir); - - // Create a subdir, where we're going to run cordova from - var subdir = path.join(project, 'bin'); - shell.mkdir('-p', subdir); - shell.cd(subdir); - - // Add plugin using relative path - addPlugin(path.relative(subdir, plugindir), pluginId, {}, done) - .then(function() { - return removePlugin(pluginId); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should successfully add a plugin when specifying CLI variables', function(done) { - addPlugin(path.join(pluginsDir, org_test_defaultvariables), org_test_defaultvariables, {cli_variables: { REQUIRED:'yes', REQUIRED_ANDROID:'yes'}}, done) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should not check npm info when using the searchpath flag', function(done) { - mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - - spyOn(registry, 'info'); - addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {searchpath: pluginsDir}, done) - .then(function() { - expect(registry.info).not.toHaveBeenCalled(); - - var fetchOptions = plugman.raw.fetch.mostRecentCall.args[2]; - expect(fetchOptions.searchpath).toBeDefined(); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should not check npm info when using the noregistry flag', function(done) { - mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - - spyOn(registry, 'info'); - addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {noregistry:true}, done) - .then(function() { - expect(registry.info).not.toHaveBeenCalled(); - - var fetchOptions = plugman.raw.fetch.mostRecentCall.args[2]; - expect(fetchOptions.noregistry).toBeTruthy(); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should not check npm info when fetching from a Git repository', function(done) { - spyOn(registry, 'info'); - addPlugin(testGitPluginRepository, testGitPluginId, {}, done) - .then(function() { - expect(registry.info).not.toHaveBeenCalled(); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should select the plugin version based on npm info when fetching from npm', function(done) { - mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - - spyOn(registry, 'info').andCallThrough(); - addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {}, done) - .then(function() { - expect(registry.info).toHaveBeenCalled(); - - var fetchTarget = plugman.raw.fetch.mostRecentCall.args[0]; - expect(fetchTarget).toEqual(npmInfoTestPlugin + '@' + npmInfoTestPluginVersion); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should handle scoped npm packages', function(done) { - var scopedPackage = '@testscope/' + npmInfoTestPlugin; - mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - - spyOn(registry, 'info').andReturn(Q({})); - addPlugin(scopedPackage, npmInfoTestPlugin, {}, done) - .then(function() { - // Check to make sure that we are at least trying to get the correct package. - // This package is not published to npm, so we can't truly do end-to-end tests - - expect(registry.info).toHaveBeenCalledWith([scopedPackage]); - - var fetchTarget = plugman.raw.fetch.mostRecentCall.args[0]; - expect(fetchTarget).toEqual(scopedPackage); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); - - it('should handle scoped npm packages with given version tags', function(done) { - var scopedPackage = '@testscope/' + npmInfoTestPlugin + '@latest'; - mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - - spyOn(registry, 'info'); - addPlugin(scopedPackage, npmInfoTestPlugin, {}, done) - .then(function() { - expect(registry.info).not.toHaveBeenCalled(); - - var fetchTarget = plugman.raw.fetch.mostRecentCall.args[0]; - expect(fetchTarget).toEqual(scopedPackage); - }) - .fail(errorHandler.errorCallback) - .fin(done); - }); -}); diff --git a/cordova-lib/spec-cordova/save.spec.js b/cordova-lib/spec-cordova/save.spec.js deleted file mode 100644 index e2be5a5b4..000000000 --- a/cordova-lib/spec-cordova/save.spec.js +++ /dev/null @@ -1,661 +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. -*/ - -describe('(save flag)', function () { - var rewire = require('rewire'), - cordova = require('../src/cordova/cordova'), - helpers = require('./helpers'), - path = require('path'), - Q = require('q'), - fs = require('fs'), - shell = require('shelljs'), - util = require('../src/cordova/util'), - prepare = require('../src/cordova/prepare'), - registry = require('../src/plugman/registry/registry'), - PlatformApi = require('../src/platforms/PlatformApiPoly'), - platform = rewire('../src/cordova/platform'); - - var appName = 'testApp', - tempPath = path.join(__dirname, 'temp'), - appPath = path.join(tempPath, appName), - platformName = helpers.testPlatform, - platformVersionOld = '4.0.0', - platformVersionNew = '4.0.1', - platformVersionNewer = '4.1.1', - platformLocalPathOld = path.join(__dirname, 'cordova-' + platformName + '-old'), - platformLocalPathNew = path.join(__dirname, 'cordova-' + platformName + '-new'), - platformLocalPathNewer = path.join(__dirname, 'cordova-' + platformName + '-newer'), - platformGitUrl = 'https://github.com/apache/cordova-' + platformName, - platformGitRef = '4.0.x', - platformTgzUrl = 'https://git-wip-us.apache.org/repos/asf?p=cordova-' + platformName + '.git;a=snapshot;h=' + platformVersionNew + ';sf=tgz', - otherPlatformName = 'windows', - otherPlatformSpec = '4.0.0', - pluginName = 'cordova-plugin-console', - pluginVersion = '1.0.0', - pluginName2 = 'cordova-plugin-globalization', - pluginVersion2 = '1.0.2', - pluginGitUrl = 'https://github.com/apache/cordova-plugin-console.git', - pluginOldName = 'org.apache.cordova.console', - pluginOldVersion = '0.2.11', - gitPluginName = 'cordova-plugin-device', - gitPluginUrl = 'https://github.com/apache/cordova-plugin-device.git', - variablePluginName = 'phonegap-facebook-plugin', - variablePluginUrl = 'https://github.com/Wizcorp/phonegap-facebook-plugin', - localPluginName = 'org.apache.cordova.fakeplugin1', - localPluginPath = path.join(__dirname, 'fixtures', 'plugins', 'fake1'), - TIMEOUT = 60 * 1000, - BIG_TIMEOUT = 2 * 60 * 1000; - - //mock variables - var revertInstallPluginsForNewPlatform, - revertDownloadPlatform, - createPlatformOrig = PlatformApi.createPlatform; - - function mockDownloadPlatform(libDir, version) { - revertDownloadPlatform = platform.__set__('downloadPlatform', function () { - return Q({ - libDir: libDir, - platform: platformName, - version: version - }); - }); - } - - /** - * For testing scoped packages. We don't have those packages published, so just - * redirect the registry calls to their un-scoped counterparts - */ - function redirectRegistryCalls(id) { - var originalFetch = registry.fetch; - spyOn(registry, 'fetch').andCallFake(function(package) { - return originalFetch([id]); - }); - - var originalInfo = registry.info; - spyOn(registry, 'info').andCallFake(function(package) { - return originalInfo([id]); - }); - } - - beforeEach(function (done) { - // initial cleanup - shell.rm('-rf', tempPath); - shell.mkdir(tempPath); - - //jasmine mocks - spyOn(util, 'isCordova').andReturn(appPath); - spyOn(util, 'cdProjectRoot').andReturn(appPath); - spyOn(cordova.raw, 'prepare').andReturn(Q()); - spyOn(prepare, 'preparePlatforms').andReturn(Q()); - - spyOn(PlatformApi, 'createPlatform').andReturn(Q()); - spyOn(PlatformApi, 'updatePlatform').andReturn(Q()); - - //rewire mocks - revertInstallPluginsForNewPlatform = platform.__set__('installPluginsForNewPlatform', function () { return Q(); }); - - //creating test app - cordova.raw.create(appPath, undefined, undefined, {}).then(function () { - //removing unnecessary whitelist plugin from config - helpers.removePlugin(appPath, 'cordova-plugin-whitelist'); - done(); - }, function (err) { - expect(true).toBe(false); - console.log(err); - done(); - }); - }, TIMEOUT); - - afterEach(function () { - revertInstallPluginsForNewPlatform(); - }); - - describe('preparing fixtures', function () { - it('cloning "old" platform', function (done) { - shell.rm('-rf', platformLocalPathOld); - shell.exec('git clone ' + platformGitUrl + ' ' + platformLocalPathOld + - ' && cd ' + platformLocalPathOld + - ' && git reset --hard ' + platformVersionOld, { silent: true }, function (err) { - expect(err).toBe(0); - done(); - }); - }, BIG_TIMEOUT); - - it('cloning "new" platform', function (done) { - shell.rm('-rf', platformLocalPathNew); - shell.exec('git clone ' + platformGitUrl + ' ' + platformLocalPathNew + - ' && cd ' + platformLocalPathNew + - ' && git reset --hard ' + platformVersionNew, { silent: true }, function (err) { - expect(err).toBe(0); - done(); - }); - }, BIG_TIMEOUT); - - it('cloning "newer" platform', function (done) { - shell.rm('-rf', platformLocalPathNewer); - shell.exec('git clone ' + platformGitUrl + ' ' + platformLocalPathNewer + - ' && cd ' + platformLocalPathNewer + - ' && git reset --hard ' + platformVersionNewer, { silent: true }, function (err) { - expect(err).toBe(0); - done(); - }); - }, BIG_TIMEOUT); - }); - - describe('platform add --save', function () { - it('spec.1 should support custom tgz files', function (done) { - helpers.removeEngine(appPath, platformName); - platform('add', platformName + '@' + platformTgzUrl, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(platformTgzUrl); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }); - }, BIG_TIMEOUT); - - it('spec.2 should save platform to config', function (done) { - helpers.removeEngine(appPath, platformName); - mockDownloadPlatform(platformLocalPathNew, platformVersionNew); - - platform('add', platformName, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe('~' + platformVersionNew); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - - it('spec.3 should overwrite platform in config, spec = version', function (done) { - helpers.setEngineSpec(appPath, platformName, platformVersionOld); - mockDownloadPlatform(platformLocalPathOld, platformVersionOld); - - platform('add', platformName, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe('~' + platformVersionOld); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - - it('spec.4 should overwrite platform in config, spec = path', function (done) { - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - mockDownloadPlatform(platformLocalPathNewer, platformVersionNewer); - - platform('add', platformName, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(platformLocalPathNewer); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - - it('spec.5 should fail and should not update config if invalid version is specified', function (done) { - helpers.removeEngine(appPath, platformName); - - platform('add', platformName + '@3.969.696', { 'save': true }) - .then(function () { - expect(false).toBe(true); - done(); - }).catch(function (err) { - expect(err.message.indexOf('version not found') >= 0).toBe(true); - expect(helpers.getEngineSpec(appPath, platformName)).toBe(null); - done(); - }); - }); - - it('spec.6 should save local path as spec if added using only local path', function (done) { - helpers.removeEngine(appPath, platformName); - - platform('add', platformLocalPathNewer, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(platformLocalPathNewer); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }); - }, TIMEOUT); - - it('spec.7 should save git url with git ref properly', function (done) { - var platformUrl = platformGitUrl + '#' + platformGitRef; - helpers.removeEngine(appPath, platformName); - mockDownloadPlatform(platformLocalPathNew, platformVersionNew); - - platform('add', platformUrl, { 'save': true }) - .then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(platformUrl); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - }); - - describe('platform remove --save', function () { - it('spec.8 should not update config if there is no engine in it', function (done) { - helpers.removeEngine(appPath, platformName); - - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.platform('rm', platformName, { 'save': true }); - }).then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(null); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }); - }, TIMEOUT); - - it('spec.9 should remove engine from config', function (done) { - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.platform('rm', platformName, { 'save': true }); - }).then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe(null); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }); - }, TIMEOUT); - }); - - describe('platform update --save', function () { - it('spec.10 should update config with new spec', function (done) { - helpers.setEngineSpec(appPath, platformName, platformVersionNew); - mockDownloadPlatform(platformLocalPathNew, platformVersionNew); - - platform('add', platformName + '@' + platformVersionNew) - .then(function () { - var fsExistsSync = fs.existsSync.bind(fs); - spyOn(fs, 'existsSync').andCallFake(function (somePath) { - return (somePath === path.join(appPath, 'platforms', platformName)) || fsExistsSync(somePath); - }); - - revertDownloadPlatform(); - mockDownloadPlatform(platformLocalPathOld, platformVersionOld); - - return platform('update', platformName + '@' + platformVersionOld, { 'save': true }); - }).then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe('~' + platformVersionOld); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - - it('spec.11 should update spec with git url when updating using git url', function (done) { - helpers.setEngineSpec(appPath, platformName, platformVersionNew); - mockDownloadPlatform(platformLocalPathOld, platformVersionOld); - - platform('add', platformName + '@' + platformVersionOld) - .then(function () { - revertDownloadPlatform(); - var fsExistsSync = fs.existsSync.bind(fs); - spyOn(fs, 'existsSync').andCallFake(function (somePath) { - return (somePath === path.join(appPath, 'platforms', platformName)) || fsExistsSync(somePath); - }); - mockDownloadPlatform(platformLocalPathNew, platformVersionNew); - return platform('update', platformGitUrl, { 'save': true }); - }).then(function () { - revertDownloadPlatform(); - var spec = helpers.getEngineSpec(appPath, platformName); - expect(spec).not.toBe(null); - expect(spec).not.toBe(platformVersionNew); - done(); - }).catch(function (err) { - console.log(err); - expect(false).toBe(true); - done(); - }).finally(function (err) { - - }); - }, TIMEOUT); - }); - - describe('plugin add --save', function () { - it('spec.12 should save plugin to config', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', pluginName, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginName)).not.toBe(null); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.13 should create new plugin tag in config with old plugin id when downgrading from plugin with new id', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - helpers.setPluginSpec(appPath, pluginName, pluginOldVersion); - return cordova.raw.plugin('add', pluginName, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginOldName)).toBe('~' + pluginOldVersion); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.14 should save variables', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', variablePluginUrl, { - 'save': true, - 'cli_variables': { - 'APP_ID':'123456789', - 'APP_NAME':'myApplication' - } - }); - }).then(function () { - expect(helpers.getPluginVariable(appPath, variablePluginName, 'APP_ID')).toBe('123456789'); - expect(helpers.getPluginVariable(appPath, variablePluginName, 'APP_NAME')).toBe('myApplication'); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.15 save git url as spec', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', pluginGitUrl, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginName)).toBe(pluginGitUrl); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.16 should save local directory as spec', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', localPluginPath, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, localPluginName)).toBe(localPluginPath); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.16.1 save scoped registry packages as spec', function (done) { - redirectRegistryCalls(pluginName + '@' + pluginVersion); - var scopedPackage = '@test-scope/' + pluginName; - - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', scopedPackage + '@' + pluginVersion, { 'save': true }); - }).then(function () { - expect(registry.fetch).toHaveBeenCalledWith([scopedPackage + '@' + pluginVersion]); - expect(helpers.getPluginSpec(appPath, pluginName)).toBe(scopedPackage + '@~' + pluginVersion); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - }); - - describe('plugin remove --save', function () { - it('spec.17 should not add plugin to config', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', pluginName); - }).then(function () { - return cordova.raw.plugin('rm', pluginName, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginName)).toBe(null); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.18 should remove plugin from config', function (done) { - platform('add', platformLocalPathNewer) - .then(function () { - return cordova.raw.plugin('add', pluginName); - }).then(function () { - helpers.setPluginSpec(appPath, pluginName, pluginGitUrl); - return cordova.raw.plugin('rm', pluginName, { 'save': true }); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginName)).toBe(null); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - }); - - describe('platform save', function () { - it('spec.19 should not update config when there are no platforms installed', function (done) { - var configContent = helpers.getConfigContent(appPath); - platform('save') - .then(function () { - expect(helpers.getConfigContent(appPath)).toBe(configContent); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.20 should add platform to config', function (done) { - mockDownloadPlatform(platformLocalPathNew, platformVersionNew); - - platform('add', platformName + '@' + platformVersionNew) - .then(function () { - return platform('save'); - }).then(function () { - expect(helpers.getEngineSpec(appPath, platformName)).toBe('~' + platformVersionNew); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }).finally(function () { - revertDownloadPlatform(); - }); - }, TIMEOUT); - }); - - describe('plugin save', function () { - it('spec.21 should not update config when there are no plugins installed', function (done) { - var configContent = helpers.getConfigContent(appPath); - cordova.raw.plugin('save') - .finally(function () { - expect(helpers.getConfigContent(appPath)).toBe(configContent); - done(); - }); - }, TIMEOUT); - - it('spec.22 should update config with plugins: one with version, one with local folder and another one vith git url', function (done) { - cordova.raw.plugin('add', pluginName + '@' + pluginVersion) - .then(function () { - return cordova.raw.plugin('add', gitPluginUrl); - }).then(function () { - return cordova.raw.plugin('add', localPluginPath); - }).then(function () { - return cordova.raw.plugin('save'); - }).then(function () { - expect(helpers.getPluginSpec(appPath, pluginName)).toBe('~' + pluginVersion); - expect(helpers.getPluginSpec(appPath, gitPluginName)).toBe(gitPluginUrl); - expect(helpers.getPluginSpec(appPath, localPluginName)).toBe(localPluginPath); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.22.1 should update config with a spec that includes the scope for scoped plugins', function (done) { - // Fetching globalization rather than console to avoid conflicts with earlier tests - redirectRegistryCalls(pluginName2 + '@' + pluginVersion2); - var scopedPackage = '@test-scope/' + pluginName2; - cordova.raw.plugin('add', scopedPackage + '@' + pluginVersion2) - .then(function () { - return cordova.raw.plugin('save'); - }).then(function () { - expect(registry.fetch).toHaveBeenCalledWith([scopedPackage + '@' + pluginVersion2]); - expect(helpers.getPluginSpec(appPath, pluginName2)).toBe(scopedPackage + '@~' + pluginVersion2); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - }); - - describe('prepare', function () { - beforeEach(function () { - // Restore back mocked createPlatform functionality - PlatformApi.createPlatform = createPlatformOrig; - }); - - it('spec.23 should restore all platforms and plugins', function (done) { - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - helpers.setPluginSpec(appPath, localPluginName, localPluginPath); - prepare() - .then(function () { - expect(path.join(appPath, 'platforms', platformName)).toExist(); - expect(path.join(appPath, 'plugins', localPluginName)).toExist(); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.23.1 should restore scoped plugins', function (done) { - redirectRegistryCalls(pluginName2 + '@~' + pluginVersion2); - var scopedPackage = '@test-scope/' + pluginName2; - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - helpers.setPluginSpec(appPath, pluginName2, scopedPackage + '@~' + pluginVersion2); - prepare() - .then(function () { - expect(registry.fetch).toHaveBeenCalledWith([scopedPackage + '@~' + pluginVersion2]); - expect(path.join(appPath, 'plugins', pluginName2)).toExist(); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }, TIMEOUT); - - it('spec.23.2 should restore plugins without spec attribute', function (done) { - redirectRegistryCalls(pluginName2); - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - helpers.setPluginSpec(appPath, pluginName2/**, do not specify spec here */); - prepare() - .then(function () { - expect(registry.fetch).toHaveBeenCalledWith([pluginName2]); - expect(path.join(appPath, 'plugins', pluginName2)).toExist(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - }) - .fin(done); - }, TIMEOUT); - - it('spec.24 should restore only specified platform', function (done) { - helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer); - helpers.setEngineSpec(appPath, otherPlatformName, otherPlatformSpec); - var options = { - verbose: false, - platforms: [ platformName ], - options: [] - }; - prepare(options) - .then(function () { - expect(path.join(appPath, 'platforms', platformName)).toExist(); - expect(path.join(appPath, 'platforms', otherPlatformName)).not.toExist(); - done(); - }).catch(function (err) { - expect(true).toBe(false); - console.log(err.message); - done(); - }); - }); - }); - - describe('(cleanup)', function () { - it('removing temp dir', function () { - shell.rm('-rf', tempPath); - shell.rm('-rf', platformLocalPathNewer); - shell.rm('-rf', platformLocalPathNew); - shell.rm('-rf', platformLocalPathOld); - }); - }); -});