release: WRNexusJS 0.4.0
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { test, expect, afterEach } from "bun:test";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { loadAppConfig, resolveProfile, loadEnv } from "../src/index.ts";
|
||||
import { loadAppConfig, resolveProfile, loadEnv, renderStyles } from "../src/index.ts";
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.WRNEXUS_PROFILE;
|
||||
@@ -66,3 +66,94 @@ test("loadEnv layers .env files by precedence; real env always wins", () => {
|
||||
for (const k of ["BASE", "SHARED", "PROD_ONLY", "QUOTED", "REALVAR"]) delete process.env[k];
|
||||
}
|
||||
});
|
||||
|
||||
test("package-aware styles add relative imports and Tailwind scan sources", async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-styles-"));
|
||||
try {
|
||||
const appDir = join(root, "app");
|
||||
const entry = join(appDir, "styles", "global.css");
|
||||
const packageSource = join(root, "packages", "system", "components");
|
||||
const packageCss = join(root, "packages", "system", "system.css");
|
||||
mkdirSync(join(appDir, "styles"), { recursive: true });
|
||||
mkdirSync(packageSource, { recursive: true });
|
||||
writeFileSync(entry, '@import "tailwindcss";\n');
|
||||
writeFileSync(packageCss, ".system{}\n");
|
||||
let wrapper = "";
|
||||
const css = await renderStyles(
|
||||
{
|
||||
entryPath: entry,
|
||||
appDir,
|
||||
appRoot: root,
|
||||
mode: "development",
|
||||
sources: [packageSource],
|
||||
entries: [packageCss],
|
||||
},
|
||||
{
|
||||
process: async ({ entryPath, originalEntryPath, sources }) => {
|
||||
expect(originalEntryPath).toBe(entry);
|
||||
expect(sources).toEqual([packageSource]);
|
||||
wrapper = readFileSync(entryPath!, "utf8");
|
||||
return ".compiled{}";
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(css).toBe(".compiled{}");
|
||||
expect(wrapper).toContain('@import "../../app/styles/global.css";');
|
||||
expect(wrapper).toContain('@source "../../packages/system/components";');
|
||||
expect(wrapper).not.toContain(root.replace(/\\/g, "/"));
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("production style processors fail closed by default", async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-styles-"));
|
||||
try {
|
||||
const entry = join(root, "global.css");
|
||||
writeFileSync(entry, "body{}\n");
|
||||
await expect(
|
||||
renderStyles(
|
||||
{ entryPath: entry, appDir: root, appRoot: root, mode: "production" },
|
||||
{
|
||||
process: () => {
|
||||
throw new Error("processor unavailable");
|
||||
},
|
||||
},
|
||||
),
|
||||
).rejects.toThrow("Stylesheet processing failed");
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("package CSS entries build without an application stylesheet", async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-package-styles-"));
|
||||
try {
|
||||
const packageCss = join(root, "packages", "system", "system.css");
|
||||
mkdirSync(join(root, "packages", "system"), { recursive: true });
|
||||
writeFileSync(packageCss, ".system{}\n");
|
||||
let wrapper = "";
|
||||
|
||||
const css = await renderStyles(
|
||||
{
|
||||
entryPath: null,
|
||||
appDir: join(root, "app"),
|
||||
appRoot: root,
|
||||
mode: "development",
|
||||
entries: [packageCss],
|
||||
},
|
||||
{
|
||||
process: async ({ entryPath, originalEntryPath }) => {
|
||||
expect(originalEntryPath).toBeNull();
|
||||
wrapper = readFileSync(entryPath!, "utf8");
|
||||
return ".package-compiled{}";
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(css).toBe(".package-compiled{}");
|
||||
expect(wrapper).toContain('@import "../../packages/system/system.css";');
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user