Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Jan 21, 2022
1 parent ec73582 commit 10e6ce6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
1 change: 0 additions & 1 deletion lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {SectionType} = require("./BundleDefinition");
const escapePropertiesFile = require("../utils/escapePropertiesFile");
const log = require("@ui5/logger").getLogger("lbt:bundle:AutoSplitter");

const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9/i;
const xmlHtmlPrePattern = /<(?:\w+:)?pre\b/;

/**
Expand Down
64 changes: 32 additions & 32 deletions test/lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const test = require("ava");
const sinon = require("sinon");
const terser = require("terser");
const {pd} = require("pretty-data");
const BundleResolver = require("../../../../lib/lbt/bundle/Resolver");
const AutoSplitter = require("../../../../lib/lbt/bundle/AutoSplitter");
Expand Down Expand Up @@ -155,11 +154,11 @@ test("_calcMinSize: compressedSize", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.js"), 123);
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.js"), 123);
});

test("_calcMinSize: js resource", async (t) => {
test("_calcMinSize: js resource (optimize=false)", async (t) => {
const pool = {
findResourceWithInfo: function() {
return {
Expand All @@ -172,13 +171,11 @@ test("_calcMinSize: js resource", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.js"), 13);
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.js"), 13);
});


test.serial("_calcMinSize: uglify js resource", async (t) => {
const stubTerser = sinon.stub(terser, "minify").resolves({code: "123"});
test.serial("_calcMinSize: js resource (optimize=true)", async (t) => {
const pool = {
findResourceWithInfo: function() {
return {
Expand All @@ -191,10 +188,13 @@ test.serial("_calcMinSize: uglify js resource", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
autpSplitter.optimize = true;
t.deepEqual(await autpSplitter._calcMinSize("mymodule.js"), 3);
stubTerser.restore();
const autoSplitter = new AutoSplitter(pool);

// The optimize flag should not be taken into account and the resource
// should not get optimized by the AutoSplitter.
autoSplitter.optimize = true;

t.deepEqual(await autoSplitter._calcMinSize("mymodule.js"), 13);
});

test("_calcMinSize: properties resource", async (t) => {
Expand All @@ -221,8 +221,8 @@ test("_calcMinSize: properties resource", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.properties"), 10, "length of 1234\\u00df");
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.properties"), 10, "length of 1234\\u00df");
});

test("_calcMinSize: xml view resource", async (t) => {
Expand All @@ -234,9 +234,9 @@ test("_calcMinSize: xml view resource", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
autpSplitter.optimizeXMLViews = true;
t.deepEqual(await autpSplitter._calcMinSize("mymodule.view.xml"), 5);
const autoSplitter = new AutoSplitter(pool);
autoSplitter.optimizeXMLViews = true;
t.deepEqual(await autoSplitter._calcMinSize("mymodule.view.xml"), 5);
});

test("_calcMinSize: xml view resource without optimizeXMLViews", async (t) => {
Expand All @@ -248,8 +248,8 @@ test("_calcMinSize: xml view resource without optimizeXMLViews", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.view.xml"), 6);
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.view.xml"), 6);
});

test.serial("_calcMinSize: optimize xml view resource", async (t) => {
Expand All @@ -262,10 +262,10 @@ test.serial("_calcMinSize: optimize xml view resource", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
autpSplitter.optimizeXMLViews = true;
autpSplitter.optimize = true;
t.deepEqual(await autpSplitter._calcMinSize("mymodule.view.xml"), 6);
const autoSplitter = new AutoSplitter(pool);
autoSplitter.optimizeXMLViews = true;
autoSplitter.optimize = true;
t.deepEqual(await autoSplitter._calcMinSize("mymodule.view.xml"), 6);
stubXmlmin.restore();
});

Expand All @@ -279,11 +279,11 @@ test.serial("_calcMinSize: optimize xml view resource and pre tag", async (t) =>
};
}
};
const autpSplitter = new AutoSplitter(pool);
autpSplitter.optimizeXMLViews = true;
autpSplitter.optimize = true;
const autoSplitter = new AutoSplitter(pool);
autoSplitter.optimizeXMLViews = true;
autoSplitter.optimize = true;
t.false(stubXmlmin.called, "xmlmin should not be called");
t.deepEqual(await autpSplitter._calcMinSize("mymodule.view.xml"), 19);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.view.xml"), 19);
stubXmlmin.restore();
});

Expand All @@ -293,8 +293,8 @@ test("_calcMinSize: no resource", async (t) => {
return null;
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.properties"), 0);
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.properties"), 0);
});

test("_calcMinSize: unknown resource with info", async (t) => {
Expand All @@ -307,6 +307,6 @@ test("_calcMinSize: unknown resource with info", async (t) => {
};
}
};
const autpSplitter = new AutoSplitter(pool);
t.deepEqual(await autpSplitter._calcMinSize("mymodule.mjs"), 47);
const autoSplitter = new AutoSplitter(pool);
t.deepEqual(await autoSplitter._calcMinSize("mymodule.mjs"), 47);
});

0 comments on commit 10e6ce6

Please sign in to comment.