CB-11022 Save modulesMetadata to both www and platform_www when necessary
authorVladimir Kotikov <v-vlkoti@microsoft.com>
Thu, 14 Apr 2016 12:53:35 +0000 (15:53 +0300)
committerVladimir Kotikov <v-vlkoti@microsoft.com>
Mon, 18 Apr 2016 09:16:37 +0000 (12:16 +0300)
 This closes #427

spec/PluginManager.spec.js
src/PluginManager.js

index e99ab05..cba7c79 100644 (file)
 require ('promise-matchers');\r
 \r
 var Q = require('q');\r
+var fs = require('fs');\r
 var path = require('path');\r
+var shell = require('shelljs');\r
 var rewire = require('rewire');\r
-var PlatformJson = require('../src/PlatformJson');\r
 var PluginManager = rewire('../src/PluginManager');\r
 var PluginInfo = require('../src/PluginInfo/PluginInfo');\r
 var ConfigChanges = require('../src/ConfigChanges/ConfigChanges');\r
@@ -30,14 +31,17 @@ var ConfigChanges = require('../src/ConfigChanges/ConfigChanges');
 var DUMMY_PLUGIN = path.join(__dirname, 'fixtures/plugins/org.test.plugins.dummyplugin');\r
 var FAKE_PLATFORM = 'cordova-atari';\r
 var FAKE_LOCATIONS = {\r
-    root: '/some/fake/path'\r
+    root: '/some/fake/path',\r
+    platformWww: '/some/fake/path/platform_www',\r
+    www: '/some/www/dir'\r
 };\r
 \r
 describe('PluginManager class', function() {\r
 \r
     beforeEach(function () {\r
-        spyOn(PlatformJson, 'load');\r
         spyOn(ConfigChanges, 'PlatformMunger');\r
+        spyOn(fs, 'writeFileSync');\r
+        spyOn(shell, 'mkdir');\r
     });\r
 \r
     it('should be constructable', function () {\r
@@ -53,6 +57,7 @@ describe('PluginManager class', function() {
     describe('instance', function () {\r
         var actions, manager;\r
         var FAKE_PROJECT;\r
+        var fail = jasmine.createSpy('fail');\r
         var ActionStackOrig = PluginManager.__get__('ActionStack');\r
 \r
         beforeEach(function () {\r
@@ -78,7 +83,7 @@ describe('PluginManager class', function() {
                 expect(manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})).not.toHaveBeenRejected();\r
             });\r
 \r
-            it('should iterate through all plugin\'s files and frameworks', function () {\r
+            it('should iterate through all plugin\'s files and frameworks', function (done) {\r
                 manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})\r
                 .then(function () {\r
                     expect(FAKE_PROJECT.getInstaller.calls.length).toBe(16);\r
@@ -87,6 +92,43 @@ describe('PluginManager class', function() {
                     expect(actions.push.calls.length).toBe(16);\r
                     expect(actions.process).toHaveBeenCalled();\r
                     expect(FAKE_PROJECT.write).toHaveBeenCalled();\r
+                })\r
+                .fail(fail)\r
+                .done(function () {\r
+                    expect(fail).not.toHaveBeenCalled();\r
+                    done();\r
+                });\r
+            });\r
+\r
+            it('should save plugin metadata to www directory', function (done) {\r
+                var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js');\r
+                var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js');\r
+\r
+                manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})\r
+                .then(function () {\r
+                    expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');\r
+                    expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');\r
+                })\r
+                .fail(fail)\r
+                .done(function () {\r
+                    expect(fail).not.toHaveBeenCalled();\r
+                    done();\r
+                });\r
+            });\r
+\r
+            it('should save plugin metadata to both www ans platform_www directories when options.usePlatformWww is specified', function (done) {\r
+                var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js');\r
+                var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js');\r
+\r
+                manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {usePlatformWww: true})\r
+                .then(function () {\r
+                    expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');\r
+                    expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');\r
+                })\r
+                .fail(fail)\r
+                .done(function () {\r
+                    expect(fail).not.toHaveBeenCalled();\r
+                    done();\r
                 });\r
             });\r
         });\r
index ea4d688..deeb92f 100644 (file)
@@ -133,9 +133,13 @@ PluginManager.prototype.doOperation = function (operation, plugin, options) {
         // Save everything (munge and plugin/modules metadata)\r
         self.munger.save_all();\r
 \r
-        var targetDir = options.usePlatformWww ? self.locations.platformWww : self.locations.www;\r
-        fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'),\r
-            self.munger.platformJson.generateMetadata(), 'utf-8');\r
+        var metadata = self.munger.platformJson.generateMetadata();\r
+        fs.writeFileSync(path.join(self.locations.www, 'cordova_plugins.js'), metadata, 'utf-8');\r
+\r
+        // CB-11022 save plugin metadata to both www and platform_www if options.usePlatformWww is specified\r
+        if (options.usePlatformWww) {\r
+            fs.writeFileSync(path.join(self.locations.platformWww, 'cordova_plugins.js'), metadata, 'utf-8');\r
+        }\r
     });\r
 };\r
 \r