deno.land / std@0.166.0 / _util / download_file_test.ts

download_file_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { join, toFileUrl } from "../path/mod.ts";import { delay } from "../async/delay.ts";import { assertEquals } from "../testing/asserts.ts";import { serve } from "../http/server.ts";
import { downloadFile } from "./download_file.ts";
Deno.test("[node/_tools/setup] downloadFile", async () => { const tmpdir = await Deno.makeTempDir(); try { const controller = new AbortController(); const serverPromise = serve( () => { // Responds with 100KB data return new Response("0".repeat(100_000)); }, { signal: controller.signal, port: 8080 }, ); await delay(50);
const downloadedFile = join(tmpdir, "downloaded.txt"); await downloadFile( "http://localhost:8080/dummy.txt", toFileUrl(downloadedFile), ); assertEquals((await Deno.readTextFile(downloadedFile)).length, 100_000); controller.abort(); await serverPromise; } finally { await Deno.remove(tmpdir, { recursive: true }); }});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago