mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-15 07:05:26 +02:00
perf: load document libraries only when needed
This commit is contained in:
@@ -47,15 +47,18 @@ describe("asset build", function () {
|
||||
it("preserves script dependencies and CSS precedence and hashes completed assets", function () {
|
||||
const result = build();
|
||||
expect(result.status, result.stderr).to.equal(0);
|
||||
for (const [bundle, group] of [["core", "coreJsFiles"], ["vendor", "vendorJsFiles"], ["mermaid", "mermaidFiles"]]) {
|
||||
for (const [bundle, group] of [["core", "coreJsFiles"], ["markdown", "markdownFiles"], ["pdf", "pdfFiles"], ["editor", "editorFiles"], ["notebook", "notebookFiles"], ["org", "orgFiles"], ["mermaid", "mermaidFiles"]]) {
|
||||
const context = { assetOrder: [] };
|
||||
vm.runInNewContext(fs.readFileSync(path.join(directory, `public/script/${bundle}.min.js`), "utf8"), context);
|
||||
expect(context.assetOrder).to.deep.equal(groups[group]);
|
||||
if (bundle === "vendor") expect(context.appLoaded).to.equal(true);
|
||||
|
||||
}
|
||||
expect(fs.readFileSync(path.join(directory, "public/css/all.min.css"), "utf8")).to.equal(".cascade{color:#00f}".repeat(groups.cssFiles.length - 1) + ".cascade{color:red}");
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(directory, "public/asset-manifest.json"), "utf8"));
|
||||
expect(Object.keys(manifest)).to.have.length(4);
|
||||
expect(Object.keys(manifest)).to.have.length(9);
|
||||
const appContext = {};
|
||||
vm.runInNewContext(fs.readFileSync(path.join(directory, "public/script/vendor.min.js"), "utf8"), appContext);
|
||||
expect(appContext.appLoaded).to.equal(true);
|
||||
for (const [name, hashed] of Object.entries(manifest)) {
|
||||
const content = fs.readFileSync(path.join(directory, "public", name.endsWith(".css") ? "css" : "script", name));
|
||||
const hash = require("node:crypto").createHash("md5").update(content).digest("hex").slice(0, 10);
|
||||
@@ -72,7 +75,7 @@ describe("asset build", function () {
|
||||
});
|
||||
|
||||
it("fails on invalid JavaScript without publishing a manifest", function () {
|
||||
fs.writeFileSync(path.join(directory, groups.vendorJsFiles[0]), "function {");
|
||||
fs.writeFileSync(path.join(directory, groups.pdfFiles[0]), "function {");
|
||||
const result = build();
|
||||
expect(result.status).not.to.equal(0);
|
||||
expect(result.stderr).to.include("uglify");
|
||||
|
||||
Reference in New Issue
Block a user