1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/cli/tests/unit_node
nasa 6f02bfd181
feat(node_compat): Added base implementation of FileHandle (#19294)
<!--
Before submitting a PR, please read https://deno.com/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->


## WHY

ref: https://github.com/denoland/deno/issues/19165

Node's fs/promises includes a FileHandle class, but deno does not. The
open function in Node's fs/promises returns a FileHandle, which provides
an IO interface to the file. However, deno's open function returns a
resource id.


### deno 

```js
> const fs = await import("node:fs/promises");
undefined
> const file3 = await fs.open("./README.md");
undefined
> file3
3
> file3.read
undefined
Node:
```

### Node
```js
> const fs = await import("fs/promises");
undefined
>   const file3 = await fs.open("./tests/e2e_unit/testdata/file.txt");
undefined
> file3
FileHandle {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  close: [Function: close],
  [Symbol(kCapture)]: false,
  [Symbol(kHandle)]: FileHandle {},
  [Symbol(kFd)]: 24,
  [Symbol(kRefs)]: 1,
  [Symbol(kClosePromise)]: null
}
> file3.read
[Function: read]
```


To be compatible with Node, deno's open function should also return a
FileHandle.

## WHAT

I have implemented the first step in adding a FileHandle.

- Changed the return value of the open function to a FileHandle object
- Implemented the readFile method in FileHandle
- Add test code


## What to do next
This PR is the first step in adding a FileHandle, and there are things
that should be done next.

- Add functionality equivalent to Node's FileHandle to FileHandle
(currently there is only readFile)

---------

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-06-09 01:13:20 +02:00
..
_fs feat(node_compat): Added base implementation of FileHandle (#19294) 2023-06-09 01:13:20 +02:00
crypto chore(cli): One Rust test per JS and Node unit test file (#19199) 2023-05-22 13:35:59 -06:00
internal refactor(node/crypto): scrypt polyfill to rust (#18746) 2023-04-18 14:29:10 +02:00
testdata fix(node): add missing process.reallyExit method (#19326) 2023-06-09 01:13:18 +02:00
_test_utils.ts test(ext/node): port _fs tests from std/node (#18262) 2023-03-20 01:10:39 +09:00
async_hooks_test.ts BREAKING(unstable): remove "Deno.serve(handler, options)" overload (#18759) 2023-04-26 14:54:03 +02:00
child_process_test.ts fix(runtime): add missing SIGIOT alias to SIGABRT (#19333) 2023-06-09 01:13:19 +02:00
fs_test.ts fix(ext/node): implement "ascii" encoding for node:fs writeFile() (#18097) 2023-03-16 12:16:03 +09:00
http_test.ts refactor: further work on node http client (#19327) 2023-06-09 01:13:18 +02:00
module_test.ts fix(node): duplicate node_module suffixes (#19222) 2023-05-23 12:46:14 +02:00
os_test.ts test(ext/node): add os_test.ts (#19305) 2023-05-29 15:03:14 +02:00
process_test.ts fix(node): don't close stdio streams (#19256) 2023-06-09 01:13:20 +02:00
querystring_test.ts test(ext/node): add querystring_test.ts and readline_test.ts (#18256) 2023-03-19 19:49:11 +09:00
readline_test.ts fix(npm): process not defined in readline (#19184) 2023-05-18 15:42:27 -04:00
string_decoder_test.ts test(ext/node): add string_decoder_test.ts from std/node (#18473) 2023-03-29 18:32:29 +09:00
timers_test.ts test(ext/node): add timers_tests.ts from std/node (#18472) 2023-03-29 18:34:37 +09:00
tls_test.ts test(ext/node): add tls_test (#17871) 2023-02-23 12:27:29 +09:00
tty_test.ts test(ext/node): add tty_test and util_test (#17868) 2023-02-23 12:28:19 +09:00
util_test.ts Revert "refactor(ext/node): Use Deno.inspect (#17960)" (#18491) 2023-03-30 15:33:28 +00:00
v8_test.ts fix(node): make 'v8.setFlagsFromString' a noop (#19271) 2023-05-26 15:41:03 +02:00
worker_threads_test.ts fix(ext/node): add basic node:worker_threads support (#19192) 2023-05-23 20:56:29 +02:00