deno.land / std@0.166.0 / examples / curl_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
36
37
38
39
40
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { serve } from "../http/server.ts";import { assertStrictEquals } from "../testing/asserts.ts";import { dirname, fromFileUrl } from "../path/mod.ts";
const moduleDir = dirname(fromFileUrl(import.meta.url));
Deno.test({ name: "[examples/curl] send a request to a specified url", fn: async () => { const abortController = new AbortController(); const serverPromise = serve( () => new Response("Hello world"), { signal: abortController.signal, port: 8081 }, ); const decoder = new TextDecoder(); const command = new Deno.Command(Deno.execPath(), { args: [ "run", "--quiet", "--allow-net", "curl.ts", "http://localhost:8081", ], cwd: moduleDir, }); const { stdout } = await command.output();
try { const actual = decoder.decode(stdout).trim(); const expected = "Hello world";
assertStrictEquals(actual, expected); } finally { abortController.abort(); await serverPromise; } },});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2448

Version Info

Tagged at
2 months ago