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

Properly handle promise in create script #784

Merged
merged 2 commits into from
Jul 17, 2019

Conversation

raphinesse
Copy link
Contributor

This seemingly fixed a spurious error in spec/unit/create.spec.js that was occurring on my system.

Copy link
Contributor

@brodycj brodycj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a tiny suggestion (don’t know if my suggestion makes any sense or not)

P.S. I do find it really interesting that the tests, including the validateProjectName failure tests, did pass with this promise not properly handled. I am suspecting that this would not have been the case when using standard JavaScript promises.

bin/lib/create.js Show resolved Hide resolved
@raphinesse
Copy link
Contributor Author

I do find it really interesting that the tests, including the validateProjectName failure tests, did pass with this promise not properly handled. I am suspecting that this would not have been the case when using standard JavaScript promises.

The validateProjectName failure tests never execute that code. It's part of exports.create. The tests for exports.create OTOH stub validateProjectName and only verify that it has been called. So this couldn't have failed any of the existing tests.

@brodycj
Copy link
Contributor

brodycj commented Jul 17, 2019

The validateProjectName failure tests never execute that code. It's part of exports.create. The tests for exports.create OTOH stub validateProjectName and only verify that it has been called. So this couldn't have failed any of the existing tests.

Hmm, I think we should add a test to cover this case.

If I would ignore this PR and inject the following change onto the master branch in my workarea:

diff --git a/bin/lib/create.js b/bin/lib/create.js
index 2fa457fa..623b655b 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -273,6 +273,7 @@ exports.create = function (project_path, config, options, events) {
     return exports.validatePackageName(package_name)
         .then(function () {
             exports.validateProjectName(project_name);
+            return Q.resolve();
         }).then(function () {
         // Log the given values for the project
             events.emit('log', 'Creating Cordova project for the Android platform:');

then npm test seems to succeed for me. What do you think?

Extra P.S. (unrelated): With the following cleanup changes, npm test passes for me back to Node.js 6:

diff --git a/bin/lib/create.js b/bin/lib/create.js
index 3c4b8373..2cc0726d 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -271,9 +271,8 @@ exports.create = function (project_path, config, options, events) {
 
     // Make the package conform to Java package types
     return exports.validatePackageName(package_name)
-        .then(function () {
-            return exports.validateProjectName(project_name);
-        }).then(function () {
+        .then(() => (exports.validateProjectName(project_name)))
+        .then(() => {
         // Log the given values for the project
             events.emit('log', 'Creating Cordova project for the Android platform:');
             events.emit('log', '\tPath: ' + project_path);

@raphinesse
Copy link
Contributor Author

I didn't quite get your comment but I have added a regression test.

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@brodycj brodycj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@raphinesse raphinesse merged commit 1de7c38 into apache:master Jul 17, 2019
@raphinesse raphinesse deleted the create-fix branch July 17, 2019 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants