General source code refactoring

This commit is contained in:
2026-09-17 12:07:01 -03:00
parent 4421b28efe
commit ac817a69d4
92 changed files with 18211 additions and 19394 deletions

View File

@@ -1,21 +1,9 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const { loadApplication, composeScript } = require("./support/application.cjs");
const root = path.resolve(__dirname, "..");
function loadContentHelpers() {
const source = fs.readFileSync(path.join(root, "src", "content.js"), "utf8");
const marker = "\n if (insertTile()) {";
const instrumented = source.replace(marker, `
globalThis.__consumptionTrendTest = {
normalizeConsumptionTrendItems,
formatConsumptionPointLabel,
createNiceConsumptionMaximum,
calculateAverageConsumption
};
${marker}`);
const context = {
chrome: { runtime: { onMessage: { addListener() {} } } },
document: { getElementById: () => ({}) },
@@ -36,13 +24,12 @@ ${marker}`);
Math
};
vm.runInNewContext(instrumented, context);
return context.__consumptionTrendTest;
return loadApplication("content", context).consumptionModel;
}
function loadBackground(fetchCalls) {
let listener;
const source = fs.readFileSync(path.join(root, "src", "background.js"), "utf8");
const source = composeScript("background");
const headers = {
get(name) {
return name.toLowerCase() === "content-type" ? "application/json" : null;