|
| 1 | +import assert from "node:assert/strict" |
| 2 | +import { mkdir, mkdtemp, writeFile } from "node:fs/promises" |
| 3 | +import { tmpdir } from "node:os" |
| 4 | +import path from "node:path" |
| 5 | +import { spawnSync } from "node:child_process" |
| 6 | +import test from "node:test" |
| 7 | +import { fileURLToPath } from "node:url" |
| 8 | + |
| 9 | +const repository = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..") |
| 10 | + |
| 11 | +test("performance check supports a repository base path", async () => { |
| 12 | + const fixture = await mkdtemp(path.join(tmpdir(), "zaati-performance-")) |
| 13 | + await mkdir(path.join(fixture, "dist", "assets"), { recursive: true }) |
| 14 | + await mkdir(path.join(fixture, "dist", "data"), { recursive: true }) |
| 15 | + await writeFile( |
| 16 | + path.join(fixture, "dist", "index.html"), |
| 17 | + '<script src="/my-fork/theme-init.js"></script><script src="/my-fork/assets/app.js"></script><link href="/my-fork/assets/app.css" rel="stylesheet">', |
| 18 | + ) |
| 19 | + await writeFile(path.join(fixture, "dist", "theme-init.js"), "document.documentElement.dataset.theme='default'") |
| 20 | + await writeFile(path.join(fixture, "dist", "assets", "app.js"), "console.log('Zaati OS')") |
| 21 | + await writeFile(path.join(fixture, "dist", "assets", "app.css"), "body{margin:0}") |
| 22 | + await writeFile(path.join(fixture, "dist", "data", "dashboard-data.json"), "{}") |
| 23 | + |
| 24 | + const result = spawnSync(process.execPath, [path.join(repository, "scripts", "check-performance.mjs")], { |
| 25 | + cwd: fixture, |
| 26 | + encoding: "utf8", |
| 27 | + }) |
| 28 | + |
| 29 | + assert.equal(result.status, 0, result.stderr) |
| 30 | + assert.match(result.stdout, /Performance budgets:/) |
| 31 | +}) |
0 commit comments