Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A07AE200BB7 for ; Wed, 26 Oct 2016 00:46:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9F2E2160AFA; Tue, 25 Oct 2016 22:46:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C50C9160AD8 for ; Wed, 26 Oct 2016 00:46:42 +0200 (CEST) Received: (qmail 73253 invoked by uid 500); 25 Oct 2016 22:46:40 -0000 Mailing-List: contact dev-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 dev@cordova.apache.org Received: (qmail 72510 invoked by uid 99); 25 Oct 2016 22:46:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2016 22:46:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 760B4EF79F; Tue, 25 Oct 2016 22:46:39 +0000 (UTC) From: audreyso To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request #499: Cb 11960 Content-Type: text/plain Message-Id: <20161025224639.760B4EF79F@git1-us-west.apache.org> Date: Tue, 25 Oct 2016 22:46:39 +0000 (UTC) archived-at: Tue, 25 Oct 2016 22:46:43 -0000 Github user audreyso commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/499#discussion_r85011104 --- Diff: cordova-lib/spec-cordova/package.json.spec.js --- @@ -0,0 +1,389 @@ +/** + 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, + Q = require('q'), + events = require('cordova-common').events, + cordova = require('../src/cordova/cordova'), + rewire = require('rewire'), + prepare = require('../src/cordova/prepare'), + platforms = require('../src/platforms/platforms'), + platform = rewire('../src/cordova/platform.js'); + +var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker'; +var pluginsDir = path.join(__dirname, 'fixtures', 'plugins'); + +function addPlugin(target, id, options) { + // Checks that there are no plugins yet. + return cordova.raw.plugin('list').then(function() { + expect(results).toMatch(/No plugins added/gi); + }).then(function() { + // Adds 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, options) { + 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); + }); +} +// Checks if plugin list is empty. +function emptyPluginList() { + return cordova.raw.plugin('list').then(function() { + var installed = results.match(/Installed plugins:\n (.*)/); + expect(installed).toBeDefined(); + expect(installed[1].indexOf('fake-plugin')).toBe(-1); + }); +} +// Checks if plugin list exists. +function fullPluginList() { + return cordova.raw.plugin('list').then(function() { + var installed = results.match(/Installed plugins:\n (.*)/); + expect(installed).toBeDefined(); + expect(installed[1].indexOf('fake-plugin')).toBeGreaterThan(-1); + }); +} + +// This group of tests checks if plugins are added and removed as expected. +describe('plugin end-to-end', function() { + var pluginId = 'cordova-plugin-device'; + var tmpDir = helpers.tmpDir('platform_test_pkgjson'); + var project = path.join(tmpDir, 'project'); + var results; + + events.on('results', function(res) { results = res; }); + + beforeEach(function() { + shell.rm('-rf', project); + + // Copy then move because we need to copy everything, but that means it will copy the whole directory. + // Using /* doesn't work because of hidden files. + shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson'), tmpDir); + shell.mv(path.join(tmpDir, 'basePkgJson'), 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); + + delete process.env.PWD; + + spyOn(prepare, 'preparePlatforms').andCallThrough(); + }); + + afterEach(function() { + process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows. + shell.rm('-rf', tmpDir); + }); + + it('Test#001 : should successfully add and remove a plugin with no options', function(done) { + var pkgJsonPath = path.join(process.cwd(),'package.json'); + var pkgJson; + var retPromise; + + expect(pkgJsonPath).toExist(); + + // Add the plugin with --save + return cordova.raw.plugin('add', pluginId, {'save':true}) + .then(function() { + // Check that the plugin add was successful. + delete require.cache[require.resolve(pkgJsonPath)]; + pkgJson = require(pkgJsonPath); + expect(pkgJson).not.toBeUndefined(); + expect(pkgJson.cordova.plugins).not.toBeUndefined(); + expect(pkgJson.cordova.plugins[pluginId]).toBeDefined(); + }).then(function() { + // And now remove it with --save. + return cordova.raw.plugin('rm', pluginId, {'save':true}) + }).then(function() { + // Delete any previous caches of require(package.json) + delete require.cache[require.resolve(pkgJsonPath)]; + pkgJson = require(pkgJsonPath); + // Checking that the plugin removed is in not in the platforms + expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined(); + }).fail(function(err) { + expect(err).toBeUndefined(); + }).fin(done); + }); + + it('Test#002 : should successfully NOT add a plugin if save is not there', function(done) { + var pkgJsonPath = path.join(process.cwd(),'package.json'); + var pkgJson; + + expect(pkgJsonPath).toExist(); + + // Add the plugin with --save. + return cordova.raw.plugin('add', 'cordova-plugin-camera', {'save':true}) + .then(function() { + // Add a second plugin without save + return cordova.raw.plugin('add', pluginId); + }).then(function() { + // Check the plugin add was successful for the first plugin that had --save. + delete require.cache[require.resolve(pkgJsonPath)]; + pkgJson = require(pkgJsonPath); + expect(pkgJson).not.toBeUndefined(); + expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toBeDefined(); + // Expect that the second plugin is not added. + expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined(); + }).fail(function(err) { + expect(err).toBeUndefined(); + }).fin(done); + }); + + it('Test#003 : should NOT remove plugin if there is no --save', function(done) { --- End diff -- done --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org