Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 6, 2023
1 parent 31a88ae commit e3d4615
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions test/lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,104 @@ ${SOURCE_MAPPING_URL}=library-preload.js.map
]);
});

test.serial("integration: createBundle with depCache", async (t) => {
const pool = new ResourcePool();
pool.addResource({
name: "a.js",
getPath: () => "a.js",
string: function() {
return this.buffer();
},
buffer: async () => "sap.ui.define([\"./b\", \"./c2\"],function(b, c){return {};});"
});
pool.addResource({
name: "b.js",
getPath: () => "b.js",
string: function() {
return this.buffer();
},
buffer: async () => "function Two(){return 2;}"
});
pool.addResource({
name: "c2.js",
getPath: () => "c2.js",
string: function() {
return this.buffer();
},
buffer: async () => "sap.ui.define([\"./c1\", \"./c3\"],function(c1, c3){return {};});"
});
pool.addResource({
name: "c1.js",
getPath: () => "c1.js",
string: function() {
return this.buffer();
},
buffer: async () => "function Three(){return 3.1;}"
});
pool.addResource({
name: "c3.js",
getPath: () => "c3.js",
string: function() {
return this.buffer();
},
buffer: async () => "function Three(){return 3.3;}"
});
pool.addResource({
name: "a.library",
getPath: () => "a.library",
string: function() {
return this.buffer();
},
buffer: async () => `<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
<appData>
<packaging xmlns="http://www.sap.com/ui5/buildext/packaging" version="2.0" >
<module-infos>
<raw-module name="a.js"
requiresTopLevelScope="false" />
</module-infos>
</packaging>
</appData>
</library>`
});

const bundleDefinition = {
name: `library-depCache-preload.js`,
sections: [{
mode: "preload",
name: "preload-section",
filters: ["a.js"]
}, {
mode: "depCache",
filters: ["*.js"]
}]
};

const builder = new Builder(pool);
const oResult = await builder.createBundle(bundleDefinition, {});
t.is(oResult.name, "library-depCache-preload.js");
const expectedContent = `//@ui5-bundle library-depCache-preload.js
sap.ui.require.preload({
"a.js":function(){
sap.ui.define(["./b", "./c2"],function(b, c){return {};});
}
},"preload-section");
sap.ui.loader.config({depCacheUI5:{
"a.js": ["b.js","c2.js"],
"c2.js": ["c1.js","c3.js"]
}});
${SOURCE_MAPPING_URL}=library-depCache-preload.js.map
`;
t.deepEqual(oResult.content, expectedContent, "EVOBundleFormat " +
"should contain:" +
" preload part from a.js" +
" depCache part from a.js && c2.js");
t.is(oResult.bundleInfo.name, "library-depCache-preload.js", "bundle info name is correct");
t.deepEqual(oResult.bundleInfo.size, expectedContent.length, "bundle info size is correct");
t.deepEqual(oResult.bundleInfo.subModules, ["a.js", "b.js", "c2.js", "c1.js", "c3.js"],
"bundle info subModules are correct");
});

test("integration: createBundle using predefine calls with source maps and a single, simple source", async (t) => {
const pool = new ResourcePool();

Expand Down

0 comments on commit e3d4615

Please sign in to comment.