You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/07/02 21:34:21 UTC

[GitHub] [cordova-android] raphinesse opened a new pull request #1013: test(pluginHandlers/common): better setup & teardown

raphinesse opened a new pull request #1013:
URL: https://github.com/apache/cordova-android/pull/1013


   ### Motivation and Context
   <!-- Why is this change required? What problem does it solve? -->
   <!-- If it fixes an open issue, please link to the issue here. -->
   - test file setup was overly verbose
   - teardown was faulty (exceptions in tests could lead to files being left behind)
   - I wanted to add a regression test to the suite
   
   ### Description
   <!-- Describe your changes in detail -->
   - use `fs.outputFileSync` to create files and their parent dirs
   - use `afterEach` to relaibly clan up after tests
   
   
   ### Testing
   <!-- Please describe in detail how you tested your changes. -->
   Affected unit tests still pass
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] raphinesse commented on a change in pull request #1013: test(pluginHandlers/common): better setup & teardown

Posted by GitBox <gi...@apache.org>.
raphinesse commented on a change in pull request #1013:
URL: https://github.com/apache/cordova-android/pull/1013#discussion_r450981059



##########
File path: spec/unit/pluginHandlers/common.spec.js
##########
@@ -35,38 +36,39 @@ var deleteJava = common.__get__('deleteJava');
 var copyNewFile = common.__get__('copyNewFile');
 
 describe('common platform handler', function () {
+    afterEach(() => {
+        fs.removeSync(test_dir);
+        fs.removeSync(non_plugin_file);
+    });
+
     describe('copyFile', function () {
         it('Test#001 : should throw if source path not found', function () {
-            fs.removeSync(src);
             expect(function () { copyFile(test_dir, src, project_dir, dest); })
                 .toThrow(new Error('"' + src + '" not found!'));
         });
 
         it('Test#002 : should throw if src not in plugin directory', function () {
             fs.ensureDirSync(project_dir);
-            fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
+            fs.outputFileSync(non_plugin_file, 'contents');
             var outside_file = '../non_plugin_file';
             expect(function () { copyFile(test_dir, outside_file, project_dir, dest); })
                 .toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
-            fs.removeSync(test_dir);
         });
 
         it('Test#003 : should allow symlink src, if inside plugin', function () {
-            fs.ensureDirSync(java_dir);
-            fs.writeFileSync(java_file, 'contents', 'utf-8');
+            fs.outputFileSync(java_file, 'contents');
 
             // This will fail on windows if not admin - ignore the error in that case.
             if (ignoreEPERMonWin32(java_file, symlink_file)) {
                 return;
             }
 
             copyFile(test_dir, symlink_file, project_dir, dest);
-            fs.removeSync(project_dir);

Review comment:
       No. `project_dir` is contained in `test_dir` which is removed in `afterEach`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] raphinesse commented on pull request #1013: test(pluginHandlers/common): better setup & teardown

Posted by GitBox <gi...@apache.org>.
raphinesse commented on pull request #1013:
URL: https://github.com/apache/cordova-android/pull/1013#issuecomment-655512740


   Thanks for the review, @timbru31 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] timbru31 commented on a change in pull request #1013: test(pluginHandlers/common): better setup & teardown

Posted by GitBox <gi...@apache.org>.
timbru31 commented on a change in pull request #1013:
URL: https://github.com/apache/cordova-android/pull/1013#discussion_r450958324



##########
File path: spec/unit/pluginHandlers/common.spec.js
##########
@@ -35,38 +36,39 @@ var deleteJava = common.__get__('deleteJava');
 var copyNewFile = common.__get__('copyNewFile');
 
 describe('common platform handler', function () {
+    afterEach(() => {
+        fs.removeSync(test_dir);
+        fs.removeSync(non_plugin_file);
+    });
+
     describe('copyFile', function () {
         it('Test#001 : should throw if source path not found', function () {
-            fs.removeSync(src);
             expect(function () { copyFile(test_dir, src, project_dir, dest); })
                 .toThrow(new Error('"' + src + '" not found!'));
         });
 
         it('Test#002 : should throw if src not in plugin directory', function () {
             fs.ensureDirSync(project_dir);
-            fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
+            fs.outputFileSync(non_plugin_file, 'contents');
             var outside_file = '../non_plugin_file';
             expect(function () { copyFile(test_dir, outside_file, project_dir, dest); })
                 .toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
-            fs.removeSync(test_dir);
         });
 
         it('Test#003 : should allow symlink src, if inside plugin', function () {
-            fs.ensureDirSync(java_dir);
-            fs.writeFileSync(java_file, 'contents', 'utf-8');
+            fs.outputFileSync(java_file, 'contents');
 
             // This will fail on windows if not admin - ignore the error in that case.
             if (ignoreEPERMonWin32(java_file, symlink_file)) {
                 return;
             }
 
             copyFile(test_dir, symlink_file, project_dir, dest);
-            fs.removeSync(project_dir);

Review comment:
       Won't this leave traces of the test behind? It's not cleared via the afterEach hook.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] raphinesse merged pull request #1013: test(pluginHandlers/common): better setup & teardown

Posted by GitBox <gi...@apache.org>.
raphinesse merged pull request #1013:
URL: https://github.com/apache/cordova-android/pull/1013


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org