1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-13 19:12:20 -05:00
denoland-deno/cli/tests/unit
Kenta Moriuchi ab60d9e6a3
fix: strict type check for cross realms (#21669)
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when
using `Object.prototype.isPrototypeOf` to check built-in types.

```js
import vm from "node:vm";

const err = new Error();
const crossErr = vm.runInNewContext(`new Error()`);

console.assert( !(crossErr instanceof Error) );
console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) );
```

This PR changes to check using internal slots solves them.

---

current: 

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error {}
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
Date {}
```

this PR:

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error: message
    at <anonymous>:1:1
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
2018-12-10T02:26:59.002Z
```

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-01-04 20:34:55 +01:00
..
abort_controller_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
blob_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
body_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
broadcast_channel_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
buffer_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
build_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
cache_api_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
chmod_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
chown_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
command_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
console_test.ts fix: strict type check for cross realms (#21669) 2024-01-04 20:34:55 +01:00
copy_file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
cron_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
custom_event_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
dir_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
dom_exception_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
error_stack_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
error_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
esnext_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
event_target_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
event_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
fetch_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
ffi_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
filereader_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
files_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
flock_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
fs_events_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
get_random_values_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
globals_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
headers_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
http_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
image_data_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
internals_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
intl_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
io_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
jupyter_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
kv_queue_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
kv_queue_test_no_db_close.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
kv_queue_undelivered_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
kv_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
link_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
make_temp_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
message_channel_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
mkdir_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
navigator_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
net_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
network_interfaces_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
opcall_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
os_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
path_from_url_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
performance_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
permissions_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
process_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
progressevent_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
promise_hooks_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
read_dir_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
read_file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
read_link_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
read_text_file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
README.md chore: fix flaky netListenUnrefAndRef (#16892) 2022-12-02 12:41:52 -05:00
real_path_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
ref_unref_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
remove_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
rename_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
request_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
resources_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
response_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
serve_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
signal_test.ts fix(cli): make signals tests more reliable (#21772) 2024-01-04 20:34:54 +01:00
stat_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
stdio_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
streams_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
structured_clone_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
symlink_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
sync_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
test_util.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
testing_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
text_encoding_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
timers_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
tls_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
truncate_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
tty_color_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
tty_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
umask_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
url_search_params_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
url_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
urlpattern_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
utime_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
version_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
wasm_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
webcrypto_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
webgpu_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
websocket_test.ts fix(ext/http): use arraybuffer binaryType for server websocket (#21741) 2024-01-04 20:34:52 +01:00
webstorage_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
worker_permissions_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
worker_types.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
write_file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00
write_text_file_test.ts chore: update copyright to 2024 (#21753) 2024-01-04 20:34:51 +01:00

Deno runtime tests

Files in this directory are unit tests for Deno runtime.

Testing Deno runtime code requires checking API under different runtime permissions. To accomplish this all tests exercised are created using Deno.test() function.

import {} from "./test_util.ts";

Deno.test(function simpleTestFn(): void {
  // test code here
});

Deno.test(
  {
    ignore: Deno.build.os === "windows",
    permissions: { read: true, write: true },
  },
  function complexTestFn(): void {
    // test code here
  },
);

Running tests

There are two ways to run unit_test_runner.ts:

# Run all tests.
cargo run --bin deno -- test --allow-all --unstable --location=http://js-unit-tests/foo/bar cli/tests/unit/

# Run a specific test module
cargo run --bin deno -- test --allow-all --unstable --location=http://js-unit-tests/foo/bar cli/tests/unit/files_test.ts

Http server

target/debug/test_server is required to run when one's running unit tests. During CI it's spawned automatically, but if you want to run tests manually make sure that server is spawned otherwise there'll be cascade of test failures.