Skip to content

Commit

Permalink
[INTERNAL] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasso85 authored and RandomByte committed Jan 16, 2020
1 parent ce1236d commit fc93f44
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/processors/themeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ThemeBuilder {

const libParams = new Resource({
path: themeDir + "/library-parameters.json",
string: JSON.stringify(result.variables, null, compress || compressJSON ? null : "\t")
string: JSON.stringify(result.variables, null, (compress || compressJSON) ? null : "\t")
});

files.push(libCss, libCssRtl, libParams);
Expand Down
6 changes: 4 additions & 2 deletions lib/tasks/buildThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ module.exports = async function({workspace, dependencies, options}) {

resources = await allResources.filter(isAvailable);
}

const compress = options.compress !== false;
const processedResources = await themeBuilder({
resources,
fs: fsInterface(combo),
options: {
compressJSON: true
compressJSON: compress,
compress: false
}
});

const compress = options.compress === undefined ? true : options.compress;
if (compress) {
const cssResources = processedResources.filter((resource) => {
return resource.getPath().endsWith(".css");
Expand Down

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
@@ -1 +1 @@
{"someColor":"#000"}
{"someColor":"#000000"}

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

39 changes: 26 additions & 13 deletions test/lib/tasks/buildThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ let buildThemes = require("../../../lib/tasks/buildThemes");
test.beforeEach((t) => {
// Stubbing processors/themeBuilder
t.context.themeBuilderStub = sinon.stub();
t.context.cssOptimizerStub = sinon.stub();
t.context.fsInterfaceStub = sinon.stub(require("@ui5/fs"), "fsInterface");
t.context.fsInterfaceStub.returns({});
mock("../../../lib/processors/themeBuilder", t.context.themeBuilderStub);
mock("../../../lib/processors/cssOptimizer", t.context.cssOptimizerStub);

// Re-require tested module
buildThemes = mock.reRequire("../../../lib/tasks/buildThemes");
Expand All @@ -19,10 +21,11 @@ test.beforeEach((t) => {
test.afterEach.always((t) => {
t.context.fsInterfaceStub.restore();
mock.stop("../../../lib/processors/themeBuilder");
mock.stop("../../../lib/processors/cssOptimizer");
});

test.serial("buildThemes", async (t) => {
t.plan(6);
t.plan(8);

const lessResource = {};

Expand All @@ -37,9 +40,9 @@ test.serial("buildThemes", async (t) => {
write: sinon.stub()
};

const cssResource = {};
const cssRtlResource = {};
const jsonParametersResource = {};
const cssResource = {getPath: () => "fu.css"};
const cssRtlResource = {getPath: () => "fu-rtl.css"};
const jsonParametersResource = {getPath: () => "fu.json"};

t.context.themeBuilderStub.returns([
cssResource,
Expand All @@ -56,15 +59,22 @@ test.serial("buildThemes", async (t) => {
});

t.deepEqual(t.context.themeBuilderStub.callCount, 1,
"Processor should be called once");
"Theme Builder should be called once");

t.deepEqual(t.context.themeBuilderStub.getCall(0).args[0], {
resources: [lessResource],
fs: {},
options: {
compress: true // default
compressJSON: true, // default
compress: false
}
}, "Processor should be called with expected arguments");
}, "Theme Builder should be called with expected arguments");

t.deepEqual(t.context.cssOptimizerStub.callCount, 1, "CSS Optimizer should be called once");
t.deepEqual(t.context.cssOptimizerStub.getCall(0).args[0], {
resources: [cssResource, cssRtlResource],
fs: {}
}, "CSS Optimizer should be called with expected arguments");

t.deepEqual(workspace.write.callCount, 3,
"workspace.write should be called 3 times");
Expand All @@ -75,7 +85,7 @@ test.serial("buildThemes", async (t) => {


test.serial("buildThemes (compress = false)", async (t) => {
t.plan(6);
t.plan(7);

const lessResource = {};

Expand All @@ -90,9 +100,9 @@ test.serial("buildThemes (compress = false)", async (t) => {
write: sinon.stub()
};

const cssResource = {};
const cssRtlResource = {};
const jsonParametersResource = {};
const cssResource = {getPath: () => "fu.css"};
const cssRtlResource = {getPath: () => "fu-rtl.css"};
const jsonParametersResource = {getPath: () => "fu.json"};

t.context.themeBuilderStub.returns([
cssResource,
Expand All @@ -110,15 +120,18 @@ test.serial("buildThemes (compress = false)", async (t) => {
});

t.deepEqual(t.context.themeBuilderStub.callCount, 1,
"Processor should be called once");
"Theme Builder should be called once");

t.deepEqual(t.context.themeBuilderStub.getCall(0).args[0], {
resources: [lessResource],
fs: {},
options: {
compressJSON: false,
compress: false
}
}, "Processor should be called with expected arguments");
}, "Theme Builder should be called with expected arguments");

t.deepEqual(t.context.cssOptimizerStub.callCount, 0, "CSS Optimizer should not be called");

t.deepEqual(workspace.write.callCount, 3,
"workspace.write should be called 3 times");
Expand Down

0 comments on commit fc93f44

Please sign in to comment.