Skip to content

Commit 041ea0b

Browse files
authored
Merge pull request #172 from observablehq/file-attachment-url-strings
File attachment URL strings (3.3.2)
2 parents e9e9a6f + fcb1084 commit 041ea0b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@observablehq/stdlib",
3-
"version": "3.3.1",
3+
"version": "3.3.2",
44
"license": "ISC",
55
"main": "dist/stdlib.js",
66
"module": "src/index.js",

src/fileAttachment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FileAttachment {
1212
});
1313
}
1414
async url() {
15-
return this._url;
15+
return (await this._url) + "";
1616
}
1717
async blob() {
1818
return (await remote_fetch(this)).blob();

test/fileAttachments-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,23 @@ test("FileAttachments is exported by stdlib", t => {
66
t.equal(FileAttachments.name, "FileAttachments");
77
t.end();
88
});
9+
10+
test("FileAttachment ensures that URLs are strings", async t => {
11+
const fileAttachments = FileAttachments((name) =>
12+
new URL(`https://example.com/${name}.js`)
13+
);
14+
const file = fileAttachments("filename");
15+
t.equal(file.constructor.name, "FileAttachment");
16+
t.equal(await file.url(), "https://example.com/filename.js");
17+
t.end();
18+
});
19+
20+
test("FileAttachment works with Promises that resolve to URLs", async t => {
21+
const fileAttachments = FileAttachments(async (name) =>
22+
new URL(`https://example.com/${name}.js`)
23+
);
24+
const file = fileAttachments("otherfile");
25+
t.equal(file.constructor.name, "FileAttachment");
26+
t.equal(await file.url(), "https://example.com/otherfile.js");
27+
t.end();
28+
});

0 commit comments

Comments
 (0)