Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] Add tests #504

Merged
merged 4 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>
<documentation>Library H</documentation>
<appData>
<packaging xmlns="http://www.sap.com/ui5/buildext/packaging" version="2.0" >
<module-infos>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library D",
"description": "Library D",
"title": "Library H",
"description": "Library H",
"resources": "resources.json",
"offline": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<documentation>Library D</documentation>
<documentation>Library H</documentation>
<appData>
<packaging xmlns="http://www.sap.com/ui5/buildext/packaging" version="2.0" >
<module-infos>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library D",
"description": "Library D",
"title": "Library H",
"description": "Library H",
"resources": "resources.json",
"offline": true
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/library.h/main/src/library/h/.library
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<copyright>Some fancy copyright</copyright>
<version>${version}</version>

<documentation>Library D</documentation>
<documentation>Library H</documentation>
<appData>
<packaging xmlns="http://www.sap.com/ui5/buildext/packaging" version="2.0" >
<module-infos>
Expand Down
63 changes: 63 additions & 0 deletions test/lib/lbt/resources/ModuleInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const test = require("ava");

const ModuleInfo = require("../../../../lib/lbt/resources/ModuleInfo");

test("ModuleInfo: constructor", async (t) => {
const moduleInfo = new ModuleInfo("myName");
t.falsy(moduleInfo.exposedGlobals, "exposedGlobals is not set");
t.falsy(moduleInfo.format, "format is not set");
t.falsy(moduleInfo.description, "description is not set");
t.false(moduleInfo.requiresTopLevelScope, "requiresTopLevelScope is false");
t.false(moduleInfo.rawModule, "rawModule is false");
t.false(moduleInfo.dynamicDependencies, "dynamicDependencies is false");
t.deepEqual(moduleInfo.subModules, [], "submodules are empty");
});

test("ModuleInfo: addSubModule", async (t) => {
// setup
const moduleInfo = new ModuleInfo("myName");
moduleInfo.addDependency("otherModule", false);
const otherModuleInfo = new ModuleInfo("otherModule");
otherModuleInfo.addDependency("unknownModule", false);
otherModuleInfo.dynamicDependencies = true;

// action
moduleInfo.addSubModule(otherModuleInfo);

// expectation
t.true(moduleInfo.dynamicDependencies, "dynamicDependencies is set");
t.deepEqual(moduleInfo.subModules, ["otherModule"], "submodule is set");
t.deepEqual(moduleInfo.dependencies, ["unknownModule"], "unknownModule dependency is copied over");
});

test("ModuleInfo: name", async (t) => {
// setup
const moduleInfo = new ModuleInfo("myName");

// action
moduleInfo.addDependency("newName", false);
moduleInfo.name = "newName";

moduleInfo.addSubModule("newName2");
moduleInfo.name = "newName2";

// expectation
t.deepEqual(moduleInfo.subModules, [], "submodule is empty");
t.deepEqual(moduleInfo.dependencies, [], "dependencies is empty");
t.is(moduleInfo.name, "newName2", "name was set");
});

test("ModuleInfo: toString", async (t) => {
// setup
const moduleInfo = new ModuleInfo("myName");

// action
moduleInfo.addDependency("dep1", false);
moduleInfo.addDependency("dep2", false);
moduleInfo.addSubModule("sub1");
moduleInfo.addSubModule("sub2");
const stringContent = moduleInfo.toString();

// expectation
t.is(stringContent, "ModuleInfo(myName, dependencies=dep1,dep2, includes=sub1,sub2)", "string value is correct");
});
55 changes: 55 additions & 0 deletions test/lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const test = require("ava");
const path = require("path");

const parentLogger = require("@ui5/logger").getGroupLogger("mygroup");

const LibraryBuilder = require("../../../../lib/types/library/LibraryBuilder");

function clone(o) {
return JSON.parse(JSON.stringify(o));
}

test("Instantiation", (t) => {
const project = clone(libraryETree);
const appBuilder = new LibraryBuilder({parentLogger, project});
t.truthy(appBuilder);
t.deepEqual(appBuilder.taskExecutionOrder, [
"escapeNonAsciiCharacters",
"replaceCopyright",
"replaceVersion",
"generateJsdoc",
"executeJsdocSdkTransformation",
"generateLibraryManifest",
"generateManifestBundle",
"generateLibraryPreload",
"buildThemes",
"createDebugFiles",
"uglify",
"generateResourcesJson"
], "LibraryBuilder is instantiated with standard tasks");
});

const libraryEPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.e");
const libraryETree = {
id: "library.e.id",
version: "1.0.0",
path: libraryEPath,
dependencies: [],
_level: 0,
_isRoot: true,
specVersion: "2.0",
type: "library",
metadata: {
name: "library.e",
copyright: "some fancy copyright.",
namespace: "library.e"
},
resources: {
configuration: {
paths: {
src: "src",
test: "test"
}
}
}
};
55 changes: 55 additions & 0 deletions test/lib/types/themeLibrary/ThemeLibraryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const test = require("ava");

const ThemeLibraryBuilder = require("../../../../lib/types/themeLibrary/ThemeLibraryBuilder");

test("tasks", async (t) => {
const themeLibraryBuilder = new ThemeLibraryBuilder({
resourceCollections: {
workspace: {
byGlob: async () => {
return [];
}
}
},
buildContext: {
isRootProject: () => {
return true;
}
},
project: {
metadata: {
name: "name",
copyright: "copyright"
},
type: "type"
},
parentLogger: {
createSubLogger: () => {
return {
createTaskLogger: () => {
return {
addWork: () => undefined,
startWork: () => undefined,
completeWork: () => undefined
};
}
};
}
},
taskUtil: {
isRootProject: () => {
return true;
}
}
});

const taskNames = Object.keys(themeLibraryBuilder.tasks);
t.deepEqual(taskNames, [
"replaceCopyright",
"replaceVersion",
"buildThemes",
"generateResourcesJson",
], "Expected tasks have been added");

await themeLibraryBuilder.build(taskNames);
});