From 8d195e4d97749fe9114b192a71b2c35fe197cd7f Mon Sep 17 00:00:00 2001 From: "zhangyongsheng.dev__dcar" Date: Wed, 15 Jan 2025 15:07:08 +0800 Subject: [PATCH] fix(ext/node): test --- ext/node/polyfills/_fs/_fs_fdatasync.ts | 5 +++++ ext/node/polyfills/_fs/_fs_fsync.ts | 3 +++ ext/node/polyfills/internal/fs/handle.ts | 6 ++++-- tests/node_compat/test/fixtures/baz.js | 8 ++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/node_compat/test/fixtures/baz.js diff --git a/ext/node/polyfills/_fs/_fs_fdatasync.ts b/ext/node/polyfills/_fs/_fs_fdatasync.ts index 02226e1c96..fce4541099 100644 --- a/ext/node/polyfills/_fs/_fs_fdatasync.ts +++ b/ext/node/polyfills/_fs/_fs_fdatasync.ts @@ -5,6 +5,7 @@ import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; import { FsFile } from "ext:deno_fs/30_fs.js"; +import { promisify } from "ext:deno_node/internal/util.mjs"; export function fdatasync( fd: number, @@ -19,3 +20,7 @@ export function fdatasync( export function fdatasyncSync(fd: number) { new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncDataSync(); } + +export const fdatasyncPromise = promisify(fdatasync) as ( + fd: number, +) => Promise; diff --git a/ext/node/polyfills/_fs/_fs_fsync.ts b/ext/node/polyfills/_fs/_fs_fsync.ts index a07f440778..1f31dbd808 100644 --- a/ext/node/polyfills/_fs/_fs_fsync.ts +++ b/ext/node/polyfills/_fs/_fs_fsync.ts @@ -5,6 +5,7 @@ import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; import { FsFile } from "ext:deno_fs/30_fs.js"; +import { promisify } from "ext:deno_node/internal/util.mjs"; export function fsync( fd: number, @@ -19,3 +20,5 @@ export function fsync( export function fsyncSync(fd: number) { new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncSync(); } + +export const fsyncPromise = promisify(fsync) as (fd: number) => Promise; diff --git a/ext/node/polyfills/internal/fs/handle.ts b/ext/node/polyfills/internal/fs/handle.ts index 4412e79c15..f18f1e5a6c 100644 --- a/ext/node/polyfills/internal/fs/handle.ts +++ b/ext/node/polyfills/internal/fs/handle.ts @@ -16,6 +16,8 @@ import { import { ftruncatePromise } from "ext:deno_node/_fs/_fs_ftruncate.ts"; export type { BigIntStats, Stats } from "ext:deno_node/_fs/_fs_stat.ts"; import { writevPromise, WriteVResult } from "ext:deno_node/_fs/_fs_writev.ts"; +import { fdatasyncPromise } from "ext:deno_node/_fs/_fs_fdatasync.ts"; +import { fsyncPromise } from "ext:deno_node/_fs/_fs_fsync.ts"; interface WriteResult { bytesWritten: number; @@ -159,11 +161,11 @@ export class FileHandle extends EventEmitter { } datasync(): Promise { - return fsCall(promises.fdatasync, this); + return fsCall(fdatasyncPromise, this); } sync(): Promise { - return fsCall(promises.fsync, this); + return fsCall(fsyncPromise, this); } utimes( diff --git a/tests/node_compat/test/fixtures/baz.js b/tests/node_compat/test/fixtures/baz.js new file mode 100644 index 0000000000..27b52d236c --- /dev/null +++ b/tests/node_compat/test/fixtures/baz.js @@ -0,0 +1,8 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 20.11.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +module.exports = 'perhaps I work';