| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import assert from "node:assert/strict";
- import fs from "node:fs/promises";
- import os from "node:os";
- import path from "node:path";
- import test from "node:test";
- import { compileSass } from "../src/actions/compileSass/index.js";
- async function setupStylesheetFixture(t) {
- const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "rhedyn-sass-"));
- const stylesDir = path.join(tempDir, "styles");
- const outDir = path.join(tempDir, "dist");
- const filePath = path.join(stylesDir, "main.scss");
- const fileOutputPath = path.join(outDir, "static/styles/main.css");
- t.after(async () => {
- await fs.rm(tempDir, { force: true, recursive: true });
- });
- await fs.mkdir(stylesDir, { recursive: true });
- await fs.mkdir(path.dirname(fileOutputPath), { recursive: true });
- await fs.writeFile(filePath, "body { color: red; }", "utf8");
- return { tempDir, outDir, filePath, fileOutputPath };
- }
- test("compileSass does not include css in detail by default", async t => {
- const { tempDir, outDir, filePath, fileOutputPath } = await setupStylesheetFixture(t);
- const result = await compileSass({
- config: {
- filePath,
- fileOutputPath,
- },
- meta: {
- opts: {
- outDir,
- runDir: tempDir,
- },
- },
- });
- assert.equal(result.detail.href, "/static/styles/main.css");
- assert.equal("css" in result.detail, false);
- });
- test("compileSass includes css in detail when configured", async t => {
- const { tempDir, outDir, filePath, fileOutputPath } = await setupStylesheetFixture(t);
- const result = await compileSass({
- config: {
- filePath,
- fileOutputPath,
- includeCssInDetail: true,
- },
- meta: {
- opts: {
- outDir,
- runDir: tempDir,
- },
- },
- });
- assert.equal(result.detail.href, "/static/styles/main.css");
- assert.equal(typeof result.detail.css, "string");
- assert.equal(result.detail.css.includes("color:red"), true);
- });
|