diff --git a/Gruntfile.js b/Gruntfile.js index 8b006f3c..9711b557 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,7 +29,11 @@ module.exports = function(grunt) { // Before generating any new files, remove any previously-created files. clean: { - tests: ['tmp'] + tests: [ + 'tmp', + 'test/preload/fixtures/app-same-dest/my/app/Component-preload.js', + 'test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json' + ] }, // Configuration to be run (and then tested). @@ -111,6 +115,24 @@ module.exports = function(grunt) { components: '**' }, + // The following two targets are testing that a generated preload file + // doesn't get included when runnign the preload again + // (same folder for src and dest) + 'component_same_dest_1': { + options: { + resources: 'test/preload/fixtures/app-same-dest', + dest: 'test/preload/fixtures/app-same-dest' + }, + components: '**' + }, + 'component_same_dest_2': { + options: { + resources: 'test/preload/fixtures/app-same-dest', + dest: 'test/preload/fixtures/app-same-dest' + }, + components: '**' + }, + 'library_default_options': { options: { resources: 'test/preload/fixtures/library', @@ -139,6 +161,58 @@ module.exports = function(grunt) { compress: false }, libraries: '**' + }, + + // The following two targets are testing that a generated preload file + // doesn't get included when runnign the preload again + // (same folder for src and dest) + 'library_same_dest_1': { + options: { + resources: [ + { + cwd: 'test/preload/fixtures/library-same-dest', + src: [ + // Defaults + '**/*.js', + '**/*.fragment.html', + '**/*.fragment.json', + '**/*.fragment.xml', + '**/*.view.html', + '**/*.view.json', + '**/*.view.xml', + '**/*.properties', + // Include "library-preload.json" for this test + '**/library-preload.json' + ] + } + ], + dest: 'test/preload/fixtures/library-same-dest' + }, + libraries: '**' + }, + 'library_same_dest_2': { + options: { + resources: [ + { + cwd: 'test/preload/fixtures/library-same-dest', + src: [ + // Defaults + '**/*.js', + '**/*.fragment.html', + '**/*.fragment.json', + '**/*.fragment.xml', + '**/*.view.html', + '**/*.view.json', + '**/*.view.xml', + '**/*.properties', + // Include "library-preload.json" for this test + '**/library-preload.json' + ] + } + ], + dest: 'test/preload/fixtures/library-same-dest' + }, + libraries: '**' } }, diff --git a/tasks/preload.js b/tasks/preload.js index d23d0226..1cf30cd3 100644 --- a/tasks/preload.js +++ b/tasks/preload.js @@ -176,7 +176,15 @@ module.exports = function (grunt) { preloadObject.name = preloadModuleName; } - var preloadPatterns = preloadOption.src ? preloadOption.src : (preloadDir + '/**'); + var preloadPatterns = preloadOption.src ? preloadOption.src : [ preloadDir + '/**' ]; + if (typeof preloadPatterns === "string") { + preloadPatterns = [ preloadPatterns ]; + } + + // Always exclude the corresponding preload file (Component-preload.js / library-preload.json) + // Otherwise it might get included every time the build runs if src / dest are the same dir + preloadPatterns.push('!' + preloadDir + '/' + preloadInfo.moduleName + preloadInfo.ext); + var preloadFiles = grunt.file.match(preloadPatterns, resourceFiles); if (preloadFiles.length === 0) { var patternsString = (typeof preloadPatterns === 'string') ? preloadPatterns : preloadPatterns.join('", "'); diff --git a/test/preload/fixtures/app-same-dest/my/app/Component-preload.js b/test/preload/fixtures/app-same-dest/my/app/Component-preload.js new file mode 100644 index 00000000..8cfddd3c --- /dev/null +++ b/test/preload/fixtures/app-same-dest/my/app/Component-preload.js @@ -0,0 +1,9 @@ +jQuery.sap.registerPreloadedModules({ + "version": "2.0", + "name": "my/app/Component-preload", + "modules": { + "my/app/Component.js": "/* © */\n\"use strict\";function myFunction(n,o){return n+o}/**\n* This is a copyright comment\n*/\n/* (c) */\n/* released under */\n/* license */\nconsole.log(\"myJS\");", + "my/app/view/my.view.xml": "XML\n", + "my/app/view/myHtmlPre.view.xml": "XML\n\n " + } +}); \ No newline at end of file diff --git a/test/preload/fixtures/app-same-dest/my/app/Component.js b/test/preload/fixtures/app-same-dest/my/app/Component.js new file mode 100644 index 00000000..8084737b --- /dev/null +++ b/test/preload/fixtures/app-same-dest/my/app/Component.js @@ -0,0 +1,22 @@ +/* © */ +'use strict'; + +/** +* This is a copyright comment +*/ + +/* (c) */ + +/* released under */ +/* normal comment */ +/* license */ + + +console.log('myJS'); + +/** + * This is a little comment + */ +function myFunction(longVariableName, longerVariableName) { + return longVariableName + longerVariableName; +} diff --git a/test/preload/fixtures/app-same-dest/my/app/view/my.view.xml b/test/preload/fixtures/app-same-dest/my/app/view/my.view.xml new file mode 100644 index 00000000..ac389a3b --- /dev/null +++ b/test/preload/fixtures/app-same-dest/my/app/view/my.view.xml @@ -0,0 +1,2 @@ +XML + \ No newline at end of file diff --git a/test/preload/fixtures/app-same-dest/my/app/view/myHtmlPre.view.xml b/test/preload/fixtures/app-same-dest/my/app/view/myHtmlPre.view.xml new file mode 100644 index 00000000..baa83f00 --- /dev/null +++ b/test/preload/fixtures/app-same-dest/my/app/view/myHtmlPre.view.xml @@ -0,0 +1,3 @@ +XML + + \ No newline at end of file diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/foo.properties b/test/preload/fixtures/library-same-dest/my/ui/lib/foo.properties new file mode 100644 index 00000000..6ac867af --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/foo.properties @@ -0,0 +1 @@ +FOO=BAR diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json b/test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json new file mode 100644 index 00000000..abd7e7a2 --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json @@ -0,0 +1,11 @@ +{ + "version": "2.0", + "name": "my.ui.lib.library-preload", + "modules": { + "my/ui/lib/library.js": "jQuery.sap.require(\"sap.ui.core.library\"),jQuery.sap.declare(\"my.ui.lib.library\"),sap.ui.getCore().initLibrary({name:\"my.ui.lib\",version:\"0.0.0\",dependencies:[\"sap.ui.core\"]});", + "my/ui/lib/myJS.js": "/* © */\n\"use strict\";function myFunction(n,o){return n+o}/**\n* This is a copyright comment\n*/\n/* (c) */\n/* released under */\n/* license */\nconsole.log(\"myJS\");", + "my/ui/lib/my.view.xml": "XML\n", + "my/ui/lib/myHtmlPre.view.xml": "XML\n\n ", + "my/ui/lib/foo.properties": "FOO=BAR\n" + } +} \ No newline at end of file diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/library.js b/test/preload/fixtures/library-same-dest/my/ui/lib/library.js new file mode 100644 index 00000000..ddc3b34c --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/library.js @@ -0,0 +1,8 @@ +jQuery.sap.require("sap.ui.core.library"); +jQuery.sap.declare("my.ui.lib.library"); + +sap.ui.getCore().initLibrary({ + name : "my.ui.lib", + version: "0.0.0", + dependencies : ["sap.ui.core"] +}); diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/my.view.xml b/test/preload/fixtures/library-same-dest/my/ui/lib/my.view.xml new file mode 100644 index 00000000..ac389a3b --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/my.view.xml @@ -0,0 +1,2 @@ +XML + \ No newline at end of file diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/myHtmlPre.view.xml b/test/preload/fixtures/library-same-dest/my/ui/lib/myHtmlPre.view.xml new file mode 100644 index 00000000..baa83f00 --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/myHtmlPre.view.xml @@ -0,0 +1,3 @@ +XML + + \ No newline at end of file diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/myJS.js b/test/preload/fixtures/library-same-dest/my/ui/lib/myJS.js new file mode 100644 index 00000000..8084737b --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/myJS.js @@ -0,0 +1,22 @@ +/* © */ +'use strict'; + +/** +* This is a copyright comment +*/ + +/* (c) */ + +/* released under */ +/* normal comment */ +/* license */ + + +console.log('myJS'); + +/** + * This is a little comment + */ +function myFunction(longVariableName, longerVariableName) { + return longVariableName + longerVariableName; +} diff --git a/test/preload/fixtures/library-same-dest/my/ui/lib/myJSON.json b/test/preload/fixtures/library-same-dest/my/ui/lib/myJSON.json new file mode 100644 index 00000000..bffd0ff5 --- /dev/null +++ b/test/preload/fixtures/library-same-dest/my/ui/lib/myJSON.json @@ -0,0 +1,3 @@ +{ + "my": "json" +} diff --git a/test/preload_test.js b/test/preload_test.js index 321e4fec..4f541ad1 100644 --- a/test/preload_test.js +++ b/test/preload_test.js @@ -45,6 +45,14 @@ describe('openui5_preload', function() { }); }); + it('library_same_dest', function() { + fileContent.equal({ + sActualFileSource: 'test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json', + sExpectedFileSource: 'test/preload/expected/library_default_options/my/ui/lib/library-preload.json', + sMessage: 'library preload JSON should be correctly created.' + }); + }); + }); describe('component', function() { @@ -73,6 +81,14 @@ describe('openui5_preload', function() { }); }); + it('component_same_dest', function() { + fileContent.equal({ + sActualFileSource: 'test/preload/fixtures/app-same-dest/my/app/Component-preload.js', + sExpectedFileSource: 'test/preload/expected/component_default_options/my/app/Component-preload.js', + sMessage: 'component preload JS should be correctly created.' + }); + }); + }); });