Skip to content

Commit

Permalink
[FEATURE] Apply default values to bunde definitions for standard tasks (
Browse files Browse the repository at this point in the history
#1033)

JIRA: CPOUI5FOUNDATION-835
  • Loading branch information
d3xter666 committed Jun 24, 2024
1 parent 0becb42 commit 4178e1a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
89 changes: 82 additions & 7 deletions test/lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)]);
});

0 comments on commit 4178e1a

Please sign in to comment.