Skip to content

Commit

Permalink
[INTERNAL] generateLibraryPreload: Add tests for bundling of modules …
Browse files Browse the repository at this point in the history
…requiring top-level scope
  • Loading branch information
RandomByte committed Jun 5, 2023
1 parent 9153d85 commit d96d28c
Show file tree
Hide file tree
Showing 30 changed files with 215 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* Some fancy copyright
*/
var topLevelVar = "Old World";
console.log('Hello ' + topLevelVar);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* Some fancy copyright
*/
var topLevelVar = "Old World";
console.log('Hello ' + topLevelVar);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.d</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>

</library>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"_version": "1.21.0",
"sap.app": {
"id": "library.d",
"type": "library",
"embeds": [],
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library D",
"description": "Library D",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.0",
"libs": {}
},
"library": {
"i18n": false
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* Some fancy copyright
*/
var topLevelVar = "Old World";
console.log('Hello ' + topLevelVar);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* ${copyright}
*/
var topLevelVar = "Old World";
console.log('Hello ' + topLevelVar);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/fixtures/library.d-minified/main/src/library/d/.library
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.d</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>

</library>
5 changes: 5 additions & 0 deletions test/fixtures/library.d-minified/main/src/library/d/legacy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions test/fixtures/library.d-minified/main/src/library/d/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"_version": "1.21.0",
"sap.app": {
"id": "library.d",
"type": "library",
"embeds": [],
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library D",
"description": "Library D",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.0",
"libs": {}
},
"library": {
"i18n": false
}
}
}
5 changes: 5 additions & 0 deletions test/fixtures/library.d-minified/main/src/library/d/some.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
5 changes: 5 additions & 0 deletions test/fixtures/library.d/main/src/library/d/legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
* ${copyright}
*/
var topLevelVar = "Old World";
console.log('Hello ' + topLevelVar);
56 changes: 55 additions & 1 deletion test/lib/tasks/bundlers/generateLibraryPreload.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as taskRepository from "../../../../lib/tasks/taskRepository.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const libraryDPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d");
const libraryDMinifiedPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d-minified");
const sapUiCorePath = path.join(__dirname, "..", "..", "..", "fixtures", "sap.ui.core");

import recursive from "recursive-readdir";
Expand Down Expand Up @@ -51,7 +52,7 @@ test.serial("integration: build library.d with library preload", async (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.is(expectedFiles.length, 5, "5 files are expected");
t.is(expectedFiles.length, 6, "6 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
Expand Down Expand Up @@ -82,6 +83,59 @@ const libraryDTree = {
}
};

test.serial("integration: build library.d-minified with library preload", async (t) => {
const destPath = "./test/tmp/build/library.d-minified/preload";
const expectedPath = "./test/expected/build/library.d-minified/preload";
const excludedTasks = ["*"];
const includedTasks = ["generateLibraryPreload"];

const graph = await graphFromObject({
dependencyTree: libraryDMinifiedTree
});
graph.setTaskRepository(taskRepository);
await t.notThrowsAsync(graph.build({
destPath,
excludedTasks,
includedTasks
}));

const expectedFiles = await findFiles(expectedPath);

// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.is(expectedFiles.length, 9, "9 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
});

const libraryDMinifiedTree = {
"id": "library.d",
"version": "1.0.0",
"path": libraryDMinifiedPath,
"dependencies": [],
"configuration": {
"specVersion": "2.0",
"type": "library",
"metadata": {
"name": "library.d",
"copyright": "Some fancy copyright"
},
"resources": {
"configuration": {
"paths": {
"src": "main/src",
"test": "main/test"
}
}
}
}
};

test.serial("integration: build sap.ui.core with library preload", async (t) => {
const destPath = "./test/tmp/build/sap.ui.core/preload";
const expectedPath = "./test/expected/build/sap.ui.core/preload";
Expand Down

0 comments on commit d96d28c

Please sign in to comment.