Skip to content
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

CB:13055- remove --nofetch option and all old fetching code #608

Closed
wants to merge 9 commits into from
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 Down Expand Up @@ -426,7 +369,7 @@ describe('HooksRunner', function () {
cordova.plugin('rm', 'com.plugin.withhooks').fail(function (err) {
expect(err.stack).toBeUndefined();
}).then(function () {
cordova.plugin('add', testPluginFixturePath).fail(function (err) {
cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) {
expect(err).toBeUndefined();
}).then(function () {
testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks');
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
Loading