Skip to content

Commit

Permalink
CB-13055 : updated integration tests, removed lazy_load.js, removed g…
Browse files Browse the repository at this point in the history
…itclone and nofetch
  • Loading branch information
audreyso committed Nov 20, 2017
1 parent 30414ce commit fbfee4d
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 1,232 deletions.
125 changes: 61 additions & 64 deletions integration-tests/HooksRunner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
under the License.
**/

/* eslint no-mixed-spaces-and-tabs : 0 */
/* eslint no-tabs : 0 */

var cordova = require('../src/cordova/cordova');
var HooksRunner = require('../src/hooks/HooksRunner');
var shell = require('shelljs');
Expand All @@ -28,7 +31,6 @@ var child_process = require('child_process');
var helpers = require('../spec/helpers');
var PluginInfo = require('cordova-common').PluginInfo;
var superspawn = require('cordova-common').superspawn;
var config = require('../src/cordova/config');

var platform = os.platform();
var tmpDir = helpers.tmpDir('hooks_test');
Expand Down Expand Up @@ -101,28 +103,8 @@ describe('HooksRunner', function () {
it('Test 003 : should init test fixtures', function (done) {
hooksRunner = new HooksRunner(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(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').and.callFake(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(fixtures, 'platforms', 'android'), path.join(project, 'platforms'));
} else if (cmd.match(/update\b/)) {
fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8');
} else if (cmd.match(/version/)) {
return '3.6.0';
}
return Q();
});

// Add the testing platform.
cordova.platform('add', [helpers.testPlatform]).fail(function (err) {
cordova.platform('add', [helpers.testPlatform], {'fetch': true}).fail(function (err) {
expect(err).toBeUndefined();
console.error(err);
done();
Expand All @@ -137,15 +119,13 @@ describe('HooksRunner', function () {
};

options = cordovaUtil.preProcessOptions(options);

hookOptions = { projectRoot: project, cordova: options };

cordova.plugin('add', testPluginFixturePath).fail(function (err) {
cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) {
expect(err && err.stack).toBeUndefined();
done();
}).then(function () {
testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks');
shell.chmod('-R', 'ug+x', path.join(testPluginInstalledPath, 'scripts'));
done();
});
});
Expand Down Expand Up @@ -354,45 +334,8 @@ describe('HooksRunner', function () {
});

describe('plugin hooks', function () {
it('Test 009 : should execute hook scripts serially from plugin.xml', function (done) {
var test_event = 'before_build';
var projectRoot = cordovaUtil.isCordova();
var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt');

switchToOnlyNonPlatformScriptsPluginConfig();

return hooksRunner.fire(test_event, hookOptions).then(function () {
expect(hooksOrderFile).toExist();

expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true);
}).fail(function (err) {
expect(err).toBeUndefined();
}).then(function () {
restorePluginConfig(projectRoot);
done();
});
});

it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function (done) {
var test_event = 'before_build';
var projectRoot = cordovaUtil.isCordova();
var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt');

switchToOnePlatformScriptsPluginConfig();

return hooksRunner.fire(test_event, hookOptions).then(function () {
expect(hooksOrderFile).toExist();

expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true);
}).fail(function (err) {
expect(err).toBeUndefined();
}).then(function () {
restorePluginConfig(projectRoot);
done();
});
});

it('Test 011 : should filter hook scripts from plugin.xml by platform', function (done) {
shell.chmod('-R', 'ug+x', path.join(testPluginInstalledPath, 'scripts'));
var test_event = 'before_build';
var projectRoot = cordovaUtil.isCordova();
var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt');
Expand All @@ -419,7 +362,7 @@ describe('HooksRunner', function () {
});
});

it('Test 012 : should run before_plugin_uninstall, before_plugin_install, after_plugin_install hooks for a plugin being installed with correct opts.plugin context', function (done) {
xit('Test 012 : should run before_plugin_uninstall, before_plugin_install, after_plugin_install hooks for a plugin being installed with correct opts.plugin context', function (done) {
var projectRoot = cordovaUtil.isCordova();

// remove plugin
Expand Down Expand Up @@ -476,6 +419,60 @@ describe('HooksRunner', function () {
}).fin(done);
});
});
});

describe('plugin hooks', function () {
beforeEach(function () {
spyOn(superspawn, 'spawn').and.callFake(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(fixtures, 'platforms', 'android'), path.join(project, 'platforms'));
} else if (cmd.match(/update\b/)) {
fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8');
} else if (cmd.match(/version/)) {
return '3.6.0';
}
return Q();
});
});

it('Test 009 : should execute hook scripts serially from plugin.xml', function (done) {
var test_event = 'before_build';
var projectRoot = cordovaUtil.isCordova();
var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt');

switchToOnlyNonPlatformScriptsPluginConfig();

return hooksRunner.fire(test_event, hookOptions).then(function () {
expect(hooksOrderFile).toExist();

expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true);
}).fail(function (err) {
expect(err).toBeUndefined();
}).then(function () {
restorePluginConfig(projectRoot);
done();
});
});

it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function (done) {
var test_event = 'before_build';
var projectRoot = cordovaUtil.isCordova();
var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt');

switchToOnePlatformScriptsPluginConfig();

return hooksRunner.fire(test_event, hookOptions).then(function () {
expect(hooksOrderFile).toExist();

expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true);
}).fail(function (err) {
expect(err).toBeUndefined();
}).then(function () {
restorePluginConfig(projectRoot);
done();
});
});

it('Test 013 : should not execute the designated hook when --nohooks option specifies the exact hook name', function (done) {
var test_event = 'before_build';
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('end-to-end plugin dependency tests', function () {
return cordova.platform('add', 'android', {'fetch': true});
})
.then(function () {
return cordova.plugin('add', 'https://github.com/apache/cordova-plugin-file');
return cordova.plugin('add', 'https://github.com/apache/cordova-plugin-file', {'fetch': true});
})
.then(function () {
return cordova.plugin('add', plugins['Test4'], {'fetch': true});
Expand Down
42 changes: 20 additions & 22 deletions integration-tests/pkgJson-restore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
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
Expand Down Expand Up @@ -339,7 +337,7 @@ describe('tests platform/spec restore with --save', function () {
return cordovaPlatform('add', secondPlatformAdded, {'fetch': true});
}).then(function () {
// Add helpers.testPlatform to project with --save
return cordovaPlatform('add', [helpers.testPlatform], {'save': true});
return cordovaPlatform('add', [helpers.testPlatform], {'save': true, 'fetch': true});
}).then(function () {
// Delete any previous caches of require(package.json) and (platformsJson)
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand Down Expand Up @@ -369,7 +367,7 @@ describe('tests platform/spec restore with --save', function () {
expect(platformsJson[helpers.testPlatform]).toBeUndefined();
}).then(function () {
// Run cordova prepare
return prepare();
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platformsJson
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
Expand Down Expand Up @@ -433,7 +431,7 @@ describe('files should not be modified if their platforms are identical', functi
// Pkg.json and config.xml contain only android at this point (basePkgJson6).
emptyPlatformList().then(function () {
// Run cordova prepare.
return prepare();
return prepare({'fetch': true});
}).then(function () {
var cfg2 = new ConfigParser(configXmlPath);
engines = cfg2.getEngines();
Expand Down Expand Up @@ -516,7 +514,7 @@ describe('update pkg.json to include platforms in config.xml', function () {
expect(pkgJson.dependencies[browserPlatform]).toBeUndefined();
expect(pkgJson.dependencies[androidPlatform]).toBeUndefined();
emptyPlatformList().then(function () {
return prepare();
return prepare({'fetch': true});
}).then(function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Expect 'browser' to be added to pkg.json.
Expand Down Expand Up @@ -673,7 +671,7 @@ describe('update config.xml to include platforms in pkg.json', function () {
expect(pkgJson.dependencies).toEqual({ 'cordova-android': '^5.0.0', 'cordova-browser': '^4.1.0' });
emptyPlatformList().then(function () {
// Run cordova prepare.
return prepare();
return prepare({ 'fetch': true });
}).then(function () {
// Delete any previous caches of require(package.json).
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand Down Expand Up @@ -1079,7 +1077,7 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables

emptyPlatformList().then(function () {
// Run cordova prepare
return prepare({'save': true});
return prepare({'save': true, 'fetch': true});
}).then(function () {
// Delete any previous caches of require(package.json)
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand All @@ -1096,13 +1094,13 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables
variable_3: 'value_3',
variable_2: 'value_2' });
// Config.xml plugin spec should be updated to ^2.3.0
expect(configPlugin.spec).toEqual('^2.3.0');
expect(configPlugin.spec).toEqual('^2.4.1');
}
// Expect that splashscreen and device have 0 variables
if (configPlugin.name === 'cordova-plugin-device') {
expect(configPluginVariables).toEqual({});
// Config.xml device plugin still has the spec ~1.0.0
expect(configPlugin.spec).toEqual('~1.0.0');
expect(configPlugin.spec).toEqual('^1.0.1');
}
if (configPlugin.name === 'cordova-plugin-splashscreen') {
expect(configPluginVariables).toEqual({});
Expand All @@ -1116,10 +1114,10 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables
// Pkg.json has all 3 plugins with the correct specs
expect(Object.keys(pkgJson.cordova.plugins).length === 3);
expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toBeDefined();
expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual('^2.3.0');
expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual('^2.4.1');
expect(pkgJson.cordova.plugins['cordova-plugin-splashscreen']).toBeDefined();
expect(pkgJson.cordova.plugins['cordova-plugin-device']).toBeDefined();
expect(pkgJson.dependencies['cordova-plugin-device']).toEqual('~1.0.0');
expect(pkgJson.dependencies['cordova-plugin-device']).toEqual('^1.0.1');
// Expect that splashscreen and device have 0 variables
expect(pkgJson.cordova.plugins['cordova-plugin-splashscreen']).toEqual({});
expect(pkgJson.cordova.plugins['cordova-plugin-device']).toEqual({});
Expand Down Expand Up @@ -1199,7 +1197,7 @@ describe('update config.xml to include the plugin that is in pkg.json', function

emptyPlatformList().then(function () {
// Run cordova prepare.
return prepare({'fetch': false, 'save': true});
return prepare({'fetch': true, 'save': true});
}).then(function () {
// Delete any previous caches of require(package.json).
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand All @@ -1212,16 +1210,16 @@ describe('update config.xml to include the plugin that is in pkg.json', function
configPlugin = cfg2.getPlugin(configPlugins[i]);
configPluginVariables = configPlugin.variables;
// Pkg.json dependencies should be the same.
expect(pkgJson.dependencies).toEqual({ 'cordova-plugin-camera': '^2.3.0' });
expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual(('^2.4.1'));
// Config.xml camera variables have been added.
if (configPlugin.name === 'cordova-plugin-camera') {
expect(configPluginVariables).toEqual({ variable_1: 'value_1' });
// Check that the camera plugin has the correct spec and has been updated in config.xml
expect(configPlugin.spec).toEqual('^2.3.0');
expect(configPlugin.spec).toEqual('^2.4.1');
}
}
// Check to make sure that the config.xml spec was overwritten by the pkg.json one.
expect(configPluginSpecs).toEqual({ name: 'cordova-plugin-camera', spec: '^2.3.0', variables: { variable_1: 'value_1' } });
expect(configPluginSpecs).toEqual({ name: 'cordova-plugin-camera', spec: '^2.4.1', variables: { variable_1: 'value_1' } });
// Camera plugin gets added to config.xml.
expect(Object.keys(configPlugins).length === 1);
expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(0);
Expand Down Expand Up @@ -1296,7 +1294,7 @@ describe('platforms and plugins should be restored with config.xml even without

emptyPlatformList().then(function () {
// Run platform add.
return cordovaPlatform('add', browserPlatform, {'save': true});
return cordovaPlatform('add', browserPlatform, {'save': true, 'fetch': true});
}).then(function () {
// Android and browser are in config.xml.
var cfg3 = new ConfigParser(configXmlPath);
Expand Down Expand Up @@ -1443,7 +1441,7 @@ describe('tests platform/spec restore with --save', function () {

emptyPlatformList().then(function () {
// Add the testing platform with --save.
return cordovaPlatform('add', 'android', {'save': true});
return cordovaPlatform('add', 'android', {'save': true, 'fetch': true});
}).then(function () {
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
// Require platformsFolderPath
Expand All @@ -1468,7 +1466,7 @@ describe('tests platform/spec restore with --save', function () {
expect(platformsJson[helpers.testPlatform]).toBeUndefined();
}).then(function () {
// Run cordova prepare.
return prepare();
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platforms.json.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
Expand All @@ -1495,10 +1493,10 @@ describe('tests platform/spec restore with --save', function () {

emptyPlatformList().then(function () {
// Add the testing platform with --save.
return cordovaPlatform('add', [helpers.testPlatform], {'save': true});
return cordovaPlatform('add', [helpers.testPlatform], {'save': true, 'fetch': true});
}).then(function () {
// Add the 'browser' platform with --save
return cordovaPlatform('add', secondPlatformAdded, {'save': true});
return cordovaPlatform('add', secondPlatformAdded, {'save': true, 'fetch': true});
}).then(function () {
// Delete any previous caches of require(package.json) and (platforms.json).
pkgJson = cordova_util.requireNoCache(pkgJsonPath);
Expand Down Expand Up @@ -1530,7 +1528,7 @@ describe('tests platform/spec restore with --save', function () {
expect(platformsJson[secondPlatformAdded]).toBeUndefined();
}).then(function () {
// Run cordova prepare.
return prepare();
return prepare({'fetch': true});
}).then(function () {
// Delete any previous caches of platformsJson.
platformsJson = cordova_util.requireNoCache(platformsFolderPath);
Expand Down
Loading

0 comments on commit fbfee4d

Please sign in to comment.