chore: drop q module (#833)

* chore: drop q module
* chore: fix & complete dropping q
* Fix faulty transformation of Q.when
* Simplify thenResolve transformation
  * Removes unnecesary Promise wrapping in onFulfilled callback.
* Transform .done calls to .then or .catch
  * The important thing is that we always handle rejections.
* Remove Q from specs
Requires Jasmine 3.5
* Replace Q.timeout w/ Promise.race & custom function

Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
This commit is contained in:
エリス
2020-01-07 21:22:59 +09:00
committed by GitHub
parent fd57909730
commit 0e6ad28e56
19 changed files with 68 additions and 69 deletions
+2 -3
View File
@@ -17,7 +17,6 @@
under the License.
*/
var Q = require('q');
var os = require('os');
var path = require('path');
var common = require('cordova-common');
@@ -38,13 +37,13 @@ describe('addPlugin method', function () {
Api = rewire('../../bin/templates/cordova/Api');
var pluginManager = jasmine.createSpyObj('pluginManager', ['addPlugin']);
pluginManager.addPlugin.and.returnValue(Q());
pluginManager.addPlugin.and.resolveTo();
spyOn(common.PluginManager, 'get').and.returnValue(pluginManager);
var projectSpy = jasmine.createSpyObj('AndroidProject', ['getPackageName', 'write', 'isClean']);
spyOn(AndroidProject, 'getProjectFile').and.returnValue(projectSpy);
Api.__set__('Api.prototype.clean', Q);
Api.__set__('Api.prototype.clean', async () => {});
// Prevent logging to avoid polluting the test reports
Api.__set__('selfEvents.emit', jasmine.createSpy());
+1 -1
View File
@@ -201,7 +201,7 @@ describe('ProjectBuilder', () => {
const testError = 'failed to find target with hash string';
ProjectBuilder.__set__('check_reqs', checkReqsSpy);
checkReqsSpy.check_android_target.and.returnValue(Promise.resolve());
checkReqsSpy.check_android_target.and.resolveTo();
execaSpy.and.rejectWith(testError);
return builder.build({}).then(
+4 -9
View File
@@ -22,7 +22,6 @@ var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
var shelljs = require('shelljs');
var fs = require('fs');
var path = require('path');
var Q = require('q');
describe('check_reqs', function () {
var original_env;
@@ -51,7 +50,7 @@ describe('check_reqs', function () {
process.env.ProgramFiles = 'windows-program-files';
return check_reqs.check_android().then(function () {
expect(process.env.ANDROID_HOME).toContain('windows-local-app-data');
}).fin(function () {
}).finally(function () {
delete process.env.LOCALAPPDATA;
delete process.env.ProgramFiles;
});
@@ -62,7 +61,7 @@ describe('check_reqs', function () {
process.env.HOME = 'home is where the heart is';
return check_reqs.check_android().then(function () {
expect(process.env.ANDROID_HOME).toContain('home is where the heart is');
}).fin(function () {
}).finally(function () {
delete process.env.HOME;
});
});
@@ -186,10 +185,8 @@ describe('check_reqs', function () {
});
describe('check_android_target', function () {
it('should should return full list of supported targets if there is a match to ideal api level', () => {
var deferred = Q.defer();
spyOn(android_sdk, 'list_targets').and.returnValue(deferred.promise);
var fake_targets = ['you are my fire', 'my one desire'];
deferred.resolve(fake_targets);
spyOn(android_sdk, 'list_targets').and.resolveTo(fake_targets);
spyOn(check_reqs, 'get_target').and.returnValue('you are my fire');
return check_reqs.check_android_target().then(function (targets) {
expect(targets).toBeDefined();
@@ -197,10 +194,8 @@ describe('check_reqs', function () {
});
});
it('should error out if there is no match between ideal api level and installed targets', () => {
var deferred = Q.defer();
spyOn(android_sdk, 'list_targets').and.returnValue(deferred.promise);
var fake_targets = ['you are my fire', 'my one desire'];
deferred.resolve(fake_targets);
spyOn(android_sdk, 'list_targets').and.resolveTo(fake_targets);
spyOn(check_reqs, 'get_target').and.returnValue('and i knowwwwwwwwwwww');
return check_reqs.check_android_target().then(() => {
fail('Expected promise to be rejected');
+2 -3
View File
@@ -22,7 +22,6 @@ var create = rewire('../../bin/lib/create');
var check_reqs = require('../../bin/templates/cordova/lib/check_reqs');
var fs = require('fs');
var path = require('path');
var Q = require('q');
var shell = require('shelljs');
describe('create', function () {
@@ -129,8 +128,8 @@ describe('create', function () {
Manifest_mock.prototype.setPackageId.and.returnValue(new Manifest_mock());
Manifest_mock.prototype.getActivity.and.returnValue(new Manifest_mock());
Manifest_mock.prototype.setName.and.returnValue(new Manifest_mock());
spyOn(create, 'validatePackageName').and.returnValue(Q());
spyOn(create, 'validateProjectName').and.returnValue(Q());
spyOn(create, 'validatePackageName').and.resolveTo();
spyOn(create, 'validateProjectName').and.resolveTo();
spyOn(create, 'setShellFatal').and.callFake(function (noop, cb) { cb(); });
spyOn(create, 'copyJsAndLibrary');
spyOn(create, 'copyScripts');
+1 -1
View File
@@ -171,7 +171,7 @@ describe('run', () => {
return run.run().then(
() => fail('Expected error to be thrown'),
err => expect(err).toContain(target)
err => expect(err.message).toContain(target)
);
});