Skip to content

CB-13057 : Remove cordova platform save command #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 6 additions & 85 deletions integration-tests/pkgJson-restore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ describe('tests platform/spec restore with --save', function () {
var cwd = process.cwd();
var pkgJsonPath = path.join(cwd, 'package.json');
var pkgJson;
var platformsFolderPath = path.join(cwd, 'platforms/platforms.json');
var platformsJson;
var configXmlPath = path.join(cwd, 'config.xml');
var bPlatform = 'browser';
var engines;
Expand All @@ -167,9 +165,6 @@ describe('tests platform/spec restore with --save', function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeDefined();
expect(pkgJson.dependencies['cordova-browser']).toEqual('git+https://github.com/apache/cordova-browser.git');
// Check that platform was added to platforms list successfully.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
expect(platformsJson[bPlatform]).toBeDefined();
}).then(function () {
// Remove platform without --save.
return cordovaPlatform('rm', bPlatform, {'fetch': true});
Expand All @@ -178,9 +173,6 @@ describe('tests platform/spec restore with --save', function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeDefined();
expect(pkgJson.dependencies['cordova-browser']).toEqual('git+https://github.com/apache/cordova-browser.git');
// Platform in platforms.json should not be there.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
expect(platformsJson[bPlatform]).toBeUndefined();
}).then(function () {
// Run cordova prepare
return prepare({'fetch': true});
Expand All @@ -200,9 +192,6 @@ describe('tests platform/spec restore with --save', function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeDefined();
expect(pkgJson.dependencies['cordova-browser']).toEqual('git+https://github.com/apache/cordova-browser.git');
// Check that platform was restored to platform.json list successfully.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
expect(platformsJson[bPlatform]).toBeDefined();
}).fail(function (err) {
expect(err).toBeUndefined();
}).fin(done);
Expand Down Expand Up @@ -327,9 +316,7 @@ describe('tests platform/spec restore with --save', function () {
var cwd = process.cwd();
var pkgJsonPath = path.join(cwd, 'package.json');
var pkgJson;
var platformsFolderPath = path.join(cwd, 'platforms/platforms.json');
var secondPlatformAdded = 'ios';
var platformsJson;

emptyPlatformList().then(function () {
// Add 'browser' platform to project without --save
Expand All @@ -340,14 +327,10 @@ describe('tests platform/spec restore with --save', function () {
}).then(function () {
// Delete any previous caches of require(package.json) and (platformsJson)
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Check the platform add of only helpers.testPlatform was successful in package.json.
expect(pkgJson.cordova.platforms).toBeDefined();
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1);
expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(-1);
// Expect both platforms to be installed platform list in platforms.json
expect(platformsJson['browser']).toBeDefined();
expect(platformsJson[secondPlatformAdded]).toBeDefined();
}).then(fullPlatformList) // Platforms should still be in platform ls.
.then(function () {
// Remove helpers.testPlatform without --save.
Expand All @@ -357,23 +340,12 @@ describe('tests platform/spec restore with --save', function () {
return cordovaPlatform('rm', secondPlatformAdded);
}).then(function () {
// Delete any previous caches of require(pkgJson) and (platformsJson)
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Check that the platform that was added with --save is still in package.json.
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1);
// Check that both platforms were removed from the platforms.json.
expect(platformsJson[secondPlatformAdded]).toBeUndefined();
expect(platformsJson['browser']).toBeUndefined();
}).then(function () {
// Run cordova prepare
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platformsJson
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Expect "helpers.testPlatform" to be in the installed platforms list.
expect(platformsJson['browser']).toBeDefined();
// Expect that 'browser' will not be in platforms.json and has not been restored.
expect(platformsJson[secondPlatformAdded]).toBeUndefined();
}).fail(function (err) {
expect(err).toBeUndefined();
}).fin(done);
Expand Down Expand Up @@ -1278,9 +1250,7 @@ describe('platforms and plugins should be restored with config.xml even without
});
var configEngArray = engNames.slice();
var configPlugins = cfg1.getPluginIdList();
var platformsFolderPath1 = path.join(cwd, 'platforms/platforms.json');
var pluginsFolderPath16 = path.join(cwd, 'plugins');
var platformsJson;
var androidPlatform = 'android';
var browserPlatform = 'windows';

Expand All @@ -1303,12 +1273,6 @@ describe('platforms and plugins should be restored with config.xml even without
});
configEngArray = engNames.slice();
expect(configEngArray.length === 2);
// Delete previouc caches of (pkg.json).
platformsJson = cordova_util.requireNoCache(platformsFolderPath1);
// Browser should be installed
expect(platformsJson).toBeDefined();
expect(platformsJson[androidPlatform]).not.toBeDefined();
expect(platformsJson[browserPlatform]).toBeDefined();
// Package.json should be auto-created.
expect(path.join(cwd, 'package.json')).toExist();
var pkgJsonPath = path.join(cwd, 'package.json');
Expand All @@ -1321,12 +1285,6 @@ describe('platforms and plugins should be restored with config.xml even without
expect(pkgJson.displayName).toEqual(cfg3.name());
// Remove android without --save.
return cordovaPlatform('rm', [browserPlatform]);
}).then(function () {
// Android should not be in the installed list (only browser).
platformsJson = cordova_util.requireNoCache(platformsFolderPath1);
expect(platformsJson).toBeDefined();
expect(platformsJson[browserPlatform]).toBeUndefined();
expect(platformsJson[androidPlatform]).not.toBeDefined();
}).then(function () {
// Run cordova prepare.
return prepare({'fetch': true});
Expand All @@ -1341,10 +1299,6 @@ describe('platforms and plugins should be restored with config.xml even without
expect(configEngArray.indexOf(androidPlatform)).toBeGreaterThan(-1);
expect(configEngArray.indexOf(browserPlatform)).toBeGreaterThan(-1);
expect(configEngArray.length === 2);
// Expect that android and browser were restored.
platformsJson = cordova_util.requireNoCache(platformsFolderPath1);
expect(platformsJson[androidPlatform]).toBeDefined();
expect(platformsJson[browserPlatform]).toBeDefined();
}).then(function () {
// Check plugins.
var cfg5 = new ConfigParser(configXmlPath);
Expand Down Expand Up @@ -1435,42 +1389,27 @@ describe('tests platform/spec restore with --save', function () {
var pkgJsonPath = path.join(cwd, 'package.json');
cordova_util.requireNoCache(pkgJsonPath);
var pkgJson;
var platformsFolderPath = path.join(cwd, 'platforms/platforms.json');
var platformsJson;

emptyPlatformList().then(function () {
// Add the testing platform with --save.
return cordovaPlatform('add', 'browser', {'save': true, 'fetch': true});
return cordovaPlatform('add', 'android', {'save': true, 'fetch': true});
}).then(function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Require platformsFolderPath
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Check the platform add was successful in package.json.
expect(pkgJson.cordova.platforms).toBeDefined();
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1);
// Expect that "helpers.testPlatform" in the installed platform list in platforms.json
expect(platformsJson).toBeDefined();
expect(platformsJson['browser']).toBeDefined();
}).then() // Platform should still be in platform ls.
expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
}).then(fullPlatformList) // Platform should still be in platform ls.
.then(function () {
// And now remove helpers.testPlatform without --save.
return cordovaPlatform('rm', ['browser']);
}).then(function () {
// Delete any previous caches of require(package.json) and (platforms.json)
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Check that the platform removed without --save is still in platforms key.
expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1);
// Check that the platform was removed from the platforms.json
expect(platformsJson['browser']).toBeUndefined();
expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
}).then(function () {
// Run cordova prepare.
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platforms.json.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Expect "helpers.testPlatform" to be in the installed platforms list in platforms.json.
expect(platformsJson['browser']).toBeDefined();
}).fail(function (err) {
expect(err).toBeUndefined();
}).fin(done);
Expand All @@ -1486,9 +1425,7 @@ describe('tests platform/spec restore with --save', function () {
var cwd = process.cwd();
var pkgJsonPath = path.join(cwd, 'package.json');
var pkgJson;
var platformsFolderPath = path.join(cwd, 'platforms/platforms.json');
var platformsJson;
var secondPlatformAdded = 'windows';
var secondPlatformAdded = 'browser';

emptyPlatformList().then(function () {
// Add the testing platform with --save.
Expand All @@ -1499,15 +1436,10 @@ describe('tests platform/spec restore with --save', function () {
}).then(function () {
// Delete any previous caches of require(package.json) and (platforms.json).
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Check the platform add of both platforms (to pkg.Json) was successful.
expect(pkgJson.cordova.platforms).toBeDefined();
expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(0);
expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(1);
// Expect that "helpers.testPlatform" in the installed platform list in platforms.json.
expect(platformsJson).toBeDefined();
expect(platformsJson[helpers.testPlatform]).toBeDefined();
expect(platformsJson[secondPlatformAdded]).toBeDefined();
}).then(fullPlatformList) // Platform should still be in platform ls.
.then(function () {
// Remove helpers.testPlatform with --save.
Expand All @@ -1516,25 +1448,14 @@ describe('tests platform/spec restore with --save', function () {
// Remove secondPlatformAdded without --save.
return cordovaPlatform('rm', secondPlatformAdded);
}).then(function () {
// Delete any previous caches of require(package.json) and (platformsJson).
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Delete any previous caches of require(package.json)
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Check that ONLY the platform removed without --save is still in (pkg.json) platforms key.
expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(0);
expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(-1);
// Check that both platforms were removed from the platforms.json list.
expect(platformsJson[helpers.testPlatform]).toBeUndefined();
expect(platformsJson[secondPlatformAdded]).toBeUndefined();
}).then(function () {
// Run cordova prepare.
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platformsJson.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Expect "helpers.testPlatform" to be in the installed platforms list in platforms.json
expect(platformsJson[helpers.testPlatform]).toBeUndefined();
// Expect 'browser' not to be in platforms.json and has not been restored.
expect(platformsJson[secondPlatformAdded]).toBeDefined();
}).fail(function (err) {
expect(err).toBeUndefined();
}).fin(done);
Expand Down
8 changes: 0 additions & 8 deletions integration-tests/pkgJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,13 @@ describe('During add, if pkg.json has a platform/plugin spec, use that one.', fu
var iosVersion;
var cwd = process.cwd();
var iosDirectory = path.join(cwd, 'platforms/ios/cordova/version');
var platformsFolderPath = path.join(cwd, 'platforms/platforms.json');
var configXmlPath = path.join(cwd, 'config.xml');
var pkgJsonPath = path.join(cwd, 'package.json');
var pkgJson = cordova_util.requireNoCache(pkgJsonPath);
var cfg = new ConfigParser(configXmlPath);
var engines = cfg.getEngines();
var engNames;
var engSpec; // eslint-disable-line no-unused-vars
var platformsJson;
var configPlugins = cfg.getPluginIdList();
var pluginPkgJsonDir = path.join(cwd, 'plugins/cordova-plugin-splashscreen/package.json');
var pluginPkgJsonVersion;
Expand All @@ -645,8 +643,6 @@ describe('During add, if pkg.json has a platform/plugin spec, use that one.', fu
// Add ios with --save and --fetch.
return cordova.platform('add', [iosPlatform], {'save': true, 'fetch': true});
}).then(function () {
// Require platformsFolderPath, ios and spec should be in there.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
// Delete any previous caches of require(package.json).
// ios has been added.
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand All @@ -666,15 +662,11 @@ describe('During add, if pkg.json has a platform/plugin spec, use that one.', fu
// Check that config and ios/cordova/version versions "satify" each other.
iosVersion = cordova_util.requireNoCache(iosDirectory);
expect(semver.satisfies(iosVersion.version, elem.spec)).toEqual(true);
// Check that config and platforms.json "satisfy".
expect(semver.satisfies(platformsJson[iosPlatform], elem.spec)).toEqual(true);
});
// Config.xml added ios platform.
expect(engNames).toEqual([ 'ios' ]);
// Check that pkg.json and ios/cordova/version versions "satisfy" each other.
expect(semver.satisfies(iosVersion.version, pkgJson.dependencies['cordova-ios'])).toEqual(true);
// Check that pkg.json and platforms.json "satisfy".
expect(semver.satisfies(platformsJson[iosPlatform], pkgJson.dependencies['cordova-ios'])).toEqual(true);
}).then(function () {
// Add splashscreen plugin with --save --fetch.
return cordova.plugin('add', 'cordova-plugin-splashscreen', {'save': true, 'fetch': true});
Expand Down
11 changes: 0 additions & 11 deletions spec/cordova/platform/addHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var events = require('cordova-common').events;
var rewire = require('rewire');
var platform_addHelper = rewire('../../../src/cordova/platform/addHelper');
var platform_module = require('../../../src/cordova/platform');
var platform_metadata = require('../../../src/cordova/platform_metadata');
var cordova_util = require('../../../src/cordova/util');
var cordova_config = require('../../../src/cordova/config');
var plugman = require('../../../src/plugman/plugman');
Expand Down Expand Up @@ -88,7 +87,6 @@ describe('cordova/platform/addHelper', function () {
platform_api_mock.createPlatform.and.returnValue(Q());
platform_api_mock.updatePlatform.and.returnValue(Q());
spyOn(cordova_util, 'getPlatformApiFunction').and.returnValue(platform_api_mock);
spyOn(platform_metadata, 'save');
spyOn(cordova_util, 'requireNoCache').and.returnValue({});
});
afterEach(function () {
Expand Down Expand Up @@ -261,15 +259,6 @@ describe('cordova/platform/addHelper', function () {
}).done(done);
});

it('should save the platform metadata', function (done) {
platform_addHelper('add', hooks_mock, projectRoot, ['atari'], {save: true, fetch: true, restoring: true}).then(function (result) {
expect(platform_metadata.save).toHaveBeenCalledWith('/some/path', 'atari', undefined);
}).fail(function (err) {
fail('unexpected failure handler invoked!');
console.error(err);
}).done(done);
});

it('should write out the version of platform just added/updated to config.xml if the save option is provided', function (done) {
platform_addHelper('add', hooks_mock, projectRoot, ['ios'], {save: true, restoring: true}).then(function (result) {
expect(cfg_parser_mock.prototype.removeEngine).toHaveBeenCalled();
Expand Down
Loading