summaryrefslogtreecommitdiff
path: root/std/fs/write_file_str_test.ts
blob: 279afe3d1a86fc1b48170b173b0f6a765fdcb774 (plain)
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
import { assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { writeFileStr, writeFileStrSync } from "./write_file_str.ts";

const testdataDir = path.resolve("fs", "testdata");

Deno.test(function testReadFileSync(): void {
  const jsonFile = path.join(testdataDir, "write_file_1.json");
  const content = "write_file_str_test";
  writeFileStrSync(jsonFile, content);

  // make sure file have been create.
  Deno.statSync(jsonFile);

  const result = new TextDecoder().decode(Deno.readFileSync(jsonFile));

  // remove test file
  Deno.removeSync(jsonFile);

  assertEquals(content, result);
});

Deno.test(async function testReadFile(): Promise<void> {
  const jsonFile = path.join(testdataDir, "write_file_2.json");
  const content = "write_file_str_test";
  await writeFileStr(jsonFile, content);

  // make sure file have been create.
  await Deno.stat(jsonFile);

  const result = new TextDecoder().decode(await Deno.readFile(jsonFile));

  // remove test file
  await Deno.remove(jsonFile);

  assertEquals(content, result);
});