Github user audreyso commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/499#discussion_r84997132
  
    --- 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) {
    +        var pkgJsonPath = path.join(process.cwd(),'package.json');
    +        var pkgJson;
    +        var retPromise;
    --- End diff --
    
    delete reProm.... (all references to retPromise)


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to