Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
"packages": ["nodejs@22"],
"shell": {
"init_hook": [
"echo 'Welcome to devbox!' > /dev/null"
],
"init_hook": ["echo 'Welcome to devbox!' > /dev/null"],
"scripts": {
"test": [
"echo \"Error: no test specified\" && exit 1"
]
"test": ["npm test"]
}
}
}
98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"globals": "^17.4.0",
"happy-dom": "^20.8.3",
"postcss": "^8.5.8",
"postcss-preset-env": "^11.2.0",
"prettier": "^3.8.1",
Expand Down
32 changes: 21 additions & 11 deletions test/build.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from "node:child_process";
import { readFileSync, readdirSync } from "node:fs";
import { resolve } from "node:path";
import { beforeAll, describe, expect, test } from "vitest";
import { beforeAll, beforeEach, describe, expect, test } from "vitest";

const distDir = resolve(import.meta.dirname, "../dist");

Expand All @@ -13,22 +13,33 @@ describe("production build", () => {
});
});

test("outputs index.html", () => {
beforeEach(() => {
const html = readFileSync(resolve(distDir, "index.html"), "utf-8");
expect(html.toLowerCase()).toContain("<!doctype html>");
document.documentElement.innerHTML = html;
});

test("outputs index.html", () => {
expect(document.querySelector("html")).not.toBeNull();
expect(document.querySelector("head")).not.toBeNull();
expect(document.querySelector("body")).not.toBeNull();
});

test("html contains expected page structure", () => {
const html = readFileSync(resolve(distDir, "index.html"), "utf-8");
expect(html).toContain("<title>Tailwind CSS Template</title>");
expect(html).toMatch(/Tailwind CSS Template\s*<\/h1>/);
expect(html).toContain("plain-old-HTML template using Tailwind CSS");
expect(document.querySelector("title").textContent).toBe(
"Tailwind CSS Template"
);
expect(document.querySelector("h1").textContent).toContain(
"Tailwind CSS Template"
);
expect(document.body.textContent).toContain(
"plain-old-HTML template using Tailwind CSS"
);
});

test("html links to a compiled css file", () => {
const html = readFileSync(resolve(distDir, "index.html"), "utf-8");
const cssLinkMatch = html.match(/href="\.\/assets\/[^"]+\.css"/);
expect(cssLinkMatch).not.toBeNull();
const link = document.querySelector('link[rel="stylesheet"]');
expect(link).not.toBeNull();
expect(link.getAttribute("href")).toMatch(/\.\/assets\/.*\.css$/);
});

test("compiled css contains tailwind utility styles", () => {
Expand All @@ -37,7 +48,6 @@ describe("production build", () => {
expect(cssFile).toBeDefined();

const css = readFileSync(resolve(distDir, "assets", cssFile), "utf-8");
// Tailwind should have compiled these utilities used in index.html
expect(css).toContain("font-bold");
expect(css).toContain("text-center");
expect(css.length).toBeGreaterThan(100);
Expand Down
11 changes: 10 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ export default {
emptyOutDir: true
},
test: {
root: "."
root: ".",
environment: "happy-dom",
environmentOptions: {
happyDOM: {
settings: {
disableCSSFileLoading: true,
handleDisabledFileLoadingAsSuccess: true
}
}
}
}
};