From 4178e1a0315ad16b7774183a18e326f8c52f5f44 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Mon, 24 Jun 2024 16:35:18 +0200 Subject: [PATCH] [FEATURE] Apply default values to bunde definitions for standard tasks (#1033) JIRA: CPOUI5FOUNDATION-835 --- lib/processors/bundlers/moduleBundler.js | 9 ++ test/lib/processors/bundlers/moduleBundler.js | 89 +++++++++++++++++-- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/lib/processors/bundlers/moduleBundler.js b/lib/processors/bundlers/moduleBundler.js index a69442cab..3f8d964f2 100644 --- a/lib/processors/bundlers/moduleBundler.js +++ b/lib/processors/bundlers/moduleBundler.js @@ -152,6 +152,15 @@ export default function({resources, options: { ignoreMissingModules: false }, bundleOptions); + // Apply defaults without modifying the passed object + bundleDefinition = Object.assign({ + resolve: false, + resolveConditional: false, + renderer: false, + sort: true, + declareRawModules: false, + }, bundleDefinition); + const pool = new LocatorResourcePool({ ignoreMissingModules: bundleOptions.ignoreMissingModules }); diff --git a/test/lib/processors/bundlers/moduleBundler.js b/test/lib/processors/bundlers/moduleBundler.js index b18942ceb..dbcc36595 100644 --- a/test/lib/processors/bundlers/moduleBundler.js +++ b/test/lib/processors/bundlers/moduleBundler.js @@ -45,6 +45,16 @@ test.serial("Builder returns single bundle", async (t) => { const bundleOptions = { "some": "option" }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; const createdBundle = { name: "BundleName.js", @@ -93,7 +103,7 @@ test.serial("Builder returns single bundle", async (t) => { t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], { // default bundleOptions @@ -133,6 +143,17 @@ test.serial("Builder returns multiple bundles", async (t) => { "some": "option" }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; + const createdBundles = [ { name: "BundleName1.js", @@ -205,7 +226,7 @@ test.serial("Builder returns multiple bundles", async (t) => { t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], { // default bundleOptions @@ -247,6 +268,16 @@ test.serial("bundleOptions default (no options passed)", async (t) => { const bundleDefinition = { "some": "definition" }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; const createdBundle = { name: "BundleName.js", @@ -294,7 +325,7 @@ test.serial("bundleOptions default (no options passed)", async (t) => { t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], { // default bundleOptions @@ -330,6 +361,17 @@ test.serial("bundleOptions default (empty options passed)", async (t) => { }; const bundleOptions = {}; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; + const createdBundle = { name: "BundleName.js", content: "Bundle Content", @@ -358,7 +400,7 @@ test.serial("bundleOptions default (empty options passed)", async (t) => { t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], { // default bundleOptions @@ -392,6 +434,17 @@ test.serial("bundleOptions (all options passed)", async (t) => { ignoreMissingModules: true }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; + const createdBundle = { name: "BundleName.js", content: "Bundle Content", @@ -420,7 +473,7 @@ test.serial("bundleOptions (all options passed)", async (t) => { t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], bundleOptions, "builder.createBundle should be called with bundleOptions"); @@ -449,6 +502,16 @@ test.serial("Passes ignoreMissingModules bundleOption to LocatorResourcePool", a "ignoreMissingModules": "foo" }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; const createdBundle = { name: "BundleName.js", @@ -497,7 +560,7 @@ test.serial("Passes ignoreMissingModules bundleOption to LocatorResourcePool", a t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once"); t.is(builder.createBundle.getCall(0).args.length, 2); - t.is(builder.createBundle.getCall(0).args[0], bundleDefinition, + t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition, "builder.createBundle should be called with bundleDefinition"); t.deepEqual(builder.createBundle.getCall(0).args[1], effectiveBundleOptions, "builder.createBundle should be called with bundleOptions"); @@ -539,6 +602,17 @@ test.serial("Verbose Logging", async (t) => { "some": "option", }; + const effectiveBundleDefinition = { + // Defaults + "resolve": false, + "resolveConditional": false, + "renderer": false, + "sort": true, + "declareRawModules": false, + + "some": "definition" + }; + const createdBundle = { name: "Bundle Name", content: "Bundle Content", @@ -570,6 +644,7 @@ test.serial("Verbose Logging", async (t) => { t.is(log.verbose.callCount, 3, "log.verbose is called 3 times when verbose level is enabled"); t.deepEqual(log.verbose.getCall(0).args, ["Generating bundle:"]); - t.deepEqual(log.verbose.getCall(1).args, ["bundleDefinition: " + JSON.stringify(bundleDefinition, null, 2)]); + t.deepEqual(log.verbose.getCall(1).args, + ["bundleDefinition: " + JSON.stringify(effectiveBundleDefinition, null, 2)]); t.deepEqual(log.verbose.getCall(2).args, ["bundleOptions: " + JSON.stringify(effectiveBundleOptions, null, 2)]); });