Skip to content

Commit

Permalink
CB-13057: updated based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso committed Dec 13, 2017
1 parent 64c63c8 commit df6f0a9
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 373 deletions.
79 changes: 1 addition & 78 deletions integration-tests/pkgJson-restore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,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 @@ -169,9 +167,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 @@ -180,9 +175,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 @@ -202,9 +194,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 @@ -330,9 +319,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 = 'browser';
//var platformsJson;

emptyPlatformList().then(function () {
// Add 'browser' platform to project without --save
Expand All @@ -343,14 +330,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(helpers.testPlatform)).toBeGreaterThan(-1);
expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(-1);
// Expect both platforms to be installed platform list in platforms.json
//expect(platformsJson[helpers.testPlatform]).toBeDefined();
//expect(platformsJson[secondPlatformAdded]).toBeDefined();
}).then(fullPlatformList) // Platforms should still be in platform ls.
.then(function () {
// Remove helpers.testPlatform without --save.
Expand All @@ -360,23 +343,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(helpers.testPlatform)).toBeGreaterThan(-1);
// Check that both platforms were removed from the platforms.json.
//expect(platformsJson[secondPlatformAdded]).toBeUndefined();
//expect(platformsJson[helpers.testPlatform]).toBeUndefined();
}).then(function () {
// Run cordova prepare
return prepare();
}).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[helpers.testPlatform]).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 @@ -1281,9 +1253,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 @@ -1306,12 +1276,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 @@ -1324,12 +1288,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 @@ -1344,10 +1302,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 @@ -1438,42 +1392,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', 'android', {'save': 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(helpers.testPlatform)).toBeGreaterThan(-1);
// Expect that "helpers.testPlatform" in the installed platform list in platforms.json
//expect(platformsJson).toBeDefined();
//expect(platformsJson[helpers.testPlatform]).toBeDefined();
}).then(fullPlatformList) // Platform should still be in platform ls.
.then(function () {
// And now remove helpers.testPlatform without --save.
return cordovaPlatform('rm', [helpers.testPlatform]);
}).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(helpers.testPlatform)).toBeGreaterThan(-1);
// Check that the platform was removed from the platforms.json
//expect(platformsJson[helpers.testPlatform]).toBeUndefined();
}).then(function () {
// Run cordova prepare.
return prepare();
}).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[helpers.testPlatform]).toBeDefined();
}).fail(function (err) {
expect(err).toBeUndefined();
}).fin(done);
Expand All @@ -1500,15 +1439,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 @@ -1517,25 +1451,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();
}).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 @@ -90,7 +89,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 @@ -263,15 +261,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
10 changes: 0 additions & 10 deletions spec/cordova/platform/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,6 @@ describe('cordova/platform', function () {
fail('did not expect fail handler to be invoked');
}).done(done);
});
// it('should direct `save` commands to the `save` method/module', function (done) {
// spyOn(platform, 'save').and.returnValue(true);
// platform('save', ['android'])
// .then(function () {
// expect(platform.save).toHaveBeenCalled();
// }).fail(function (e) {
// expect(e).toBeUndefined();
// fail('did not expect fail handler to be invoked');
// }).done(done);
// });
it('should direct `list`, all other commands and no command at all to the `list` method/module', function (done) {
spyOn(platform, 'list').and.returnValue(true);
// test the `list` command directly
Expand Down
Loading

0 comments on commit df6f0a9

Please sign in to comment.