Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10352959
test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
test.ts
View Options
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
Details
Attached
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)
Attached To
Mode
rSTREAM tempstream
Attached
Detach File
Event Timeline
Log In to Comment