Skip to content

Commit

Permalink
[INTERNAL] Add tests (#504)
Browse files Browse the repository at this point in the history
Add tests to increase coverage
Fix naming in manifest.json file of library H

Co-authored-by: Matthias Osswald <[email protected]>
  • Loading branch information
tobiasso85 and matz3 authored Aug 27, 2020
1 parent 4c81be8 commit 7416a97
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 7 deletions.
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);
});

0 comments on commit 7416a97

Please sign in to comment.