deno/tests/specs/bundle/html/assert-helpers.ts
Nathan Whitaker 4e4bbf2fcc
feat(bundle): support html entrypoint (#29856)
For instance

`deno bundle --outdir dist index.html`

It will find scripts referenced in the html, bundle them, and then
update the paths in index.html for the bundled assets.

Right now it doesn't handle other assets (from `link` elements), but it
could
2025-09-09 12:18:10 -07:00

32 lines
926 B
TypeScript

export function assertFileContains(path: string, pattern: string | RegExp) {
const contents = Deno.readTextFileSync(path);
let matcher: (s: string) => boolean;
if (typeof pattern === "string") {
matcher = (s) => s.includes(pattern);
} else {
matcher = (s) => pattern.test(s);
}
if (!matcher(contents)) {
let message = "";
message += "file does not contain the pattern: " + path + "\n";
message += "wanted: " + pattern + "\n";
message += "found: " + contents + "\n";
throw new Error(message);
}
}
export function assertFileDoesNotContain(
path: string,
pattern: string | RegExp,
) {
try {
assertFileContains(path, pattern);
} catch (_e) {
return;
}
let message = "";
message += "file contains the pattern: " + path + "\n";
message += "did not want: " + pattern + "\n";
message += "found: " + Deno.readTextFileSync(path) + "\n";
throw new Error(message);
}