Skip to content

Commit a85067d

Browse files
committed
test: Cover test cases
1 parent bedf4b1 commit a85067d

File tree

8 files changed

+105
-97
lines changed

8 files changed

+105
-97
lines changed

test/expected/build/application.i/dest/Component-preload.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.i/dest/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"sap.m": {},
2222
"sap.ui.fl": {}
2323
}
24-
}
24+
},
25+
"flexBundle": true
2526
}
2627
}

test/expected/build/application.j/dest-resources-json/Component-preload.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.j/dest-resources-json/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"lazy": false
2424
}
2525
}
26-
}
26+
},
27+
"flexBundle": true
2728
}
2829
}

test/expected/build/application.j/dest-resources-json/resources.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
"name": "Component-preload.js",
1919
"module": "application/j/Component-preload.js",
20-
"size": 3658,
20+
"size": 3676,
2121
"merged": true,
2222
"required": [
2323
"sap/m/library.js",
@@ -89,7 +89,7 @@
8989
{
9090
"name": "manifest.json",
9191
"module": "application/j/manifest.json",
92-
"size": 424
92+
"size": 446
9393
},
9494
{
9595
"name": "resources.json",

test/expected/build/application.j/dest/Component-preload.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.j/dest/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"lazy": false
2424
}
2525
}
26-
}
26+
},
27+
"flexBundle": true
2728
}
2829
}

test/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 94 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ function createPlaceholderWorkspace(changes, manifest, flexBundle) {
160160
t.deepEqual(writtenManifest, {
161161
"sap.ui5": {
162162
dependencies: {
163-
minUI5Version: minVersion
163+
minUI5Version: minVersion,
164+
libs: {
165+
"sap.ui.fl": {}
166+
}
164167
},
165168
flexBundle: true
166169
}
@@ -247,7 +250,7 @@ function createPlaceholderWorkspace(changes, manifest, flexBundle) {
247250
});
248251
});
249252

250-
test("flexBundle property set to true when flexibility-bundle.json exists", async (t) => {
253+
test("flexBundle property set to true when bundle is created", async (t) => {
251254
const manifest = {
252255
"_version": "1.58.0",
253256
"sap.app": {
@@ -296,7 +299,7 @@ test("flexBundle property set to true when flexibility-bundle.json exists", asyn
296299
// Check that manifest was updated with flexBundle: true
297300
t.true(placeholderWorkspace.write.callCount > 0, "workspace.write should be called");
298301

299-
// Find the manifest write call (should be the first call for the manifest)
302+
// Find the manifest write call
300303
let manifestCall;
301304
for (let i = 0; i < placeholderWorkspace.write.callCount; i++) {
302305
const call = placeholderWorkspace.write.getCall(i);
@@ -311,11 +314,81 @@ test("flexBundle property set to true when flexibility-bundle.json exists", asyn
311314
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
312315

313316
t.truthy(manifestContent["sap.ui5"], "sap.ui5 section should exist");
314-
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be set to true");
317+
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be set to true when bundle is created");
315318
t.deepEqual(manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
316319
});
317320

318-
test("flexBundle property set to false when flexibility-bundle.json does not exist", async (t) => {
321+
test("flexBundle property set to true when bundle is created even without existing flexibility-bundle.json",
322+
async (t) => {
323+
const manifest = {
324+
"_version": "1.58.0",
325+
"sap.app": {
326+
"id": "sap.ui.demo.app",
327+
"type": "application"
328+
},
329+
"sap.ui5": {
330+
"dependencies": {
331+
"minUI5Version": "1.75.0"
332+
}
333+
}
334+
};
335+
336+
const changeList = [{
337+
"fileName": "test_change",
338+
"fileType": "change",
339+
"changeType": "rename",
340+
"reference": "test.Component",
341+
"content": {},
342+
"selector": {"id": "testId"},
343+
"layer": "CUSTOMER"
344+
}];
345+
346+
const placeholderWorkspace = {
347+
byGlob: async () => changeList.map(createPlaceholderResource),
348+
byPath: async (path) => {
349+
if (path.includes("manifest.json")) {
350+
return createPlaceholderResource(manifest, path);
351+
} else if (path.includes("flexibility-bundle.json")) {
352+
// Return null to indicate file does not exist
353+
return null;
354+
}
355+
return null;
356+
},
357+
write: sinon.stub().returnsArg(0)
358+
};
359+
360+
await generateFlexChangesBundle({
361+
workspace: placeholderWorkspace,
362+
taskUtil: false,
363+
options: {
364+
projectNamespace: "sap/ui/demo/app"
365+
}
366+
});
367+
368+
// Check that manifest was updated with flexBundle: true
369+
t.true(placeholderWorkspace.write.callCount > 0, "workspace.write should be called");
370+
371+
// Find the manifest write call
372+
let manifestCall;
373+
for (let i = 0; i < placeholderWorkspace.write.callCount; i++) {
374+
const call = placeholderWorkspace.write.getCall(i);
375+
const path = call.args[0].getPath ? await call.args[0].getPath() : "unknown";
376+
if (path && path.includes("manifest.json")) {
377+
manifestCall = call;
378+
break;
379+
}
380+
}
381+
382+
t.truthy(manifestCall, "Manifest should be written");
383+
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
384+
385+
t.truthy(manifestContent["sap.ui5"], "sap.ui5 section should exist");
386+
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be set to true when bundle is created");
387+
t.deepEqual(
388+
manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
389+
});
390+
391+
test("sap.ui.fl dependency disables lazy loading if already present", async (t) => {
319392
const manifest = {
320393
"_version": "1.58.0",
321394
"sap.app": {
@@ -324,7 +397,12 @@ test("flexBundle property set to false when flexibility-bundle.json does not exi
324397
},
325398
"sap.ui5": {
326399
"dependencies": {
327-
"minUI5Version": "1.75.0"
400+
"minUI5Version": "1.75.0",
401+
"libs": {
402+
"sap.ui.fl": {
403+
"lazy": true
404+
}
405+
}
328406
}
329407
}
330408
};
@@ -340,13 +418,12 @@ test("flexBundle property set to false when flexibility-bundle.json does not exi
340418
}];
341419

342420
const placeholderWorkspace = {
343-
byGlob: async () => changeList.map(createPlaceholderResource),
421+
byGlob: async () => changeList.map((change) => createPlaceholderResource(change)),
344422
byPath: async (path) => {
345423
if (path.includes("manifest.json")) {
346424
return createPlaceholderResource(manifest, path);
347425
} else if (path.includes("flexibility-bundle.json")) {
348-
// Return null to indicate file does not exist
349-
return null;
426+
return createPlaceholderResource({}, path);
350427
}
351428
return null;
352429
},
@@ -361,9 +438,6 @@ test("flexBundle property set to false when flexibility-bundle.json does not exi
361438
}
362439
});
363440

364-
// Check that manifest was updated with flexBundle: false
365-
t.true(placeholderWorkspace.write.callCount > 0, "workspace.write should be called");
366-
367441
// Find the manifest write call
368442
let manifestCall;
369443
for (let i = 0; i < placeholderWorkspace.write.callCount; i++) {
@@ -378,12 +452,11 @@ test("flexBundle property set to false when flexibility-bundle.json does not exi
378452
t.truthy(manifestCall, "Manifest should be written");
379453
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
380454

381-
t.truthy(manifestContent["sap.ui5"], "sap.ui5 section should exist");
382-
t.false(manifestContent["sap.ui5"].flexBundle, "flexBundle should be set to false");
383-
t.deepEqual(manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
455+
const sapUiFlDependency = manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"];
456+
t.false(sapUiFlDependency.lazy, "sap.ui.fl lazy loading should be disabled when bundle is created");
384457
});
385458

386-
test("flexBundle property set to true when only flexibility-bundle.json exists (no changes)", async (t) => {
459+
test("no manifest update when no changes exist", async (t) => {
387460
const manifest = {
388461
"_version": "1.58.0",
389462
"sap.app": {
@@ -403,7 +476,7 @@ test("flexBundle property set to true when only flexibility-bundle.json exists (
403476
if (path.includes("manifest.json")) {
404477
return createPlaceholderResource(manifest, path);
405478
} else if (path.includes("flexibility-bundle.json")) {
406-
// Return non-null to indicate file exists
479+
// Even if file exists, task won't run without changes
407480
return createPlaceholderResource({}, path);
408481
}
409482
return null;
@@ -419,14 +492,11 @@ test("flexBundle property set to true when only flexibility-bundle.json exists (
419492
}
420493
});
421494

422-
// Check that manifest was updated with flexBundle: true even without changes
423-
const manifestCall = placeholderWorkspace.write.getCall(0);
424-
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
425-
426-
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be set to true");
495+
// Task should not execute when there are no changes
496+
t.is(placeholderWorkspace.write.callCount, 0, "workspace.write should not be called when no changes exist");
427497
});
428498

429-
test("flexBundle property overrides existing value when flexibility-bundle.json exists", async (t) => {
499+
test("flexBundle property overrides existing value when bundle is created", async (t) => {
430500
const manifest = {
431501
"_version": "1.58.0",
432502
"sap.app": {
@@ -487,71 +557,6 @@ test("flexBundle property overrides existing value when flexibility-bundle.json
487557
t.truthy(manifestCall, "Manifest should be written");
488558
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
489559

490-
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be overridden to true");
491-
t.deepEqual(manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
492-
});
493-
494-
test("flexBundle property overrides existing value when flexibility-bundle.json does not exist", async (t) => {
495-
const manifest = {
496-
"_version": "1.58.0",
497-
"sap.app": {
498-
"id": "sap.ui.demo.app",
499-
"type": "application"
500-
},
501-
"sap.ui5": {
502-
"dependencies": {
503-
"minUI5Version": "1.75.0"
504-
},
505-
"flexBundle": true // Pre-existing value that should be overridden
506-
}
507-
};
508-
509-
const changeList = [{
510-
"fileName": "test_change",
511-
"fileType": "change",
512-
"changeType": "rename",
513-
"reference": "test.Component",
514-
"content": {},
515-
"selector": {"id": "testId"},
516-
"layer": "CUSTOMER"
517-
}];
518-
519-
const placeholderWorkspace = {
520-
byGlob: async () => changeList.map((change) => createPlaceholderResource(change)),
521-
byPath: async (path) => {
522-
if (path.includes("manifest.json")) {
523-
return createPlaceholderResource(manifest, path);
524-
} else if (path.includes("flexibility-bundle.json")) {
525-
// Return null to indicate file does not exist
526-
return null;
527-
}
528-
return null;
529-
},
530-
write: sinon.stub().returnsArg(0)
531-
};
532-
533-
await generateFlexChangesBundle({
534-
workspace: placeholderWorkspace,
535-
taskUtil: false,
536-
options: {
537-
projectNamespace: "sap/ui/demo/app"
538-
}
539-
});
540-
541-
// Check that manifest was updated and existing flexBundle: true was overridden to false
542-
let manifestCall;
543-
for (let i = 0; i < placeholderWorkspace.write.callCount; i++) {
544-
const call = placeholderWorkspace.write.getCall(i);
545-
const path = call.args[0].getPath ? await call.args[0].getPath() : "unknown";
546-
if (path && path.includes("manifest.json")) {
547-
manifestCall = call;
548-
break;
549-
}
550-
}
551-
552-
t.truthy(manifestCall, "Manifest should be written");
553-
const manifestContent = JSON.parse(await manifestCall.args[0].getString());
554-
555-
t.false(manifestContent["sap.ui5"].flexBundle, "flexBundle should be overridden to false");
560+
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be overridden to true when bundle is created");
556561
t.deepEqual(manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
557562
});

0 commit comments

Comments
 (0)