Initial Commit
This commit is contained in:
69
packages/foundation/data/templates/tests/tree-shake.test.ts
Normal file
69
packages/foundation/data/templates/tests/tree-shake.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Tree-shake smoke test.
|
||||
*
|
||||
* Verifies that each sub-module can be imported in isolation without pulling
|
||||
* in unrelated code. This acts as a proxy for correct `sideEffects: false`
|
||||
* behaviour and clean ESM boundaries.
|
||||
*/
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
describe("tree-shake isolation", () => {
|
||||
it("can import only escape utils", { timeout: 30000 }, async () => {
|
||||
const mod = await import("../src/utils/escape.js");
|
||||
expect(typeof mod.escapeRegex).toBe("function");
|
||||
expect(typeof mod.isEscaped).toBe("function");
|
||||
expect(typeof mod.unescapeTemplate).toBe("function");
|
||||
});
|
||||
|
||||
it("can import only format utils", { timeout: 30000 }, async () => {
|
||||
const mod = await import("../src/utils/format.js");
|
||||
expect(typeof mod.pad).toBe("function");
|
||||
expect(typeof mod.formatDate).toBe("function");
|
||||
expect(typeof mod.generateUuid).toBe("function");
|
||||
expect(typeof mod.generateNanoid).toBe("function");
|
||||
});
|
||||
|
||||
it("can import only nested-value utils", { timeout: 30000 }, async () => {
|
||||
const mod = await import("../src/utils/nested-value.js");
|
||||
expect(typeof mod.getNestedValue).toBe("function");
|
||||
expect(typeof mod.hasNestedPath).toBe("function");
|
||||
expect(typeof mod.setNestedValue).toBe("function");
|
||||
});
|
||||
|
||||
it("can import ParseState without TemplateEngine", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
const mod = await import("../src/engine/ParseState.js");
|
||||
expect(typeof mod.createParseState).toBe("function");
|
||||
expect(typeof mod.cloneParseState).toBe("function");
|
||||
});
|
||||
|
||||
it("can import a single plugin without loading all others", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
const mod = await import(
|
||||
"../src/plugins/variables/DotNotationPlugin.js"
|
||||
);
|
||||
expect(typeof mod.createDotNotationPlugin).toBe("function");
|
||||
});
|
||||
|
||||
it("can import schemas in isolation", { timeout: 30000 }, async () => {
|
||||
const mod = await import("../src/schemas/templates.schemas.js");
|
||||
expect(mod.TemplateEngineOptionsSchema).toBeDefined();
|
||||
expect(mod.ParseOptionsSchema).toBeDefined();
|
||||
expect(mod.PluginPrioritySchema).toBeDefined();
|
||||
});
|
||||
|
||||
it("minimalPreset does not import dynamic plugins", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
// If minimalPreset somehow pulled in DateTimePlugin the import would
|
||||
// still succeed, but this test documents the intended isolation.
|
||||
const { minimalPreset } = await import("../src/presets/minimal.js");
|
||||
const preset = minimalPreset();
|
||||
expect(preset.plugins.map((p) => p.name)).toEqual(
|
||||
expect.arrayContaining(["array-index", "dot-notation"])
|
||||
);
|
||||
expect(preset.plugins).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user