Page MenuHomeSealhub

test.ts
No OneTemporary

import assert from "assert";
import { Readable } from "stream";
import { promisify } from "util";
import { Templatable, tempstream } from ".";
import { Slot } from "./slot";
import streamToString from "./tostring";
const name = new Slot("noname");
const st = (time: number, cb: () => void) => setTimeout(cb, time);
const sleep = promisify(st);
// a test
function html(
strings: TemplateStringsArray,
...params: Templatable[]
): Readable {
const title = new Slot("Default page title");
setTimeout(() => title.set("Changed page title"), 3000);
console.error(
"try playing around with the above timeout. Weird things happen when you go to e.g. 3000"
);
// process.exit(1);
return tempstream/* HTML */ `<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>${title}</title>
</head>
<body>
${tempstream(strings, ...params)}
</body> `;
}
// template`hello ${world}, and ${name}`.pipe(process.stdout);
describe("tempstream", () => {
it("renders properly in the basic case", async () => {
const list_items = Promise.resolve(
["one", "two", "three"].map((e) => `<li>${e}</li>`)
);
const title = new Slot("Default page title");
setTimeout(() => title.set("Changed page title"), 20);
const slept = sleep(100).then(() => "slept");
const result =
await streamToString(tempstream/* HTML */ `<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>${title}</title>
</head>
<body>
hello World, I ${slept}.
<ul>
${list_items}
</ul>
</body> `);
assert.strictEqual(
result,
`<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Changed page title</title>
</head>
<body>
hello World, I slept.
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</body> `
);
});
});

File Metadata

Mime Type
text/html
Expires
Mon, Nov 3, 01:50 (7 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1030577
Default Alt Text
test.ts (1 KB)

Event Timeline