Skip to content

Commit

Permalink
Add test for writeFile
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Nov 4, 2024
1 parent bc98058 commit e3b22c0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/unit_node/_fs/_fs_handle_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import * as path from "@std/path";
import * as path from "jsr:@std/path";
import { Buffer } from "node:buffer";
import * as fs from "node:fs/promises";
import { assert, assertEquals } from "@std/assert";
import { assert, assertEquals } from "jsr:@std/assert";

const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
Expand Down Expand Up @@ -99,7 +99,21 @@ Deno.test("[node/fs filehandle.stat] Get file status", async function () {
const stat = await fileHandle.stat();

assertEquals(stat.isFile(), true);
assertEquals(stat.size, 11);
assertEquals(stat.size, "hello world".length);

await fileHandle.close();
});

Deno.test("[node/fs filehandle.writeFile] Write to file", async function () {
const tempFile: string = await Deno.makeTempFile();
const fileHandle = await fs.open(tempFile, "w");

const str = "hello world";
await fileHandle.writeFile(str);

const data = Deno.readFileSync(tempFile);
await Deno.remove(tempFile);
await fileHandle.close();

assertEquals(decoder.decode(data), "hello world");
})

0 comments on commit e3b22c0

Please sign in to comment.