0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

Merge remote-tracking branch 'upstream/main' into check-workspace-member-compiler-options

This commit is contained in:
Nayeem Rahman 2024-12-05 08:04:42 +00:00
commit b3bd581919
554 changed files with 30844 additions and 641 deletions

85
Cargo.lock generated
View file

@ -1676,7 +1676,7 @@ dependencies = [
"serde", "serde",
"thiserror 1.0.64", "thiserror 1.0.64",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1766,7 +1766,7 @@ dependencies = [
"tokio", "tokio",
"uuid", "uuid",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1854,7 +1854,7 @@ dependencies = [
"log", "log",
"napi_sym", "napi_sym",
"thiserror 1.0.64", "thiserror 1.0.64",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1973,7 +1973,7 @@ dependencies = [
"url", "url",
"webpki-root-certs", "webpki-root-certs",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
"x25519-dalek", "x25519-dalek",
"x509-parser", "x509-parser",
"yoke", "yoke",
@ -2173,7 +2173,7 @@ dependencies = [
"uuid", "uuid",
"which 4.4.2", "which 4.4.2",
"winapi", "winapi",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -2192,9 +2192,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_task_shell" name = "deno_task_shell"
version = "0.20.1" version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e09966ce29f8d26b652a43355397e1df43b85759e7824196bf0ceaeaa9a2f4" checksum = "fa3763bc068e17b6d488fb73ecda463c13ef792b0a5288b6018bc2119becd635"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures", "futures",
@ -2205,6 +2205,7 @@ dependencies = [
"path-dedot", "path-dedot",
"thiserror 1.0.64", "thiserror 1.0.64",
"tokio", "tokio",
"windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -4557,7 +4558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.52.4", "windows-targets 0.48.5",
] ]
[[package]] [[package]]
@ -8622,7 +8623,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [ dependencies = [
"windows-core", "windows-core",
"windows-targets 0.52.4", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8631,7 +8632,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [ dependencies = [
"windows-targets 0.52.4", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8649,7 +8650,16 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [ dependencies = [
"windows-targets 0.52.4", "windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -8669,17 +8679,18 @@ dependencies = [
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm 0.52.4", "windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.4", "windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.4", "windows_i686_gnu 0.52.6",
"windows_i686_msvc 0.52.4", "windows_i686_gnullvm",
"windows_x86_64_gnu 0.52.4", "windows_i686_msvc 0.52.6",
"windows_x86_64_gnullvm 0.52.4", "windows_x86_64_gnu 0.52.6",
"windows_x86_64_msvc 0.52.4", "windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
] ]
[[package]] [[package]]
@ -8690,9 +8701,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
@ -8702,9 +8713,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
@ -8714,9 +8725,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
@ -8726,9 +8743,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
@ -8738,9 +8755,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
@ -8750,9 +8767,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
@ -8762,9 +8779,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.4" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "winnow" name = "winnow"

View file

@ -240,7 +240,7 @@ nix = "=0.27.1"
# windows deps # windows deps
junction = "=0.2.0" junction = "=0.2.0"
winapi = "=0.3.9" winapi = "=0.3.9"
windows-sys = { version = "0.52.0", features = ["Win32_Foundation", "Win32_Media", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_WindowsProgramming", "Wdk", "Wdk_System", "Wdk_System_SystemInformation", "Win32_Security", "Win32_System_Pipes", "Wdk_Storage_FileSystem", "Win32_System_Registry", "Win32_System_Kernel"] } windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Media", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_WindowsProgramming", "Wdk", "Wdk_System", "Wdk_System_SystemInformation", "Win32_Security", "Win32_System_Pipes", "Wdk_Storage_FileSystem", "Win32_System_Registry", "Win32_System_Kernel", "Win32_System_Threading", "Win32_UI", "Win32_UI_Shell"] }
winres = "=0.1.12" winres = "=0.1.12"
[profile.release] [profile.release]

View file

@ -83,7 +83,7 @@ deno_path_util.workspace = true
deno_resolver.workspace = true deno_resolver.workspace = true
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_semver.workspace = true deno_semver.workspace = true
deno_task_shell = "=0.20.1" deno_task_shell = "=0.20.2"
deno_telemetry.workspace = true deno_telemetry.workspace = true
deno_terminal.workspace = true deno_terminal.workspace = true
libsui = "0.5.0" libsui = "0.5.0"

View file

@ -2664,10 +2664,10 @@ Display outdated dependencies:
<p(245)>deno outdated</> <p(245)>deno outdated</>
<p(245)>deno outdated --compatible</> <p(245)>deno outdated --compatible</>
Update dependencies: Update dependencies to latest semver compatible versions:
<p(245)>deno outdated --update</> <p(245)>deno outdated --update</>
Update dependencies to latest versions, ignoring semver requirements:
<p(245)>deno outdated --update --latest</> <p(245)>deno outdated --update --latest</>
<p(245)>deno outdated --update</>
Filters can be used to select which packages to act on. Filters can include wildcards (*) to match multiple packages. Filters can be used to select which packages to act on. Filters can include wildcards (*) to match multiple packages.
<p(245)>deno outdated --update --latest \"@std/*\"</> <p(245)>deno outdated --update --latest \"@std/*\"</>
@ -2703,7 +2703,6 @@ Specific version requirements to update to can be specified:
.help( .help(
"Update to the latest version, regardless of semver constraints", "Update to the latest version, regardless of semver constraints",
) )
.requires("update")
.conflicts_with("compatible"), .conflicts_with("compatible"),
) )
.arg( .arg(
@ -11687,6 +11686,14 @@ Usage: deno repl [OPTIONS] [-- [ARGS]...]\n"
recursive: false, recursive: false,
}, },
), ),
(
svec!["--latest"],
OutdatedFlags {
filters: svec![],
kind: OutdatedKind::PrintOutdated { compatible: false },
recursive: false,
},
),
]; ];
for (input, expected) in cases { for (input, expected) in cases {
let mut args = svec!["deno", "outdated"]; let mut args = svec!["deno", "outdated"];

View file

@ -59,8 +59,7 @@ impl FileOrRedirect {
cache_entry: deno_cache_dir::CacheEntry, cache_entry: deno_cache_dir::CacheEntry,
) -> Result<Self, AnyError> { ) -> Result<Self, AnyError> {
if let Some(redirect_to) = cache_entry.metadata.headers.get("location") { if let Some(redirect_to) = cache_entry.metadata.headers.get("location") {
let redirect = let redirect = specifier.join(redirect_to)?;
deno_core::resolve_import(redirect_to, specifier.as_str())?;
Ok(FileOrRedirect::Redirect(redirect)) Ok(FileOrRedirect::Redirect(redirect))
} else { } else {
Ok(FileOrRedirect::File(File { Ok(FileOrRedirect::File(File {

View file

@ -353,7 +353,12 @@ impl<'a> TsResponseImportMapper<'a> {
let pkg_reqs = npm_resolver.resolve_pkg_reqs_from_pkg_id(&pkg_id); let pkg_reqs = npm_resolver.resolve_pkg_reqs_from_pkg_id(&pkg_id);
// check if any pkg reqs match what is found in an import map // check if any pkg reqs match what is found in an import map
if !pkg_reqs.is_empty() { if !pkg_reqs.is_empty() {
let sub_path = self.resolve_package_path(specifier); let sub_path = npm_resolver
.resolve_pkg_folder_from_pkg_id(&pkg_id)
.ok()
.and_then(|pkg_folder| {
self.resolve_package_path(specifier, &pkg_folder)
});
if let Some(import_map) = self.maybe_import_map { if let Some(import_map) = self.maybe_import_map {
let pkg_reqs = pkg_reqs.iter().collect::<HashSet<_>>(); let pkg_reqs = pkg_reqs.iter().collect::<HashSet<_>>();
let mut matches = Vec::new(); let mut matches = Vec::new();
@ -367,6 +372,10 @@ impl<'a> TsResponseImportMapper<'a> {
let value_sub_path = package_ref.sub_path().unwrap_or(""); let value_sub_path = package_ref.sub_path().unwrap_or("");
if let Some(key_sub_path) = if let Some(key_sub_path) =
sub_path.strip_prefix(value_sub_path) sub_path.strip_prefix(value_sub_path)
{
// keys that don't end in a slash can't be mapped to a subpath
if entry.raw_key.ends_with('/')
|| key_sub_path.is_empty()
{ {
matches matches
.push(format!("{}{}", entry.raw_key, key_sub_path)); .push(format!("{}{}", entry.raw_key, key_sub_path));
@ -375,6 +384,7 @@ impl<'a> TsResponseImportMapper<'a> {
} }
} }
} }
}
// select the shortest match // select the shortest match
matches.sort_by_key(|a| a.len()); matches.sort_by_key(|a| a.len());
if let Some(matched) = matches.first() { if let Some(matched) = matches.first() {
@ -413,10 +423,16 @@ impl<'a> TsResponseImportMapper<'a> {
fn resolve_package_path( fn resolve_package_path(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
package_root_folder: &Path,
) -> Option<String> { ) -> Option<String> {
let package_json = self let package_json = self
.resolver .resolver
.get_closest_package_json(specifier) .pkg_json_resolver(specifier)
// the specifier might have a closer package.json, but we
// want the root of the package's package.json
.get_closest_package_json_from_file_path(
&package_root_folder.join("package.json"),
)
.ok() .ok()
.flatten()?; .flatten()?;
let root_folder = package_json.path.parent()?; let root_folder = package_json.path.parent()?;

View file

@ -20,14 +20,12 @@ use deno_resolver::DenoResolverOptions;
use deno_resolver::NodeAndNpmReqResolver; use deno_resolver::NodeAndNpmReqResolver;
use deno_runtime::deno_fs; use deno_runtime::deno_fs;
use deno_runtime::deno_node::NodeResolver; use deno_runtime::deno_node::NodeResolver;
use deno_runtime::deno_node::PackageJson;
use deno_runtime::deno_node::PackageJsonResolver; use deno_runtime::deno_node::PackageJsonResolver;
use deno_semver::jsr::JsrPackageReqReference; use deno_semver::jsr::JsrPackageReqReference;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use deno_semver::package::PackageNv; use deno_semver::package::PackageNv;
use deno_semver::package::PackageReq; use deno_semver::package::PackageReq;
use indexmap::IndexMap; use indexmap::IndexMap;
use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::InNpmPackageChecker; use node_resolver::InNpmPackageChecker;
use node_resolver::NodeResolutionKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode; use node_resolver::ResolutionMode;
@ -380,6 +378,14 @@ impl LspResolver {
resolver.npm_resolver.as_ref().and_then(|r| r.as_managed()) resolver.npm_resolver.as_ref().and_then(|r| r.as_managed())
} }
pub fn pkg_json_resolver(
&self,
referrer: &ModuleSpecifier,
) -> &Arc<PackageJsonResolver> {
let resolver = self.get_scope_resolver(Some(referrer));
&resolver.pkg_json_resolver
}
pub fn graph_imports_by_referrer( pub fn graph_imports_by_referrer(
&self, &self,
file_referrer: &ModuleSpecifier, file_referrer: &ModuleSpecifier,
@ -522,16 +528,6 @@ impl LspResolver {
.is_some() .is_some()
} }
pub fn get_closest_package_json(
&self,
referrer: &ModuleSpecifier,
) -> Result<Option<Arc<PackageJson>>, ClosestPkgJsonError> {
let resolver = self.get_scope_resolver(Some(referrer));
resolver
.pkg_json_resolver
.get_closest_package_json(referrer)
}
pub fn resolve_redirects( pub fn resolve_redirects(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
@ -945,9 +941,7 @@ impl RedirectResolver {
if chain.len() > 10 { if chain.len() > 10 {
break None; break None;
} }
let Ok(target) = let Ok(target) = specifier.join(location) else {
deno_core::resolve_import(location, specifier.as_str())
else {
break None; break None;
}; };
chain.push(( chain.push((

View file

@ -236,8 +236,21 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
else { else {
return Ok(None); return Ok(None);
}; };
let folder_name = folder_path.parent().unwrap().to_string_lossy(); // ex. project/node_modules/.deno/preact@10.24.3/node_modules/preact/
Ok(get_package_folder_id_from_folder_name(&folder_name)) let Some(node_modules_ancestor) = folder_path
.ancestors()
.find(|ancestor| ancestor.ends_with("node_modules"))
else {
return Ok(None);
};
let Some(folder_name) =
node_modules_ancestor.parent().and_then(|p| p.file_name())
else {
return Ok(None);
};
Ok(get_package_folder_id_from_folder_name(
&folder_name.to_string_lossy(),
))
} }
async fn cache_packages(&self) -> Result<(), AnyError> { async fn cache_packages(&self) -> Result<(), AnyError> {

View file

@ -78,41 +78,24 @@ pub async fn execute_script(
let packages_task_configs: Vec<PackageTaskInfo> = if let Some(filter) = let packages_task_configs: Vec<PackageTaskInfo> = if let Some(filter) =
&task_flags.filter &task_flags.filter
{ {
let task_name = task_flags.task.as_ref().unwrap();
// Filter based on package name // Filter based on package name
let package_regex = arg_to_regex(filter)?; let package_regex = arg_to_regex(filter)?;
let task_regex = arg_to_regex(task_name)?; let workspace = cli_options.workspace();
let Some(task_name) = &task_flags.task else {
print_available_tasks_workspace(
cli_options,
&package_regex,
filter,
force_use_pkg_json,
)?;
return Ok(0);
};
let task_regex = arg_to_regex(task_name)?;
let mut packages_task_info: Vec<PackageTaskInfo> = vec![]; let mut packages_task_info: Vec<PackageTaskInfo> = vec![];
fn matches_package(
config: &FolderConfigs,
force_use_pkg_json: bool,
regex: &Regex,
) -> bool {
if !force_use_pkg_json {
if let Some(deno_json) = &config.deno_json {
if let Some(name) = &deno_json.json.name {
if regex.is_match(name) {
return true;
}
}
}
}
if let Some(package_json) = &config.pkg_json {
if let Some(name) = &package_json.name {
if regex.is_match(name) {
return true;
}
}
}
false
}
let workspace = cli_options.workspace();
for folder in workspace.config_folders() { for folder in workspace.config_folders() {
if !matches_package(folder.1, force_use_pkg_json, &package_regex) { if !matches_package(folder.1, force_use_pkg_json, &package_regex) {
continue; continue;
@ -198,6 +181,7 @@ pub async fn execute_script(
&mut std::io::stdout(), &mut std::io::stdout(),
&cli_options.start_dir, &cli_options.start_dir,
&tasks_config, &tasks_config,
None,
)?; )?;
return Ok(0); return Ok(0);
}; };
@ -315,6 +299,7 @@ impl<'a> TaskRunner<'a> {
&mut std::io::stderr(), &mut std::io::stderr(),
&self.cli_options.start_dir, &self.cli_options.start_dir,
tasks_config, tasks_config,
None,
) )
} }
@ -675,6 +660,32 @@ fn sort_tasks_topo<'a>(
Ok(sorted) Ok(sorted)
} }
fn matches_package(
config: &FolderConfigs,
force_use_pkg_json: bool,
regex: &Regex,
) -> bool {
if !force_use_pkg_json {
if let Some(deno_json) = &config.deno_json {
if let Some(name) = &deno_json.json.name {
if regex.is_match(name) {
return true;
}
}
}
}
if let Some(package_json) = &config.pkg_json {
if let Some(name) = &package_json.name {
if regex.is_match(name) {
return true;
}
}
}
false
}
fn output_task(task_name: &str, script: &str) { fn output_task(task_name: &str, script: &str) {
log::info!( log::info!(
"{} {} {}", "{} {} {}",
@ -684,12 +695,67 @@ fn output_task(task_name: &str, script: &str) {
); );
} }
fn print_available_tasks_workspace(
cli_options: &Arc<CliOptions>,
package_regex: &Regex,
filter: &str,
force_use_pkg_json: bool,
) -> Result<(), AnyError> {
let workspace = cli_options.workspace();
let mut matched = false;
for folder in workspace.config_folders() {
if !matches_package(folder.1, force_use_pkg_json, package_regex) {
continue;
}
matched = true;
let member_dir = workspace.resolve_member_dir(folder.0);
let mut tasks_config = member_dir.to_tasks_config()?;
let mut pkg_name = folder
.1
.deno_json
.as_ref()
.and_then(|deno| deno.json.name.clone())
.or(folder.1.pkg_json.as_ref().and_then(|pkg| pkg.name.clone()));
if force_use_pkg_json {
tasks_config = tasks_config.with_only_pkg_json();
pkg_name = folder.1.pkg_json.as_ref().and_then(|pkg| pkg.name.clone());
}
print_available_tasks(
&mut std::io::stdout(),
&cli_options.start_dir,
&tasks_config,
pkg_name,
)?;
}
if !matched {
log::warn!(
"{}",
colors::red(format!("No package name matched the filter '{}' in available 'deno.json' or 'package.json' files.", filter))
);
}
Ok(())
}
fn print_available_tasks( fn print_available_tasks(
writer: &mut dyn std::io::Write, writer: &mut dyn std::io::Write,
workspace_dir: &Arc<WorkspaceDirectory>, workspace_dir: &Arc<WorkspaceDirectory>,
tasks_config: &WorkspaceTasksConfig, tasks_config: &WorkspaceTasksConfig,
pkg_name: Option<String>,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
writeln!(writer, "{}", colors::green("Available tasks:"))?; let heading = if let Some(s) = pkg_name {
format!("Available tasks ({}):", colors::cyan(s))
} else {
"Available tasks:".to_string()
};
writeln!(writer, "{}", colors::green(heading))?;
let is_cwd_root_dir = tasks_config.root.is_none(); let is_cwd_root_dir = tasks_config.root.is_none();
if tasks_config.is_empty() { if tasks_config.is_empty() {

View file

@ -407,7 +407,7 @@ pub fn bi_pipe_pair_raw(
&s, &s,
OPEN_EXISTING, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED,
0, std::ptr::null_mut(),
); );
if hd2 == INVALID_HANDLE_VALUE { if hd2 == INVALID_HANDLE_VALUE {
return Err(io::Error::last_os_error()); return Err(io::Error::last_os_error());

View file

@ -429,7 +429,9 @@ where
let pkg_json_resolver = state.borrow::<PackageJsonResolverRc>(); let pkg_json_resolver = state.borrow::<PackageJsonResolverRc>();
let pkg = pkg_json_resolver let pkg = pkg_json_resolver
.get_closest_package_json_from_path(&PathBuf::from(parent_path.unwrap())) .get_closest_package_json_from_file_path(&PathBuf::from(
parent_path.unwrap(),
))
.ok() .ok()
.flatten(); .flatten();
if pkg.is_none() { if pkg.is_none() {
@ -620,8 +622,8 @@ where
let referrer_path = ensure_read_permission::<P>(state, &referrer_path) let referrer_path = ensure_read_permission::<P>(state, &referrer_path)
.map_err(RequireErrorKind::Permission)?; .map_err(RequireErrorKind::Permission)?;
let pkg_json_resolver = state.borrow::<PackageJsonResolverRc>(); let pkg_json_resolver = state.borrow::<PackageJsonResolverRc>();
let Some(pkg) = let Some(pkg) = pkg_json_resolver
pkg_json_resolver.get_closest_package_json_from_path(&referrer_path)? .get_closest_package_json_from_file_path(&referrer_path)?
else { else {
return Ok(None); return Ok(None);
}; };

View file

@ -39,7 +39,6 @@ const {
SafeWeakMap, SafeWeakMap,
Array, Array,
ObjectEntries, ObjectEntries,
SafeMap,
ReflectApply, ReflectApply,
SymbolFor, SymbolFor,
Error, Error,
@ -617,26 +616,25 @@ class SpanExporter {
const CURRENT = new AsyncVariable(); const CURRENT = new AsyncVariable();
class Context { class Context {
#data = new SafeMap(); #data: Record<symbol, unknown> = { __proto__: null };
// deno-lint-ignore no-explicit-any constructor(data?: Record<symbol, unknown> | null | undefined) {
constructor(data?: Iterable<readonly [any, any]> | null | undefined) { this.#data = { __proto__: null, ...data };
this.#data = data ? new SafeMap(data) : new SafeMap();
} }
getValue(key: symbol): unknown { getValue(key: symbol): unknown {
return this.#data.get(key); return this.#data[key];
} }
setValue(key: symbol, value: unknown): Context { setValue(key: symbol, value: unknown): Context {
const c = new Context(this.#data); const c = new Context(this.#data);
c.#data.set(key, value); c.#data[key] = value;
return c; return c;
} }
deleteValue(key: symbol): Context { deleteValue(key: symbol): Context {
const c = new Context(this.#data); const c = new Context(this.#data);
c.#data.delete(key); delete c.#data[key];
return c; return c;
} }
} }

View file

@ -60,10 +60,10 @@ impl<TEnv: NodeResolverEnv> PackageJsonResolver<TEnv> {
let Ok(file_path) = deno_path_util::url_to_file_path(url) else { let Ok(file_path) = deno_path_util::url_to_file_path(url) else {
return Ok(None); return Ok(None);
}; };
self.get_closest_package_json_from_path(&file_path) self.get_closest_package_json_from_file_path(&file_path)
} }
pub fn get_closest_package_json_from_path( pub fn get_closest_package_json_from_file_path(
&self, &self,
file_path: &Path, file_path: &Path,
) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> { ) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> {

View file

@ -9610,6 +9610,69 @@ fn lsp_completions_npm() {
client.shutdown(); client.shutdown();
} }
#[test]
fn lsp_auto_imports_npm_auto() {
let context = TestContextBuilder::for_npm().use_temp_cwd().build();
let temp_dir_path = context.temp_dir().path();
temp_dir_path.join("deno.json").write_json(&json!({
"nodeModulesDir": "auto",
"imports": {
"preact": "npm:preact@^10.19.6",
},
}));
// add a file that uses the import so that typescript knows about it
temp_dir_path
.join("mod.ts")
.write("import { useEffect } from 'preact/hooks'; console.log(useEffect);");
context.run_deno("cache mod.ts");
let mut client = context.new_lsp_command().build();
client.initialize_default();
let file_uri = temp_dir_path.join("file.ts").url_file();
let mut diagnostics = client
.did_open(json!({
"textDocument": {
"uri": file_uri,
"languageId": "typescript",
"version": 1,
"text": "useEffect",
}
}))
.all();
assert_eq!(diagnostics.len(), 1);
let diagnostic = diagnostics.remove(0);
let res = client.write_request(
"textDocument/codeAction",
json!({
"textDocument": {
"uri": file_uri,
},
"range": {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 9 }
},
"context": {
"diagnostics": [diagnostic],
"only": ["quickfix"]
}
}),
);
assert_eq!(
res
.as_array()
.unwrap()
.first()
.unwrap()
.as_object()
.unwrap()
.get("title")
.unwrap()
.as_str()
.unwrap(),
"Add import from \"preact/hooks\""
);
client.shutdown();
}
#[test] #[test]
fn lsp_npm_specifier_unopened_file() { fn lsp_npm_specifier_unopened_file() {
let context = TestContextBuilder::new() let context = TestContextBuilder::new()

View file

@ -122,6 +122,16 @@
"sequential": ["test-child-process-exit.js"] "sequential": ["test-child-process-exit.js"]
}, },
"tests": { "tests": {
"abort": [
"test-addon-uv-handle-leak.js"
],
"benchmark": [
"test-benchmark-async-hooks.js",
"test-benchmark-http.js",
"test-benchmark-http2.js",
"test-benchmark-tls.js",
"test-benchmark-worker.js"
],
"common": [ "common": [
"child_process.js", "child_process.js",
"countdown.js", "countdown.js",
@ -133,6 +143,13 @@
"internet.js", "internet.js",
"tmpdir.js" "tmpdir.js"
], ],
"es-module": [
"test-cjs-prototype-pollution.js",
"test-esm-dynamic-import-mutating-fs.js",
"test-esm-loader-cache-clearing.js",
"test-esm-windows.js",
"test-vm-compile-function-lineoffset.js"
],
"fixtures": [ "fixtures": [
"a.js", "a.js",
"child_process_should_emit_error.js", "child_process_should_emit_error.js",
@ -161,12 +178,29 @@
// "test-dns.js", // "test-dns.js",
"test-http-https-default-ports.js" "test-http-https-default-ports.js"
], ],
"message": [
"eval_messages.js",
"max_tick_depth.js",
"stdin_messages.js",
"util_inspect_error.js"
],
"parallel": [ "parallel": [
"test-arm-math-illegal-instruction.js",
"test-assert-async.js", "test-assert-async.js",
"test-assert-fail.js", "test-assert-fail.js",
"test-assert-strict-exists.js", "test-assert-strict-exists.js",
"test-assert.js", "test-assert.js",
"test-async-hooks-run-in-async-scope-caught-exception.js",
"test-async-hooks-run-in-async-scope-this-arg.js",
"test-async-local-storage-bind.js",
"test-async-local-storage-contexts.js",
"test-async-local-storage-deep-stack.js",
"test-async-local-storage-http-multiclients.js",
"test-async-local-storage-snapshot.js",
"test-atomics-wake.js",
"test-bad-unicode.js", "test-bad-unicode.js",
"test-beforeexit-event-exit.js",
"test-blob-buffer-too-large.js",
"test-blocklist.js", "test-blocklist.js",
"test-btoa-atob.js", "test-btoa-atob.js",
"test-buffer-alloc.js", "test-buffer-alloc.js",
@ -202,6 +236,7 @@
"test-buffer-readint.js", "test-buffer-readint.js",
"test-buffer-readuint.js", "test-buffer-readuint.js",
"test-buffer-safe-unsafe.js", "test-buffer-safe-unsafe.js",
"test-buffer-sharedarraybuffer.js",
"test-buffer-slice.js", "test-buffer-slice.js",
"test-buffer-slow.js", "test-buffer-slow.js",
"test-buffer-swap.js", "test-buffer-swap.js",
@ -209,6 +244,7 @@
"test-buffer-tostring-range.js", "test-buffer-tostring-range.js",
"test-buffer-tostring-rangeerror.js", "test-buffer-tostring-rangeerror.js",
"test-buffer-tostring.js", "test-buffer-tostring.js",
"test-buffer-write.js",
"test-buffer-writedouble.js", "test-buffer-writedouble.js",
"test-buffer-writefloat.js", "test-buffer-writefloat.js",
"test-buffer-writeint.js", "test-buffer-writeint.js",
@ -237,8 +273,10 @@
"test-child-process-execfilesync-maxbuf.js", "test-child-process-execfilesync-maxbuf.js",
"test-child-process-execsync-maxbuf.js", "test-child-process-execsync-maxbuf.js",
"test-child-process-flush-stdio.js", "test-child-process-flush-stdio.js",
"test-child-process-fork3.js",
"test-child-process-ipc-next-tick.js", "test-child-process-ipc-next-tick.js",
"test-child-process-kill.js", "test-child-process-kill.js",
"test-child-process-send-type-error.js",
"test-child-process-set-blocking.js", "test-child-process-set-blocking.js",
"test-child-process-spawn-args.js", "test-child-process-spawn-args.js",
"test-child-process-spawn-event.js", "test-child-process-spawn-event.js",
@ -246,49 +284,140 @@
"test-child-process-spawnsync-maxbuf.js", "test-child-process-spawnsync-maxbuf.js",
"test-child-process-spawnsync-validation-errors.js", "test-child-process-spawnsync-validation-errors.js",
"test-child-process-spawnsync.js", "test-child-process-spawnsync.js",
// TODO(crowlKats): socket is not yet polyfilled "test-child-process-stdin-ipc.js",
// "test-client-request-destroy.js", "test-child-process-stdio-overlapped.js",
"test-client-request-destroy.js",
"test-cluster-uncaught-exception.js",
"test-console-assign-undefined.js",
"test-console-async-write-error.js", "test-console-async-write-error.js",
"test-console-formatTime.js",
"test-console-group.js", "test-console-group.js",
"test-console-log-stdio-broken-dest.js", "test-console-log-stdio-broken-dest.js",
"test-console-log-throw-primitive.js", "test-console-log-throw-primitive.js",
"test-console-no-swallow-stack-overflow.js", "test-console-no-swallow-stack-overflow.js",
"test-console-not-call-toString.js",
"test-console-self-assign.js",
"test-console-sync-write-error.js", "test-console-sync-write-error.js",
"test-console-table.js", "test-console-table.js",
"test-console-tty-colors.js", "test-console-tty-colors.js",
"test-crypto-dh-errors.js",
"test-crypto-dh-odd-key.js",
"test-crypto-dh-shared.js", "test-crypto-dh-shared.js",
"test-crypto-dh.js", "test-crypto-dh.js",
"test-crypto-domain.js",
"test-crypto-from-binary.js",
"test-crypto-hash.js", "test-crypto-hash.js",
"test-crypto-hkdf.js", "test-crypto-hkdf.js",
"test-crypto-hmac.js", "test-crypto-hmac.js",
"test-crypto-keygen-dh-classic.js",
"test-crypto-keygen-duplicate-deprecated-option.js",
"test-crypto-keygen-empty-passphrase-no-error.js",
"test-crypto-keygen-key-objects.js",
"test-crypto-keygen-missing-oid.js",
"test-crypto-keygen-non-standard-public-exponent.js",
"test-crypto-keygen-rfc8017-9-1.js",
"test-crypto-keygen-rfc8017-a-2-3.js",
"test-crypto-lazy-transform-writable.js",
"test-crypto-no-algorithm.js",
"test-crypto-op-during-process-exit.js",
"test-crypto-padding-aes256.js",
"test-crypto-pbkdf2.js", "test-crypto-pbkdf2.js",
"test-crypto-prime.js", "test-crypto-prime.js",
"test-crypto-psychic-signatures.js",
"test-crypto-publicDecrypt-fails-first-time.js",
"test-crypto-randomfillsync-regression.js",
"test-crypto-scrypt.js",
"test-crypto-secret-keygen.js", "test-crypto-secret-keygen.js",
"test-crypto-stream.js", "test-crypto-stream.js",
"test-crypto-subtle-zero-length.js",
"test-crypto-update-encoding.js", "test-crypto-update-encoding.js",
"test-crypto-x509.js", "test-crypto-x509.js",
"test-dgram-address.js",
"test-dgram-bind-default-address.js",
"test-dgram-bind-error-repeat.js",
"test-dgram-bind.js",
"test-dgram-bytes-length.js",
"test-dgram-close-during-bind.js", "test-dgram-close-during-bind.js",
"test-dgram-close-in-listening.js",
"test-dgram-close-is-not-callback.js",
"test-dgram-close-signal.js", "test-dgram-close-signal.js",
"test-dgram-close.js",
"test-dgram-connect-send-callback-buffer-length.js",
"test-dgram-connect-send-callback-buffer.js",
"test-dgram-connect-send-callback-multi-buffer.js",
"test-dgram-connect-send-default-host.js",
"test-dgram-connect-send-empty-array.js",
"test-dgram-connect-send-empty-buffer.js",
"test-dgram-connect-send-empty-packet.js",
"test-dgram-connect-send-multi-buffer-copy.js",
"test-dgram-connect-send-multi-string-array.js",
"test-dgram-connect.js",
"test-dgram-createSocket-type.js",
"test-dgram-error-message-address.js",
"test-dgram-implicit-bind.js",
"test-dgram-listen-after-bind.js",
"test-dgram-msgsize.js",
"test-dgram-oob-buffer.js",
"test-dgram-recv-error.js",
"test-dgram-ref.js",
"test-dgram-send-bad-arguments.js",
"test-dgram-send-callback-buffer-empty-address.js",
"test-dgram-send-callback-buffer-length-empty-address.js",
"test-dgram-send-callback-buffer-length.js",
"test-dgram-send-callback-buffer.js",
"test-dgram-send-callback-multi-buffer-empty-address.js",
"test-dgram-send-callback-multi-buffer.js",
"test-dgram-send-callback-recursive.js",
"test-dgram-send-default-host.js",
"test-dgram-send-empty-array.js",
"test-dgram-send-empty-buffer.js",
"test-dgram-send-empty-packet.js",
"test-dgram-send-error.js",
"test-dgram-send-invalid-msg-type.js",
"test-dgram-send-multi-buffer-copy.js",
"test-dgram-send-multi-string-array.js",
"test-dgram-udp4.js",
"test-dgram-udp6-send-default-host.js",
"test-dgram-unref.js",
"test-diagnostics-channel-bind-store.js",
"test-diagnostics-channel-has-subscribers.js", "test-diagnostics-channel-has-subscribers.js",
"test-diagnostics-channel-net.js", "test-diagnostics-channel-net.js",
"test-diagnostics-channel-object-channel-pub-sub.js", "test-diagnostics-channel-object-channel-pub-sub.js",
"test-diagnostics-channel-pub-sub.js", "test-diagnostics-channel-pub-sub.js",
"test-diagnostics-channel-safe-subscriber-errors.js",
"test-diagnostics-channel-symbol-named.js", "test-diagnostics-channel-symbol-named.js",
"test-diagnostics-channel-sync-unsubscribe.js", "test-diagnostics-channel-sync-unsubscribe.js",
"test-diagnostics-channel-tracing-channel-args-types.js", "test-diagnostics-channel-tracing-channel-args-types.js",
"test-diagnostics-channel-tracing-channel-async-error.js",
"test-diagnostics-channel-tracing-channel-async.js",
"test-diagnostics-channel-tracing-channel-callback-run-stores.js", "test-diagnostics-channel-tracing-channel-callback-run-stores.js",
"test-diagnostics-channel-tracing-channel-promise-run-stores.js", "test-diagnostics-channel-tracing-channel-promise-run-stores.js",
"test-diagnostics-channel-tracing-channel-run-stores.js",
"test-diagnostics-channel-tracing-channel-sync-error.js", "test-diagnostics-channel-tracing-channel-sync-error.js",
"test-diagnostics-channel-tracing-channel-sync.js", "test-diagnostics-channel-tracing-channel-sync.js",
"test-diagnostics-channel-udp.js", "test-diagnostics-channel-udp.js",
"test-dns-lookup.js", "test-dns-lookup.js",
"test-dns-memory-error.js", "test-dns-memory-error.js",
"test-dns-multi-channel.js",
"test-dns-promises-exists.js", "test-dns-promises-exists.js",
"test-dns-resolvens-typeerror.js", "test-dns-resolvens-typeerror.js",
"test-dns-setservers-type-check.js", "test-dns-setservers-type-check.js",
"test-domain-crypto.js",
"test-domain-ee-error-listener.js",
"test-domain-nested-throw.js",
"test-domain-nested.js",
"test-domain-stack.js",
"test-domain-top-level-error-handler-clears-stack.js",
"test-dsa-fips-invalid-key.js",
"test-env-newprotomethod-remove-unnecessary-prototypes.js",
"test-error-aggregateTwoErrors.js",
"test-error-prepare-stack-trace.js",
"test-errors-aborterror.js",
"test-eval-strict-referenceerror.js", "test-eval-strict-referenceerror.js",
"test-eval.js", "test-eval.js",
"test-event-capture-rejections.js",
"test-event-emitter-add-listeners.js", "test-event-emitter-add-listeners.js",
"test-event-emitter-check-listener-leaks.js",
"test-event-emitter-emit-context.js", "test-event-emitter-emit-context.js",
"test-event-emitter-error-monitor.js", "test-event-emitter-error-monitor.js",
"test-event-emitter-errors.js", "test-event-emitter-errors.js",
@ -297,6 +426,9 @@
"test-event-emitter-listener-count.js", "test-event-emitter-listener-count.js",
"test-event-emitter-listeners-side-effects.js", "test-event-emitter-listeners-side-effects.js",
"test-event-emitter-listeners.js", "test-event-emitter-listeners.js",
"test-event-emitter-max-listeners-warning-for-null.js",
"test-event-emitter-max-listeners-warning-for-symbol.js",
"test-event-emitter-max-listeners-warning.js",
"test-event-emitter-max-listeners.js", "test-event-emitter-max-listeners.js",
"test-event-emitter-method-names.js", "test-event-emitter-method-names.js",
"test-event-emitter-modify-in-emit.js", "test-event-emitter-modify-in-emit.js",
@ -315,6 +447,7 @@
"test-events-once.js", "test-events-once.js",
"test-events-uncaught-exception-stack.js", "test-events-uncaught-exception-stack.js",
"test-eventtarget-brandcheck.js", "test-eventtarget-brandcheck.js",
"test-eventtarget-once-twice.js",
"test-exception-handler.js", "test-exception-handler.js",
"test-exception-handler2.js", "test-exception-handler2.js",
"test-file-read-noexist.js", "test-file-read-noexist.js",
@ -325,28 +458,42 @@
"test-fs-access.js", "test-fs-access.js",
"test-fs-append-file-sync.js", "test-fs-append-file-sync.js",
"test-fs-append-file.js", "test-fs-append-file.js",
"test-fs-buffertype-writesync.js",
"test-fs-chmod-mask.js", "test-fs-chmod-mask.js",
"test-fs-chmod.js", "test-fs-chmod.js",
"test-fs-chown-type-check.js", "test-fs-chown-type-check.js",
"test-fs-close.js",
"test-fs-constants.js",
"test-fs-copyfile.js", "test-fs-copyfile.js",
"test-fs-empty-readStream.js", "test-fs-empty-readStream.js",
"test-fs-fmap.js",
"test-fs-lchown.js", "test-fs-lchown.js",
"test-fs-long-path.js",
"test-fs-mkdir.js", "test-fs-mkdir.js",
"test-fs-non-number-arguments-throw.js",
"test-fs-open-flags.js", "test-fs-open-flags.js",
"test-fs-open-mode-mask.js", "test-fs-open-mode-mask.js",
"test-fs-open-no-close.js", "test-fs-open-no-close.js",
"test-fs-open-numeric-flags.js", "test-fs-open-numeric-flags.js",
"test-fs-open.js", "test-fs-open.js",
"test-fs-opendir.js", "test-fs-opendir.js",
"test-fs-promises-exists.js",
"test-fs-promises-file-handle-stat.js", "test-fs-promises-file-handle-stat.js",
"test-fs-promises-file-handle-write.js",
"test-fs-promises-readfile-empty.js",
"test-fs-promises-readfile-with-fd.js",
"test-fs-promises-writefile-with-fd.js", "test-fs-promises-writefile-with-fd.js",
"test-fs-read-file-sync-hostname.js",
"test-fs-read-file-sync.js",
"test-fs-read-stream-autoClose.js", "test-fs-read-stream-autoClose.js",
"test-fs-read-stream-concurrent-reads.js", "test-fs-read-stream-concurrent-reads.js",
"test-fs-read-stream-double-close.js", "test-fs-read-stream-double-close.js",
"test-fs-read-stream-encoding.js", "test-fs-read-stream-encoding.js",
"test-fs-read-stream-fd-leak.js",
"test-fs-read-stream-fd.js", "test-fs-read-stream-fd.js",
"test-fs-read-stream-inherit.js", "test-fs-read-stream-inherit.js",
"test-fs-read-stream-patch-open.js", "test-fs-read-stream-patch-open.js",
"test-fs-read-stream-pos.js",
"test-fs-read-stream-resume.js", "test-fs-read-stream-resume.js",
"test-fs-read-stream-throw-type-error.js", "test-fs-read-stream-throw-type-error.js",
"test-fs-read-stream.js", "test-fs-read-stream.js",
@ -356,8 +503,12 @@
"test-fs-readdir-stack-overflow.js", "test-fs-readdir-stack-overflow.js",
"test-fs-readdir.js", "test-fs-readdir.js",
"test-fs-readfile-empty.js", "test-fs-readfile-empty.js",
"test-fs-readfile-unlink.js",
"test-fs-readfile-zero-byte-liar.js",
"test-fs-readfilesync-enoent.js",
"test-fs-readv-sync.js", "test-fs-readv-sync.js",
"test-fs-readv.js", "test-fs-readv.js",
"test-fs-ready-event-stream.js",
"test-fs-realpath-native.js", "test-fs-realpath-native.js",
"test-fs-rmdir-recursive-sync-warns-not-found.js", "test-fs-rmdir-recursive-sync-warns-not-found.js",
"test-fs-rmdir-recursive-sync-warns-on-file.js", "test-fs-rmdir-recursive-sync-warns-on-file.js",
@ -367,33 +518,122 @@
"test-fs-rmdir-recursive-warns-on-file.js", "test-fs-rmdir-recursive-warns-on-file.js",
"test-fs-rmdir-recursive.js", "test-fs-rmdir-recursive.js",
"test-fs-rmdir-type-check.js", "test-fs-rmdir-type-check.js",
"test-fs-sir-writes-alot.js",
"test-fs-stream-construct-compat-error-read.js",
"test-fs-stream-construct-compat-graceful-fs.js",
"test-fs-stream-construct-compat-old-node.js",
"test-fs-stream-destroy-emit-error.js",
"test-fs-stream-double-close.js",
"test-fs-stream-fs-options.js",
"test-fs-stream-options.js",
"test-fs-symlink-dir-junction-relative.js",
"test-fs-timestamp-parsing-error.js",
"test-fs-truncate-clear-file-zero.js",
"test-fs-util-validateoffsetlength.js",
"test-fs-utimes-y2K38.js",
"test-fs-utimes.js", "test-fs-utimes.js",
"test-fs-watch-file-enoent-after-deletion.js",
"test-fs-watch-recursive-add-file-with-url.js",
"test-fs-watch-recursive-add-file.js",
"test-fs-watch-recursive-add-folder.js",
"test-fs-watch-recursive-update-file.js",
"test-fs-watchfile.js", "test-fs-watchfile.js",
"test-fs-write-buffer.js", "test-fs-write-buffer.js",
"test-fs-write-file-buffer.js", "test-fs-write-file-buffer.js",
"test-fs-write-file-invalid-path.js", "test-fs-write-file-invalid-path.js",
"test-fs-write-file-sync.js", "test-fs-write-file-sync.js",
"test-fs-write-file.js", "test-fs-write-file.js",
"test-fs-write-negativeoffset.js",
"test-fs-write-no-fd.js", "test-fs-write-no-fd.js",
"test-fs-write-stream-autoclose-option.js", "test-fs-write-stream-autoclose-option.js",
"test-fs-write-stream-close-without-callback.js", "test-fs-write-stream-close-without-callback.js",
"test-fs-write-stream-double-close.js", "test-fs-write-stream-double-close.js",
"test-fs-write-stream-encoding.js",
"test-fs-write-stream-end.js", "test-fs-write-stream-end.js",
"test-fs-write-stream-fs.js", "test-fs-write-stream-fs.js",
"test-fs-write-stream-patch-open.js",
"test-fs-write-stream-throw-type-error.js", "test-fs-write-stream-throw-type-error.js",
"test-fs-write-stream.js", "test-fs-write-stream.js",
"test-fs-write-sync.js", "test-fs-write-sync.js",
"test-fs-write.js", "test-fs-write.js",
"test-fs-writev-sync.js", "test-fs-writev-sync.js",
"test-fs-writev.js",
"test-global-domexception.js",
"test-global-encoder.js",
"test-global-webcrypto.js",
"test-global-webstreams.js",
"test-handle-wrap-close-abort.js", "test-handle-wrap-close-abort.js",
"test-http-abort-before-end.js",
"test-http-addrequest-localaddress.js",
"test-http-agent-false.js",
"test-http-agent-getname.js", "test-http-agent-getname.js",
"test-http-agent-keepalive-delay.js",
"test-http-agent-maxtotalsockets.js",
"test-http-agent-no-protocol.js",
"test-http-agent-null.js",
"test-http-allow-req-after-204-res.js",
"test-http-bind-twice.js",
"test-http-buffer-sanity.js",
"test-http-chunked-smuggling.js",
"test-http-chunked.js",
"test-http-client-abort2.js",
"test-http-client-check-http-token.js",
"test-http-client-close-with-default-agent.js",
"test-http-client-default-headers-exist.js",
"test-http-client-defaults.js",
"test-http-client-encoding.js",
"test-http-client-get-url.js", "test-http-client-get-url.js",
"test-http-client-headers-array.js",
"test-http-client-invalid-path.js",
"test-http-client-keep-alive-hint.js",
"test-http-client-race-2.js",
"test-http-client-race.js",
"test-http-client-read-in-error.js", "test-http-client-read-in-error.js",
"test-http-client-reject-unexpected-agent.js",
"test-http-client-timeout-connect-listener.js",
"test-http-client-timeout-with-data.js",
"test-http-client-unescaped-path.js",
"test-http-client-upload-buf.js",
"test-http-client-upload.js",
// TODO(lev): ClientRequest.socket is not polyfilled so this test keeps // TODO(lev): ClientRequest.socket is not polyfilled so this test keeps
// failing // failing
//"test-http-client-set-timeout.js", //"test-http-client-set-timeout.js",
"test-http-common.js",
"test-http-contentLength0.js",
"test-http-correct-hostname.js",
"test-http-date-header.js",
"test-http-decoded-auth.js",
"test-http-default-encoding.js",
"test-http-dump-req-when-res-ends.js",
"test-http-end-throw-socket-handling.js",
"test-http-eof-on-connect.js",
"test-http-extra-response.js",
"test-http-flush-headers.js",
"test-http-full-response.js",
"test-http-head-request.js",
"test-http-head-response-has-no-body-end-implicit-headers.js",
"test-http-head-response-has-no-body-end.js",
"test-http-head-response-has-no-body.js",
"test-http-head-throw-on-response-body-write.js",
"test-http-header-obstext.js",
"test-http-header-owstext.js",
"test-http-header-read.js",
"test-http-header-validators.js", "test-http-header-validators.js",
"test-http-hex-write.js",
"test-http-highwatermark.js",
"test-http-host-headers.js",
"test-http-hostname-typechecking.js",
"test-http-incoming-message-destroy.js",
"test-http-invalid-path-chars.js",
"test-http-invalidheaderfield.js",
"test-http-invalidheaderfield2.js",
"test-http-keep-alive-timeout-custom.js",
"test-http-listening.js",
"test-http-localaddress-bind-error.js",
"test-http-localaddress.js", "test-http-localaddress.js",
"test-http-methods.js",
"test-http-outgoing-end-types.js",
"test-http-outgoing-finished.js",
// TODO(bartlomieju): temporarily disabled while we iterate on the HTTP client // TODO(bartlomieju): temporarily disabled while we iterate on the HTTP client
// "test-http-outgoing-buffer.js", // "test-http-outgoing-buffer.js",
"test-http-outgoing-internal-headernames-getter.js", "test-http-outgoing-internal-headernames-getter.js",
@ -403,53 +643,186 @@
// "test-http-outgoing-message-inheritance.js", // "test-http-outgoing-message-inheritance.js",
"test-http-outgoing-renderHeaders.js", "test-http-outgoing-renderHeaders.js",
"test-http-outgoing-settimeout.js", "test-http-outgoing-settimeout.js",
"test-http-outgoing-write-types.js",
"test-http-parser-free.js",
"test-http-pause-no-dump.js",
"test-http-pause-resume-one-end.js",
"test-http-pause.js",
"test-http-pipe-fs.js",
"test-http-pipeline-requests-connection-leak.js",
"test-http-proxy.js",
"test-http-readable-data-event.js",
"test-http-request-arguments.js",
"test-http-request-dont-override-options.js",
"test-http-request-end-twice.js",
"test-http-request-end.js",
"test-http-request-invalid-method-error.js",
"test-http-request-large-payload.js",
"test-http-request-methods.js",
"test-http-res-write-end-dont-take-array.js",
"test-http-response-multiheaders.js",
"test-http-response-readable.js",
"test-http-response-writehead-returns-this.js",
"test-http-server-delete-parser.js",
"test-http-server-write-after-end.js",
"test-http-server-write-end-after-end.js",
"test-http-set-cookies.js",
"test-http-set-header-chain.js",
"test-http-status-code.js",
"test-http-status-reason-invalid-chars.js",
"test-http-uncaught-from-request-callback.js",
"test-http-url.parse-auth.js",
"test-http-url.parse-basic.js",
"test-http-url.parse-https.request.js", "test-http-url.parse-https.request.js",
"test-http-url.parse-only-support-http-https-protocol.js", "test-http-url.parse-only-support-http-https-protocol.js",
"test-http-url.parse-path.js",
"test-http-url.parse-post.js",
"test-http-url.parse-search.js",
"test-http-wget.js",
"test-http-write-empty-string.js",
"test-http-zerolengthbuffer.js",
"test-http2-client-request-listeners-warning.js",
"test-http2-compat-expect-handling.js",
"test-http2-compat-socket-set.js",
"test-http2-connect-options.js",
"test-http2-date-header.js",
"test-http2-dont-override.js",
"test-http2-endafterheaders.js",
"test-http2-methods.js",
"test-http2-request-response-proto.js",
"test-http2-respond-file-204.js",
"test-http2-respond-file-compat.js",
"test-http2-session-timeout.js",
"test-http2-socket-proxy.js",
"test-http2-status-code-invalid.js",
"test-http2-status-code.js",
"test-http2-stream-removelisteners-after-close.js",
"test-http2-write-empty-string.js",
"test-https-client-renegotiation-limit.js",
"test-https-connecting-to-http.js",
"test-https-foafssl.js",
"test-https-localaddress-bind-error.js",
"test-https-localaddress.js",
"test-icu-data-dir.js",
"test-icu-env.js",
"test-icu-stringwidth.js",
"test-icu-transcode.js", "test-icu-transcode.js",
"test-inspector-stops-no-file.js",
"test-instanceof.js",
"test-internal-fs.js",
"test-internal-util-normalizeencoding.js",
"test-kill-segfault-freebsd.js",
"test-listen-fd-detached-inherit.js",
"test-listen-fd-detached.js",
"test-memory-usage-emfile.js",
"test-memory-usage.js",
"test-messagechannel.js",
"test-microtask-queue-integration.js",
"test-microtask-queue-run-immediate.js",
"test-microtask-queue-run.js",
"test-module-cache.js",
"test-module-circular-symlinks.js",
"test-module-isBuiltin.js",
"test-module-multi-extensions.js",
"test-module-nodemodulepaths.js",
"test-module-readonly.js",
"test-module-relative-lookup.js",
"test-net-access-byteswritten.js", "test-net-access-byteswritten.js",
"test-net-after-close.js",
"test-net-autoselectfamily.js", "test-net-autoselectfamily.js",
"test-net-better-error-messages-listen-path.js", "test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-listen.js",
"test-net-better-error-messages-path.js", "test-net-better-error-messages-path.js",
"test-net-better-error-messages-port-hostname.js", "test-net-better-error-messages-port-hostname.js",
"test-net-bind-twice.js",
"test-net-buffersize.js",
"test-net-bytes-written-large.js",
"test-net-can-reset-timeout.js",
"test-net-connect-after-destroy.js", "test-net-connect-after-destroy.js",
"test-net-connect-call-socket-connect.js",
"test-net-connect-destroy.js", "test-net-connect-destroy.js",
"test-net-connect-immediate-destroy.js", "test-net-connect-immediate-destroy.js",
"test-net-connect-immediate-finish.js", "test-net-connect-immediate-finish.js",
"test-net-connect-no-arg.js", "test-net-connect-no-arg.js",
"test-net-connect-options-fd.js",
"test-net-connect-options-ipv6.js",
"test-net-connect-options-port.js",
"test-net-connect-paused-connection.js",
"test-net-dns-custom-lookup.js",
"test-net-dns-error.js", "test-net-dns-error.js",
"test-net-dns-lookup-skip.js",
"test-net-dns-lookup.js",
"test-net-during-close.js", "test-net-during-close.js",
"test-net-eaddrinuse.js",
"test-net-end-close.js", "test-net-end-close.js",
"test-net-end-without-connect.js", "test-net-end-without-connect.js",
"test-net-error-twice.js",
"test-net-isip.js", "test-net-isip.js",
"test-net-isipv4.js", "test-net-isipv4.js",
"test-net-isipv6.js", "test-net-isipv6.js",
"test-net-keepalive.js",
"test-net-listen-after-destroying-stdin.js",
"test-net-listen-close-server-callback-is-not-function.js", "test-net-listen-close-server-callback-is-not-function.js",
"test-net-listen-close-server.js", "test-net-listen-close-server.js",
"test-net-listen-error.js",
"test-net-listen-invalid-port.js", "test-net-listen-invalid-port.js",
"test-net-listening.js", "test-net-listening.js",
"test-net-local-address-port.js",
"test-net-localerror.js", "test-net-localerror.js",
"test-net-options-lookup.js", "test-net-options-lookup.js",
"test-net-pause-resume-connecting.js",
"test-net-persistent-keepalive.js",
"test-net-persistent-nodelay.js",
"test-net-persistent-ref-unref.js",
"test-net-pipe-connect-errors.js", "test-net-pipe-connect-errors.js",
"test-net-reconnect.js",
"test-net-remote-address-port.js",
"test-net-remote-address.js",
"test-net-server-capture-rejection.js",
"test-net-server-close.js",
"test-net-server-listen-options-signal.js", "test-net-server-listen-options-signal.js",
"test-net-server-listen-options.js", "test-net-server-listen-options.js",
"test-net-server-listen-path.js", "test-net-server-listen-path.js",
"test-net-server-listen-remove-callback.js", "test-net-server-listen-remove-callback.js",
"test-net-server-options.js", "test-net-server-options.js",
"test-net-server-pause-on-connect.js",
"test-net-server-unref-persistent.js", "test-net-server-unref-persistent.js",
"test-net-server-unref.js", "test-net-server-unref.js",
"test-net-settimeout.js",
"test-net-socket-close-after-end.js",
"test-net-socket-connect-invalid-autoselectfamily.js",
"test-net-socket-connect-without-cb.js",
"test-net-socket-connecting.js",
"test-net-socket-destroy-send.js",
"test-net-socket-destroy-twice.js", "test-net-socket-destroy-twice.js",
"test-net-socket-end-before-connect.js",
"test-net-socket-end-callback.js",
"test-net-socket-no-halfopen-enforcer.js", "test-net-socket-no-halfopen-enforcer.js",
"test-net-socket-ready-without-cb.js",
"test-net-socket-setnodelay.js", "test-net-socket-setnodelay.js",
"test-net-socket-timeout-unref.js",
"test-net-socket-write-after-close.js",
"test-net-socket-write-error.js",
"test-net-sync-cork.js",
"test-net-timeout-no-handle.js", "test-net-timeout-no-handle.js",
"test-net-writable.js",
"test-net-write-arguments.js", "test-net-write-arguments.js",
"test-net-write-connect-write.js",
"test-net-write-fully-async-buffer.js",
"test-net-write-fully-async-hex-string.js",
"test-net-write-slow.js",
"test-next-tick-doesnt-hang.js", "test-next-tick-doesnt-hang.js",
"test-next-tick-domain.js",
"test-next-tick-errors.js",
"test-next-tick-fixed-queue-regression.js", "test-next-tick-fixed-queue-regression.js",
"test-next-tick-intentional-starvation.js", "test-next-tick-intentional-starvation.js",
"test-next-tick-ordering.js", "test-next-tick-ordering.js",
"test-next-tick-ordering2.js", "test-next-tick-ordering2.js",
"test-next-tick-when-exiting.js", "test-next-tick-when-exiting.js",
"test-next-tick.js", "test-next-tick.js",
"test-no-node-snapshot.js",
"test-nodeeventtarget.js", "test-nodeeventtarget.js",
"test-os-homedir-no-envvar.js",
"test-os.js", "test-os.js",
"test-outgoing-message-destroy.js", "test-outgoing-message-destroy.js",
"test-outgoing-message-pipe.js", "test-outgoing-message-pipe.js",
@ -468,15 +841,35 @@
"test-path-win32-exists.js", "test-path-win32-exists.js",
"test-path-zero-length-strings.js", "test-path-zero-length-strings.js",
"test-path.js", "test-path.js",
"test-perf-gc-crash.js",
"test-performanceobserver-gc.js",
"test-pipe-return-val.js",
"test-pipe-writev.js",
"test-process-abort.js",
"test-process-argv-0.js",
"test-process-beforeexit.js", "test-process-beforeexit.js",
"test-process-binding-internalbinding-allowlist.js", "test-process-binding-internalbinding-allowlist.js",
"test-process-binding.js",
"test-process-dlopen-undefined-exports.js",
"test-process-domain-segfault.js",
"test-process-emitwarning.js",
"test-process-env-allowed-flags.js", "test-process-env-allowed-flags.js",
"test-process-env-delete.js",
"test-process-env-windows-error-reset.js",
"test-process-exit-from-before-exit.js", "test-process-exit-from-before-exit.js",
"test-process-exit-handler.js", "test-process-exit-handler.js",
"test-process-exit-recursive.js", "test-process-exit-recursive.js",
"test-process-exit.js", "test-process-exit.js",
"test-process-getgroups.js",
"test-process-hrtime-bigint.js",
"test-process-kill-pid.js", "test-process-kill-pid.js",
"test-process-next-tick.js",
"test-process-no-deprecation.js",
"test-process-ppid.js",
"test-process-really-exit.js",
"test-process-uptime.js", "test-process-uptime.js",
"test-process-warning.js",
"test-promise-handled-rejection-no-warning.js",
"test-promise-unhandled-silent.js", "test-promise-unhandled-silent.js",
"test-promise-unhandled-throw-handler.js", "test-promise-unhandled-throw-handler.js",
"test-punycode.js", "test-punycode.js",
@ -484,6 +877,14 @@
"test-querystring-maxKeys-non-finite.js", "test-querystring-maxKeys-non-finite.js",
"test-querystring-multichar-separator.js", "test-querystring-multichar-separator.js",
"test-querystring.js", "test-querystring.js",
"test-readable-from-iterator-closing.js",
"test-readable-from.js",
"test-readable-large-hwm.js",
"test-readable-single-end.js",
"test-readline-async-iterators-destroy.js",
"test-readline-async-iterators.js",
"test-readline-carriage-return-between-chunks.js",
"test-readline-csi.js",
"test-readline-emit-keypress-events.js", "test-readline-emit-keypress-events.js",
"test-readline-interface-escapecodetimeout.js", "test-readline-interface-escapecodetimeout.js",
"test-readline-keys.js", "test-readline-keys.js",
@ -492,7 +893,31 @@
"test-readline-set-raw-mode.js", "test-readline-set-raw-mode.js",
"test-readline-undefined-columns.js", "test-readline-undefined-columns.js",
"test-readline.js", "test-readline.js",
"test-ref-unref-return.js",
"test-regression-object-prototype.js",
"test-require-invalid-package.js",
"test-require-long-path.js",
"test-require-nul.js",
"test-require-process.js",
"test-signal-handler-remove-on-exit.js",
"test-signal-handler.js",
"test-socket-address.js",
"test-socket-write-after-fin-error.js",
"test-source-map-enable.js",
"test-spawn-cmd-named-pipe.js",
"test-stdin-from-file-spawn.js", "test-stdin-from-file-spawn.js",
"test-stdin-hang.js",
"test-stdin-pipe-large.js",
"test-stdin-pipe-resume.js",
"test-stdin-script-child-option.js",
"test-stdio-pipe-access.js",
"test-stdio-pipe-redirect.js",
"test-stdio-pipe-stderr.js",
"test-stdio-undestroy.js",
"test-stdout-cannot-be-closed-child-process-pipe.js",
"test-stdout-pipeline-destroy.js",
"test-stdout-stderr-reading.js",
"test-stdout-stderr-write.js",
"test-stream-add-abort-signal.js", "test-stream-add-abort-signal.js",
"test-stream-aliases-legacy.js", "test-stream-aliases-legacy.js",
"test-stream-auto-destroy.js", "test-stream-auto-destroy.js",
@ -500,22 +925,30 @@
"test-stream-backpressure.js", "test-stream-backpressure.js",
"test-stream-big-packet.js", "test-stream-big-packet.js",
"test-stream-big-push.js", "test-stream-big-push.js",
"test-stream-catch-rejections.js",
"test-stream-construct.js", "test-stream-construct.js",
"test-stream-decoder-objectmode.js",
"test-stream-destroy-event-order.js", "test-stream-destroy-event-order.js",
"test-stream-duplex-destroy.js", "test-stream-duplex-destroy.js",
"test-stream-duplex-end.js", "test-stream-duplex-end.js",
"test-stream-duplex-from.js", "test-stream-duplex-from.js",
"test-stream-duplex-props.js", "test-stream-duplex-props.js",
"test-stream-duplex-readable-end.js", "test-stream-duplex-readable-end.js",
"test-stream-duplex-readable-writable.js",
"test-stream-duplex-writable-finished.js", "test-stream-duplex-writable-finished.js",
"test-stream-duplex.js", "test-stream-duplex.js",
"test-stream-end-of-streams.js",
"test-stream-end-paused.js", "test-stream-end-paused.js",
"test-stream-error-once.js", "test-stream-error-once.js",
"test-stream-events-prepend.js", "test-stream-events-prepend.js",
"test-stream-filter.js",
"test-stream-flatMap.js",
"test-stream-forEach.js",
"test-stream-inheritance.js", "test-stream-inheritance.js",
"test-stream-ispaused.js", "test-stream-ispaused.js",
"test-stream-objectmode-undefined.js", "test-stream-objectmode-undefined.js",
"test-stream-once-readable-pipe.js", "test-stream-once-readable-pipe.js",
"test-stream-passthrough-drain.js",
"test-stream-pipe-after-end.js", "test-stream-pipe-after-end.js",
"test-stream-pipe-await-drain-manual-resume.js", "test-stream-pipe-await-drain-manual-resume.js",
"test-stream-pipe-await-drain-push-while-write.js", "test-stream-pipe-await-drain-push-while-write.js",
@ -523,6 +956,7 @@
"test-stream-pipe-cleanup-pause.js", "test-stream-pipe-cleanup-pause.js",
"test-stream-pipe-cleanup.js", "test-stream-pipe-cleanup.js",
"test-stream-pipe-error-handling.js", "test-stream-pipe-error-handling.js",
"test-stream-pipe-error-unhandled.js",
"test-stream-pipe-event.js", "test-stream-pipe-event.js",
"test-stream-pipe-flow-after-unpipe.js", "test-stream-pipe-flow-after-unpipe.js",
"test-stream-pipe-flow.js", "test-stream-pipe-flow.js",
@ -533,8 +967,12 @@
"test-stream-pipe-unpipe-streams.js", "test-stream-pipe-unpipe-streams.js",
"test-stream-pipe-without-listenerCount.js", "test-stream-pipe-without-listenerCount.js",
"test-stream-pipeline-async-iterator.js", "test-stream-pipeline-async-iterator.js",
"test-stream-pipeline-duplex.js",
"test-stream-pipeline-listeners.js",
"test-stream-pipeline-queued-end-in-destroy.js", "test-stream-pipeline-queued-end-in-destroy.js",
"test-stream-pipeline-uncaught.js",
"test-stream-pipeline-with-empty-string.js", "test-stream-pipeline-with-empty-string.js",
"test-stream-push-order.js",
"test-stream-push-strings.js", "test-stream-push-strings.js",
"test-stream-readable-aborted.js", "test-stream-readable-aborted.js",
"test-stream-readable-add-chunk-during-data.js", "test-stream-readable-add-chunk-during-data.js",
@ -566,15 +1004,21 @@
"test-stream-readable-resumeScheduled.js", "test-stream-readable-resumeScheduled.js",
"test-stream-readable-setEncoding-existing-buffers.js", "test-stream-readable-setEncoding-existing-buffers.js",
"test-stream-readable-setEncoding-null.js", "test-stream-readable-setEncoding-null.js",
"test-stream-readable-strategy-option.js",
"test-stream-readable-unpipe-resume.js",
"test-stream-readable-unshift.js", "test-stream-readable-unshift.js",
"test-stream-readable-with-unimplemented-_read.js", "test-stream-readable-with-unimplemented-_read.js",
"test-stream-readableListening-state.js", "test-stream-readableListening-state.js",
"test-stream-reduce.js",
"test-stream-toArray.js",
"test-stream-toWeb-allows-server-response.js",
"test-stream-transform-callback-twice.js", "test-stream-transform-callback-twice.js",
"test-stream-transform-constructor-set-methods.js", "test-stream-transform-constructor-set-methods.js",
"test-stream-transform-destroy.js", "test-stream-transform-destroy.js",
"test-stream-transform-final-sync.js", "test-stream-transform-final-sync.js",
"test-stream-transform-final.js", "test-stream-transform-final.js",
"test-stream-transform-flush-data.js", "test-stream-transform-flush-data.js",
"test-stream-transform-hwm0.js",
"test-stream-transform-objectmode-falsey-value.js", "test-stream-transform-objectmode-falsey-value.js",
"test-stream-transform-split-highwatermark.js", "test-stream-transform-split-highwatermark.js",
"test-stream-transform-split-objectmode.js", "test-stream-transform-split-objectmode.js",
@ -589,6 +1033,7 @@
"test-stream-writable-decoded-encoding.js", "test-stream-writable-decoded-encoding.js",
"test-stream-writable-destroy.js", "test-stream-writable-destroy.js",
"test-stream-writable-end-cb-error.js", "test-stream-writable-end-cb-error.js",
"test-stream-writable-end-cb-uncaught.js",
"test-stream-writable-end-multiple.js", "test-stream-writable-end-multiple.js",
"test-stream-writable-ended-state.js", "test-stream-writable-ended-state.js",
"test-stream-writable-final-async.js", "test-stream-writable-final-async.js",
@ -616,6 +1061,7 @@
"test-stream2-basic.js", "test-stream2-basic.js",
"test-stream2-compatibility.js", "test-stream2-compatibility.js",
"test-stream2-decode-partial.js", "test-stream2-decode-partial.js",
"test-stream2-finish-pipe-error.js",
"test-stream2-finish-pipe.js", "test-stream2-finish-pipe.js",
"test-stream2-large-read-stall.js", "test-stream2-large-read-stall.js",
"test-stream2-objects.js", "test-stream2-objects.js",
@ -638,24 +1084,60 @@
"test-stream3-cork-end.js", "test-stream3-cork-end.js",
"test-stream3-cork-uncork.js", "test-stream3-cork-uncork.js",
"test-stream3-pause-then-read.js", "test-stream3-pause-then-read.js",
"test-stream3-pipeline-async-iterator.js",
"test-streams-highwatermark.js", "test-streams-highwatermark.js",
"test-string-decoder.js", "test-string-decoder.js",
"test-stringbytes-external.js",
"test-sync-fileread.js",
"test-sys.js",
"test-tick-processor-arguments.js",
"test-timers-api-refs.js", "test-timers-api-refs.js",
"test-timers-args.js", "test-timers-args.js",
"test-timers-clear-null-does-not-throw-error.js", "test-timers-clear-null-does-not-throw-error.js",
"test-timers-clear-object-does-not-throw-error.js", "test-timers-clear-object-does-not-throw-error.js",
"test-timers-clear-timeout-interval-equivalent.js", "test-timers-clear-timeout-interval-equivalent.js",
"test-timers-clearImmediate-als.js",
"test-timers-clearImmediate.js", "test-timers-clearImmediate.js",
"test-timers-immediate-queue.js",
"test-timers-immediate.js",
"test-timers-interval-throw.js", "test-timers-interval-throw.js",
"test-timers-non-integer-delay.js", "test-timers-non-integer-delay.js",
"test-timers-refresh-in-callback.js",
"test-timers-refresh.js", "test-timers-refresh.js",
"test-timers-same-timeout-wrong-list-deleted.js", "test-timers-same-timeout-wrong-list-deleted.js",
"test-timers-setimmediate-infinite-loop.js",
"test-timers-socket-timeout-removes-other-socket-unref-timer.js",
"test-timers-timeout-with-non-integer.js", "test-timers-timeout-with-non-integer.js",
"test-timers-uncaught-exception.js", "test-timers-uncaught-exception.js",
"test-timers-unref-throw-then-ref.js", "test-timers-unref-throw-then-ref.js",
"test-timers-unref.js",
"test-timers-unrefd-interval-still-fires.js",
"test-timers-unrefed-in-beforeexit.js",
"test-timers-unrefed-in-callback.js",
"test-timers-user-call.js", "test-timers-user-call.js",
"test-timers-zero-timeout.js", "test-timers-zero-timeout.js",
"test-timers.js",
"test-tls-alert-handling.js",
"test-tls-alert.js",
"test-tls-client-renegotiation-limit.js",
"test-tls-dhe.js",
"test-tls-ecdh-auto.js",
"test-tls-ecdh-multiple.js",
"test-tls-ecdh.js",
"test-tls-enable-trace-cli.js",
"test-tls-enable-trace.js",
"test-tls-env-extra-ca-no-crypto.js",
"test-tls-ocsp-callback.js",
"test-tls-psk-server.js",
"test-tls-securepair-server.js",
"test-tls-server-verify.js",
"test-tls-session-cache.js",
"test-tls-set-ciphers.js",
"test-tls-transport-destroy-after-own-gc.js",
"test-trace-events-async-hooks-dynamic.js",
"test-trace-events-async-hooks-worker.js",
"test-tty-stdin-end.js", "test-tty-stdin-end.js",
"test-tz-version.js",
"test-url-domain-ascii-unicode.js", "test-url-domain-ascii-unicode.js",
"test-url-fileurltopath.js", "test-url-fileurltopath.js",
"test-url-format-invalid-input.js", "test-url-format-invalid-input.js",
@ -666,19 +1148,31 @@
"test-url-pathtofileurl.js", "test-url-pathtofileurl.js",
"test-url-relative.js", "test-url-relative.js",
"test-url-urltooptions.js", "test-url-urltooptions.js",
"test-utf8-scripts.js",
"test-util-deprecate-invalid-code.js", "test-util-deprecate-invalid-code.js",
"test-util-deprecate.js", "test-util-deprecate.js",
"test-util-format.js", "test-util-format.js",
"test-util-inherits.js", "test-util-inherits.js",
"test-util-inspect-getters-accessing-this.js",
"test-util-inspect-long-running.js", "test-util-inspect-long-running.js",
"test-util-inspect-namespace.js", "test-util-inspect-namespace.js",
"test-util-inspect-proxy.js", "test-util-inspect-proxy.js",
"test-util-inspect.js", "test-util-inspect.js",
"test-util-isDeepStrictEqual.js", "test-util-isDeepStrictEqual.js",
"test-util-primordial-monkeypatching.js",
"test-util-promisify.js", "test-util-promisify.js",
"test-util-types-exists.js", "test-util-types-exists.js",
"test-util-types.js", "test-util-types.js",
"test-util.js", "test-util.js",
"test-uv-binding-constant.js",
"test-uv-unmapped-exception.js",
"test-v8-coverage.js",
"test-v8-deserialize-buffer.js",
"test-v8-flag-pool-size-0.js",
"test-v8-global-setter.js",
"test-v8-stop-coverage.js",
"test-v8-take-coverage-noop.js",
"test-v8-take-coverage.js",
"test-vm-access-process-env.js", "test-vm-access-process-env.js",
"test-vm-attributes-property-not-on-sandbox.js", "test-vm-attributes-property-not-on-sandbox.js",
"test-vm-codegen.js", "test-vm-codegen.js",
@ -723,28 +1217,39 @@
"test-vm-timeout-escape-promise-2.js", "test-vm-timeout-escape-promise-2.js",
"test-vm-timeout-escape-promise.js", "test-vm-timeout-escape-promise.js",
"test-vm-timeout.js", "test-vm-timeout.js",
"test-weakref.js",
"test-webcrypto-encrypt-decrypt.js",
"test-webcrypto-sign-verify.js", "test-webcrypto-sign-verify.js",
"test-websocket.js",
"test-webstream-string-tag.js",
"test-whatwg-encoding-custom-api-basics.js", "test-whatwg-encoding-custom-api-basics.js",
"test-whatwg-encoding-custom-textdecoder-ignorebom.js", "test-whatwg-encoding-custom-textdecoder-ignorebom.js",
"test-whatwg-encoding-custom-textdecoder-streaming.js", "test-whatwg-encoding-custom-textdecoder-streaming.js",
"test-whatwg-events-add-event-listener-options-passive.js", "test-whatwg-events-add-event-listener-options-passive.js",
"test-whatwg-events-add-event-listener-options-signal.js", "test-whatwg-events-add-event-listener-options-signal.js",
"test-whatwg-events-customevent.js", "test-whatwg-events-customevent.js",
"test-whatwg-readablebytestreambyob.js",
"test-whatwg-url-custom-deepequal.js", "test-whatwg-url-custom-deepequal.js",
"test-whatwg-url-custom-global.js", "test-whatwg-url-custom-global.js",
"test-whatwg-url-custom-href-side-effect.js", "test-whatwg-url-custom-href-side-effect.js",
"test-whatwg-url-custom-tostringtag.js", "test-whatwg-url-custom-tostringtag.js",
"test-whatwg-url-override-hostname.js", "test-whatwg-url-override-hostname.js",
"test-whatwg-url-properties.js", "test-whatwg-url-properties.js",
"test-worker-cleanexit-with-js.js",
"test-worker-message-port-infinite-message-loop.js", "test-worker-message-port-infinite-message-loop.js",
"test-worker-message-port-multiple-sharedarraybuffers.js", "test-worker-message-port-multiple-sharedarraybuffers.js",
"test-worker-message-port-receive-message.js", "test-worker-message-port-receive-message.js",
"test-worker-on-process-exit.js",
"test-worker-ref-onexit.js",
"test-worker-terminate-unrefed.js",
"test-zlib-close-after-error.js", "test-zlib-close-after-error.js",
"test-zlib-close-after-write.js", "test-zlib-close-after-write.js",
"test-zlib-convenience-methods.js", "test-zlib-convenience-methods.js",
"test-zlib-create-raw.js",
"test-zlib-deflate-raw-inherits.js", "test-zlib-deflate-raw-inherits.js",
"test-zlib-destroy-pipe.js", "test-zlib-destroy-pipe.js",
"test-zlib-empty-buffer.js", "test-zlib-empty-buffer.js",
"test-zlib-flush-write-sync-interleaved.js",
"test-zlib-from-string.js", "test-zlib-from-string.js",
"test-zlib-invalid-input.js", "test-zlib-invalid-input.js",
"test-zlib-no-stream.js", "test-zlib-no-stream.js",
@ -762,14 +1267,41 @@
"console-dumb-tty.js", "console-dumb-tty.js",
"no_dropped_stdio.js", "no_dropped_stdio.js",
"no_interleaved_stdio.js", "no_interleaved_stdio.js",
"test-set-raw-mode-reset-process-exit.js",
"test-set-raw-mode-reset.js",
"test-tty-color-support-warning-2.js", "test-tty-color-support-warning-2.js",
"test-tty-color-support-warning.js", "test-tty-color-support-warning.js",
"test-tty-stdin-call-end.js",
"test-tty-stdin-end.js", "test-tty-stdin-end.js",
"test-tty-stdout-end.js" "test-tty-stdout-end.js"
], ],
"pummel": [], "pummel": [
"test-crypto-dh-hash.js",
"test-crypto-timing-safe-equal-benchmarks.js",
"test-dh-regr.js",
"test-fs-largefile.js",
"test-fs-readfile-tostring-fail.js",
"test-fs-watch-system-limit.js",
"test-heapsnapshot-near-heap-limit-big.js",
"test-net-many-clients.js",
"test-net-pingpong-delay.js",
"test-process-cpuUsage.js",
"test-stream-pipe-multi.js"
],
"sequential": [ "sequential": [
"test-child-process-exit.js" "test-buffer-creation-regression.js",
"test-child-process-exit.js",
"test-http-server-keep-alive-timeout-slow-server.js",
"test-net-better-error-messages-port.js",
"test-net-connect-handle-econnrefused.js",
"test-net-connect-local-error.js",
"test-net-reconnect-error.js",
"test-net-response-size.js",
"test-net-server-bind.js",
"test-tls-lookup.js",
"test-tls-psk-client.js",
"test-tls-securepair-client.js",
"test-tls-session-timeout.js"
] ]
}, },
"windowsIgnore": { "windowsIgnore": {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,143 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const { spawnSync } = require('child_process');
// This is a sibling test to test/addons/uv-handle-leak.
const bindingPath = path.resolve(
__dirname, '..', 'addons', 'uv-handle-leak', 'build',
`${common.buildType}/binding.node`);
if (!fs.existsSync(bindingPath))
common.skip('binding not built yet');
if (process.argv[2] === 'child') {
const { Worker } = require('worker_threads');
// The worker thread loads and then unloads `bindingPath`. Because of this the
// symbols in `bindingPath` are lost when the worker thread quits, but the
// number of open handles in the worker thread's event loop is assessed in the
// main thread afterwards, and the names of the callbacks associated with the
// open handles is retrieved at that time as well. Thus, we require
// `bindingPath` here so that the symbols and their names survive the life
// cycle of the worker thread.
require(bindingPath);
new Worker(`
const binding = require(${JSON.stringify(bindingPath)});
binding.leakHandle();
binding.leakHandle(0);
binding.leakHandle(0x42);
`, { eval: true });
} else {
const child = cp.spawnSync(process.execPath, [__filename, 'child']);
const stderr = child.stderr.toString();
assert.strictEqual(child.stdout.toString(), '');
const lines = stderr.split('\n');
let state = 'initial';
// Parse output that is formatted like this:
// uv loop at [0x559b65ed5770] has open handles:
// [0x7f2de0018430] timer (active)
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: 0x7f2df33df140 example_instance [...]
// (First field): 0x7f2df33dedc0 vtable for ExampleOwnerClass [...]
// [0x7f2de000b870] timer
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: (nil)
// [0x7f2de000b910] timer
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: 0x42
// uv loop at [0x559b65ed5770] has 3 open handles in total
function isGlibc() {
try {
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
const libcInfo = lddOut.toString().split('\n').map(
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
if (libcInfo.length === 0)
return false;
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
if (/gnu_get_libc_version/.test(nmOut))
return true;
} catch {
return false;
}
}
if (!(common.isFreeBSD ||
common.isAIX ||
common.isIBMi ||
(common.isLinux && !isGlibc()) ||
common.isWindows)) {
assert(stderr.includes('ExampleOwnerClass'), stderr);
assert(stderr.includes('CloseCallback'), stderr);
assert(stderr.includes('example_instance'), stderr);
}
while (lines.length > 0) {
const line = lines.shift().trim();
if (line.length === 0) {
continue; // Skip empty lines.
}
switch (state) {
case 'initial':
assert.match(line, /^uv loop at \[.+\] has open handles:$/);
state = 'handle-start';
break;
case 'handle-start':
if (/^uv loop at \[.+\] has \d+ open handles in total$/.test(line)) {
state = 'source-line';
break;
}
assert.match(line, /^\[.+\] timer( \(active\))?$/);
state = 'close-callback';
break;
case 'close-callback':
assert.match(line, /^Close callback:/);
state = 'data';
break;
case 'data':
assert.match(line, /^Data: .+$/);
state = 'maybe-first-field';
break;
case 'maybe-first-field':
if (!/^\(First field\)/.test(line)) {
lines.unshift(line);
}
state = 'handle-start';
break;
case 'source-line':
assert.match(line, /CheckedUvLoopClose/);
state = 'assertion-failure';
break;
case 'assertion-failure':
assert.match(line, /Assertion failed:/);
state = 'done';
break;
case 'done':
break;
}
}
assert.strictEqual(state, 'done');
}

View file

@ -0,0 +1,20 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for async_hooks benchmark test');
const runBenchmark = require('../common/benchmark');
runBenchmark('async_hooks');

View file

@ -0,0 +1,21 @@
// 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.
'use strict';
const common = require('../common');
if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP benchmark test');
// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('http', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,23 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP/2 benchmark test');
// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('http2', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,24 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for TLS benchmark test');
// Because the TLS benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('tls', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,21 @@
// 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.
'use strict';
const common = require('../common');
if (!common.enoughTestMem)
common.skip('Insufficient memory for Worker benchmark test');
// Because the worker benchmarks can run on different threads,
// this should be in sequential rather than parallel to make sure
// it does not conflict with tests that choose random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('worker', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,19 @@
// 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.
'use strict';
const { mustNotCall, mustCall } = require('../common');
Object.defineProperties(Object.prototype, {
then: {
set: mustNotCall('set %Object.prototype%.then'),
get: mustNotCall('get %Object.prototype%.then'),
},
});
import('data:text/javascript,').then(mustCall());

View file

@ -0,0 +1,29 @@
// 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.
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('node:assert');
const fs = require('node:fs/promises');
tmpdir.refresh();
const target = tmpdir.fileURL(`${Math.random()}.mjs`);
(async () => {
await assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' });
await fs.writeFile(target, 'export default "actual target"\n');
const moduleRecord = await import(target);
await fs.rm(target);
assert.strictEqual(await import(target), moduleRecord);
})().then(common.mustCall());

View file

@ -0,0 +1,17 @@
// 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.
'use strict';
require('../common');
const { cache } = require;
Object.keys(cache).forEach((key) => {
delete cache[key];
});
// Require the same module again triggers the crash
require('../common');

View file

@ -0,0 +1,54 @@
// 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.
'use strict';
// This test ensures that JavaScript file that includes
// a reserved Windows word can be loaded as ESM module
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs').promises;
const path = require('path');
const imp = (file) => {
return import(path.relative(__dirname, file).replace(/\\/g, '/'));
};
(async () => {
tmpdir.refresh();
const rel = (file) => tmpdir.resolve(file);
{ // Load a single script
const file = rel('con.mjs');
await fs.writeFile(file, 'export default "ok"');
assert.strictEqual((await imp(file)).default, 'ok');
await fs.unlink(file);
}
{ // Load a module
const entry = rel('entry.mjs');
const nmDir = rel('node_modules');
const mDir = rel('node_modules/con');
const pkg = rel('node_modules/con/package.json');
const script = rel('node_modules/con/index.mjs');
await fs.writeFile(entry, 'export {default} from "con"');
await fs.mkdir(nmDir);
await fs.mkdir(mDir);
await fs.writeFile(pkg, '{"main":"index.mjs"}');
await fs.writeFile(script, 'export default "ok"');
assert.strictEqual((await imp(entry)).default, 'ok');
await fs.unlink(script);
await fs.unlink(pkg);
await fs.rmdir(mDir);
await fs.rmdir(nmDir);
await fs.unlink(entry);
}
})().then(common.mustCall());

View file

@ -0,0 +1,41 @@
// 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.
'use strict';
require('../common');
const assert = require('assert');
const { compileFunction } = require('node:vm');
const min = -2147483648;
const max = 2147483647;
compileFunction('', [], { lineOffset: min, columnOffset: min });
compileFunction('', [], { lineOffset: max, columnOffset: max });
assert.throws(
() => {
compileFunction('', [], { lineOffset: min - 1, columnOffset: max });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.lineOffset" is out of range/,
}
);
assert.throws(
() => {
compileFunction('', [], { lineOffset: min, columnOffset: min - 1 });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.columnOffset" is out of range/,
}
);

View file

@ -0,0 +1,60 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
const args = [];
if (strict) args.push('--use_strict');
args.push('-pe', cmd);
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.on('close', cb);
}
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
'var x = 100; y = x;',
'var ______________________________________________; throw 10' ];
function go() {
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);
});
}
go();

View file

@ -0,0 +1,38 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
process.maxTickDepth = 10;
let i = 20;
process.nextTick(function f() {
console.error(`tick ${i}`);
if (i-- > 0)
process.nextTick(f);
});

View file

@ -0,0 +1,61 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
const args = [];
if (strict) args.push('--use_strict');
args.push('-p');
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.stdin.end(cmd);
child.on('close', cb);
}
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
'let x = 100; y = x;',
'let ______________________________________________; throw 10' ];
function go() {
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);
});
}
go();

View file

@ -0,0 +1,19 @@
// 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.
'use strict';
require('../common');
const util = require('util');
const err = new Error('foo\nbar');
console.log(util.inspect({ err, nested: { err } }, { compact: true }));
console.log(util.inspect({ err, nested: { err } }, { compact: false }));
err.foo = 'bar';
console.log(util.inspect(err, { compact: true, breakLength: 5 }));

View file

@ -0,0 +1,22 @@
// 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.
'use strict';
require('../common');
// This test ensures Math functions don't fail with an "illegal instruction"
// error on ARM devices (primarily on the Raspberry Pi 1)
// See https://github.com/nodejs/node/issues/1376
// and https://code.google.com/p/v8/issues/detail?id=4019
// Iterate over all Math functions
Object.getOwnPropertyNames(Math).forEach((functionName) => {
if (!/[A-Z]/.test(functionName)) {
// The function names don't have capital letters.
Math[functionName](-0.5);
}
});

View file

@ -0,0 +1,18 @@
// 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.
'use strict';
require('../common');
const { AsyncResource } = require('async_hooks');
try {
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
} catch {
// Continue regardless of error.
}
// Should abort (fail the case) if async id is not matching.

View file

@ -0,0 +1,24 @@
// 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.
'use strict';
// Test that passing thisArg to runInAsyncScope() works.
const common = require('../common');
const assert = require('assert');
const { AsyncResource } = require('async_hooks');
const thisArg = {};
const res = new AsyncResource('fhqwhgads');
function callback() {
assert.strictEqual(this, thisArg);
}
res.runInAsyncScope(common.mustCall(callback), thisArg);

View file

@ -0,0 +1,24 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
[1, false, '', {}, []].forEach((i) => {
assert.throws(() => AsyncLocalStorage.bind(i), {
code: 'ERR_INVALID_ARG_TYPE'
});
});
const fn = common.mustCall(AsyncLocalStorage.bind(() => 123));
assert.strictEqual(fn(), 123);
const fn2 = AsyncLocalStorage.bind(common.mustCall((arg) => assert.strictEqual(arg, 'test')));
fn2('test');

View file

@ -0,0 +1,42 @@
// 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.
'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
const { AsyncLocalStorage } = require('async_hooks');
// Regression test for https://github.com/nodejs/node/issues/38781
const context = vm.createContext({
AsyncLocalStorage,
assert
});
vm.runInContext(`
const storage = new AsyncLocalStorage()
async function test() {
return storage.run({ test: 'vm' }, async () => {
assert.strictEqual(storage.getStore().test, 'vm');
await 42;
assert.strictEqual(storage.getStore().test, 'vm');
});
}
test()
`, context);
const storage = new AsyncLocalStorage();
async function test() {
return storage.run({ test: 'main context' }, async () => {
assert.strictEqual(storage.getStore().test, 'main context');
await 42;
assert.strictEqual(storage.getStore().test, 'main context');
});
}
test();

View file

@ -0,0 +1,22 @@
// 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.
'use strict';
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');
// Regression test for: https://github.com/nodejs/node/issues/34556
const als = new AsyncLocalStorage();
const done = common.mustCall();
function run(count) {
if (count !== 0) return als.run({}, run, --count);
done();
}
run(1000);

View file

@ -0,0 +1,72 @@
// 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.
'use strict';
const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const http = require('http');
const cls = new AsyncLocalStorage();
const NUM_CLIENTS = 10;
// Run multiple clients that receive data from a server
// in multiple chunks, in a single non-closure function.
// Use the AsyncLocalStorage (ALS) APIs to maintain the context
// and data download. Make sure that individual clients
// receive their respective data, with no conflicts.
// Set up a server that sends large buffers of data, filled
// with cardinal numbers, increasing per request
let index = 0;
const server = http.createServer((q, r) => {
// Send a large chunk as response, otherwise the data
// may be sent in a single chunk, and the callback in the
// client may be called only once, defeating the purpose of test
r.end((index++ % 10).toString().repeat(1024 * 1024));
});
const countdown = new Countdown(NUM_CLIENTS, () => {
server.close();
});
server.listen(0, common.mustCall(() => {
for (let i = 0; i < NUM_CLIENTS; i++) {
cls.run(new Map(), common.mustCall(() => {
const options = { port: server.address().port };
const req = http.get(options, common.mustCall((res) => {
const store = cls.getStore();
store.set('data', '');
// Make ondata and onend non-closure
// functions and fully dependent on ALS
res.setEncoding('utf8');
res.on('data', ondata);
res.on('end', common.mustCall(onend));
}));
req.end();
}));
}
}));
// Accumulate the current data chunk with the store data
function ondata(d) {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
let chunk = store.get('data');
chunk += d;
store.set('data', chunk);
}
// Retrieve the store data, and test for homogeneity
function onend() {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
const data = store.get('data');
assert.strictEqual(data, data[0].repeat(data.length));
countdown.dec();
}

View file

@ -0,0 +1,23 @@
// 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.
'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
const runInAsyncScope =
asyncLocalStorage.run(123, common.mustCall(() => AsyncLocalStorage.snapshot()));
const result =
asyncLocalStorage.run(321, common.mustCall(() => {
return runInAsyncScope(() => {
return asyncLocalStorage.getStore();
});
}));
strictEqual(result, 123);

View file

@ -0,0 +1,14 @@
// 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.
'use strict';
require('../common');
const assert = require('assert');
// https://github.com/nodejs/node/issues/21219
assert.strictEqual(Atomics.wake, undefined);

View file

@ -0,0 +1,34 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const { mustNotCall } = require('../common');
process.on('beforeExit', mustNotCall('exit should not allow this to occur'));
process.exit();

View file

@ -0,0 +1,31 @@
// 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.
// Flags: --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
const { Blob, kMaxLength } = require('buffer');
if (common.isFreeBSD)
common.skip('Oversized buffer make the FreeBSD CI runner crash');
try {
new Blob([new Uint8Array(kMaxLength), [1]]);
} catch (e) {
if (
e.message === 'Array buffer allocation failed' ||
e.message === `Invalid typed array length: ${kMaxLength}`
) {
common.skip(
'Insufficient memory on this platform for oversized buffer test.'
);
} else {
assert.strictEqual(e.code, 'ERR_BUFFER_TOO_LARGE');
}
}

View file

@ -0,0 +1,34 @@
// 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.
'use strict';
require('../common');
const assert = require('assert');
const sab = new SharedArrayBuffer(24);
const arr1 = new Uint16Array(sab);
const arr2 = new Uint16Array(12);
arr2[0] = 5000;
arr1[0] = 5000;
arr1[1] = 4000;
arr2[1] = 4000;
const arr_buf = Buffer.from(arr1.buffer);
const ar_buf = Buffer.from(arr2.buffer);
assert.deepStrictEqual(arr_buf, ar_buf);
arr1[1] = 6000;
arr2[1] = 6000;
assert.deepStrictEqual(arr_buf, ar_buf);
// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
Buffer.from({ buffer: sab }); // Should not throw.

View file

@ -0,0 +1,115 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
[-1, 10].forEach((offset) => {
assert.throws(
() => Buffer.alloc(9).write('foo', offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 && <= 9. Received ${offset}`
}
);
});
const resultMap = new Map([
['utf8', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['ucs2', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['ascii', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['latin1', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['binary', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['utf16le', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['base64', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['base64url', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['hex', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
]);
// utf8, ucs2, ascii, latin1, utf16le
const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1',
'binary', 'utf16le', 'utf-16le'];
encodings
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
.forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('foo', encoding);
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
if (encoding.includes('-'))
encoding = encoding.replace('-', '');
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// base64
['base64', 'BASE64', 'base64url', 'BASE64URL'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('Zm9v', encoding);
assert.strictEqual(buf.write('Zm9v', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// hex
['hex', 'HEX'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('666f6f', encoding);
assert.strictEqual(buf.write('666f6f', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// Invalid encodings
for (let i = 1; i < 10; i++) {
const encoding = String(i).repeat(i);
const error = common.expectsError({
code: 'ERR_UNKNOWN_ENCODING',
name: 'TypeError',
message: `Unknown encoding: ${encoding}`
});
assert.ok(!Buffer.isEncoding(encoding));
assert.throws(() => Buffer.alloc(9).write('foo', encoding), error);
}
// UCS-2 overflow CVE-2018-12115
for (let i = 1; i < 4; i++) {
// Allocate two Buffers sequentially off the pool. Run more than once in case
// we hit the end of the pool and don't get sequential allocations
const x = Buffer.allocUnsafe(4).fill(0);
const y = Buffer.allocUnsafe(4).fill(1);
// Should not write anything, pos 3 doesn't have enough room for a 16-bit char
assert.strictEqual(x.write('ыыыыыы', 3, 'ucs2'), 0);
// CVE-2018-12115 experienced via buffer overrun to next block in the pool
assert.strictEqual(Buffer.compare(y, Buffer.alloc(4, 1)), 0);
}
// Should not write any data when there is no space for 16-bit chars
const z = Buffer.alloc(4, 0);
assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0);
assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0);
// Make sure longer strings are written up to the buffer end.
assert.strictEqual(z.write('abcd', 2), 2);
assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]);
// Large overrun could corrupt the process
assert.strictEqual(Buffer.alloc(4)
.write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0);
{
// .write() does not affect the byte after the written-to slice of the Buffer.
// Refs: https://github.com/nodejs/node/issues/26422
const buf = Buffer.alloc(8);
assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4);
assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]);
}

View file

@ -0,0 +1,34 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const child_process = require('child_process');
const fixtures = require('../common/fixtures');
child_process.fork(fixtures.path('empty.js')); // should not hang

View file

@ -0,0 +1,36 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
function fail(proc, args) {
assert.throws(() => {
proc.send.apply(proc, args);
}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
}
let target = process;
if (process.argv[2] !== 'child') {
target = cp.fork(__filename, ['child']);
target.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
}
fail(target, ['msg', null, null]);
fail(target, ['msg', null, '']);
fail(target, ['msg', null, 'foo']);
fail(target, ['msg', null, 0]);
fail(target, ['msg', null, NaN]);
fail(target, ['msg', null, 1]);
fail(target, ['msg', null, null, common.mustNotCall()]);

View file

@ -0,0 +1,47 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
if (process.argv[2] === 'child') {
// Just reference stdin, it should start it
process.stdin; // eslint-disable-line no-unused-expressions
return;
}
const proc = spawn(process.execPath, [__filename, 'child'], {
stdio: ['ipc', 'inherit', 'inherit']
});
proc.on('exit', common.mustCall(function(code) {
assert.strictEqual(code, 0);
}));

View file

@ -0,0 +1,86 @@
// 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.
// Test for "overlapped" stdio option. This test uses the "overlapped-checker"
// helper program which basically a specialized echo program.
//
// The test has two goals:
//
// - Verify that overlapped I/O works on windows. The test program will deadlock
// if stdin doesn't have the FILE_FLAG_OVERLAPPED flag set on startup (see
// test/overlapped-checker/main_win.c for more details).
// - Verify that "overlapped" stdio option works transparently as a pipe (on
// unix/windows)
//
// This is how the test works:
//
// - This script assumes only numeric strings are written to the test program
// stdout.
// - The test program will be spawned with "overlapped" set on stdin and "pipe"
// set on stdout/stderr and at startup writes a number to its stdout
// - When this script receives some data, it will parse the number, add 50 and
// write to the test program's stdin.
// - The test program will then echo the number back to us which will repeat the
// cycle until the number reaches 200, at which point we send the "exit"
// string, which causes the test program to exit.
// - Extra assertion: Every time the test program writes a string to its stdout,
// it will write the number of bytes written to stderr.
// - If overlapped I/O is not setup correctly, this test is going to hang.
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const child_process = require('child_process');
const exeExtension = process.platform === 'win32' ? '.exe' : '';
const exe = 'overlapped-checker' + exeExtension;
const exePath = path.join(path.dirname(process.execPath), exe);
if (!require('fs').existsSync(exePath)) {
common.skip(exe + ' binary is not available');
}
const child = child_process.spawn(exePath, [], {
stdio: ['overlapped', 'pipe', 'pipe']
});
child.stdin.setEncoding('utf8');
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
function writeNext(n) {
child.stdin.write((n + 50).toString());
}
child.stdout.on('data', (s) => {
const n = Number(s);
if (n >= 200) {
child.stdin.write('exit');
return;
}
writeNext(n);
});
let stderr = '';
child.stderr.on('data', (s) => {
stderr += s;
});
child.stderr.on('end', common.mustCall(() => {
// This is the sequence of numbers sent to us:
// - 0 (1 byte written)
// - 50 (2 bytes written)
// - 100 (3 bytes written)
// - 150 (3 bytes written)
// - 200 (3 bytes written)
assert.strictEqual(stderr, '12333');
}));
child.on('exit', common.mustCall((status) => {
// The test program will return the number of writes as status code.
assert.strictEqual(status, 0);
}));

View file

@ -0,0 +1,20 @@
// 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.
'use strict';
// Test that http.ClientRequest,prototype.destroy() returns `this`.
require('../common');
const assert = require('assert');
const http = require('http');
const clientRequest = new http.ClientRequest({ createConnection: () => {} });
assert.strictEqual(clientRequest.destroyed, false);
assert.strictEqual(clientRequest.destroy(), clientRequest);
assert.strictEqual(clientRequest.destroyed, true);
assert.strictEqual(clientRequest.destroy(), clientRequest);

View file

@ -0,0 +1,56 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// Installing a custom uncaughtException handler should override the default
// one that the cluster module installs.
// https://github.com/joyent/node/issues/2556
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const fork = require('child_process').fork;
const MAGIC_EXIT_CODE = 42;
const isTestRunner = process.argv[2] !== 'child';
if (isTestRunner) {
const primary = fork(__filename, ['child']);
primary.on('exit', common.mustCall((code) => {
assert.strictEqual(code, MAGIC_EXIT_CODE);
}));
} else if (cluster.isPrimary) {
process.on('uncaughtException', common.mustCall(() => {
process.nextTick(() => process.exit(MAGIC_EXIT_CODE));
}));
cluster.fork();
throw new Error('kill primary');
} else { // worker
process.exit();
}

View file

@ -0,0 +1,35 @@
// 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.
'use strict';
// Patch global.console before importing modules that may modify the console
// object.
const tmp = global.console;
global.console = 42;
require('../common');
const assert = require('assert');
// Originally the console had a getter. Test twice to verify it had no side
// effect.
assert.strictEqual(global.console, 42);
assert.strictEqual(global.console, 42);
assert.throws(
() => console.log('foo'),
{ name: 'TypeError' }
);
global.console = 1;
assert.strictEqual(global.console, 1);
assert.strictEqual(console, 1);
// Reset the console
global.console = tmp;
console.log('foo');

View file

@ -0,0 +1,21 @@
// 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.
'use strict';
// Flags: --expose-internals
require('../common');
const { formatTime } = require('internal/console/constructor');
const assert = require('assert');
assert.strictEqual(formatTime(100.0096), '100.01ms');
assert.strictEqual(formatTime(100.0115), '100.011ms');
assert.strictEqual(formatTime(1500.04), '1.500s');
assert.strictEqual(formatTime(1000.056), '1.000s');
assert.strictEqual(formatTime(60300.3), '1:00.300 (m:ss.mmm)');
assert.strictEqual(formatTime(4000457.4), '1:06:40.457 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3601310.4), '1:00:01.310 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3213601017.6), '892:40:01.018 (h:mm:ss.mmm)');

View file

@ -0,0 +1,41 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('assert');
function func() {}
let toStringCalled = false;
func.toString = function() {
toStringCalled = true;
};
require('util').inspect(func);
assert.ok(!toStringCalled);

View file

@ -0,0 +1,13 @@
// 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.
'use strict';
require('../common');
// Assigning to itself should not throw.
global.console = global.console; // eslint-disable-line no-self-assign

View file

@ -0,0 +1,118 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
// https://github.com/nodejs/node/issues/32738
// XXX(bnoordhuis) validateInt32() throwing ERR_OUT_OF_RANGE and RangeError
// instead of ERR_INVALID_ARG_TYPE and TypeError is questionable, IMO.
assert.throws(() => crypto.createDiffieHellman(13.37), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "sizeOrKey" is out of range. ' +
'It must be an integer. Received 13.37',
});
assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "generator" is out of range. ' +
'It must be an integer. Received 13.37',
});
for (const bits of [-1, 0, 1]) {
if (common.hasOpenSSL3) {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL',
name: 'Error',
message: /modulus too small/,
});
} else {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
name: 'Error',
message: /bits too small/,
});
}
}
for (const g of [-1, 1]) {
const ex = {
code: 'ERR_OSSL_DH_BAD_GENERATOR',
name: 'Error',
message: /bad generator/,
};
assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex);
assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex);
}
for (const g of [Buffer.from([]),
Buffer.from([0]),
Buffer.from([1])]) {
const ex = {
code: 'ERR_OSSL_DH_BAD_GENERATOR',
name: 'Error',
message: /bad generator/,
};
assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex);
assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex);
}
[
[0x1, 0x2],
() => { },
/abc/,
{},
].forEach((input) => {
assert.throws(
() => crypto.createDiffieHellman(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
}
);
});
// Invalid test: curve argument is undefined
assert.throws(
() => crypto.createECDH(),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "curve" argument must be of type string. ' +
'Received undefined'
});
assert.throws(
function() {
crypto.getDiffieHellman('unknown-group');
},
{
name: 'Error',
code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP',
message: 'Unknown DH group'
},
'crypto.getDiffieHellman(\'unknown-group\') ' +
'failed to throw the expected error.'
);
assert.throws(
() => crypto.createDiffieHellman('', true),
{
code: 'ERR_INVALID_ARG_TYPE'
}
);
[true, Symbol(), {}, () => {}, []].forEach((generator) => assert.throws(
() => crypto.createDiffieHellman('', 'base64', generator),
{ code: 'ERR_INVALID_ARG_TYPE' }
));

View file

@ -0,0 +1,50 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
function test() {
const odd = Buffer.alloc(39, 'A');
const c = crypto.createDiffieHellman(common.hasOpenSSL3 ? 1024 : 32);
c.setPrivateKey(odd);
c.generateKeys();
}
// FIPS requires a length of at least 1024
if (!common.hasFipsCrypto) {
test();
} else {
assert.throws(function() { test(); }, /key size too small/);
}

View file

@ -0,0 +1,56 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const domain = require('domain');
const test = (fn) => {
const ex = new Error('BAM');
const d = domain.create();
d.on('error', common.mustCall(function(err) {
assert.strictEqual(err, ex);
}));
const cb = common.mustCall(function() {
throw ex;
});
d.run(cb);
};
test(function(cb) {
crypto.pbkdf2('password', 'salt', 1, 8, cb);
});
test(function(cb) {
crypto.randomBytes(32, cb);
});

View file

@ -0,0 +1,72 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// This is the same as test/simple/test-crypto, but from before the shift
// to use buffers by default.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const EXTERN_APEX = 0xFBEE9;
// Manually controlled string for checking binary output
let ucs2_control = 'a\u0000';
// Grow the strings to proper length
while (ucs2_control.length <= EXTERN_APEX) {
ucs2_control = ucs2_control.repeat(2);
}
// Check resultant buffer and output string
const b = Buffer.from(ucs2_control + ucs2_control, 'ucs2');
//
// Test updating from birant data
//
{
const datum1 = b.slice(700000);
const hash1_converted = crypto.createHash('sha1')
.update(datum1.toString('base64'), 'base64')
.digest('hex');
const hash1_direct = crypto.createHash('sha1').update(datum1).digest('hex');
assert.strictEqual(hash1_direct, hash1_converted);
const datum2 = b;
const hash2_converted = crypto.createHash('sha1')
.update(datum2.toString('base64'), 'base64')
.digest('hex');
const hash2_direct = crypto.createHash('sha1').update(datum2).digest('hex');
assert.strictEqual(hash2_direct, hash2_converted);
}

View file

@ -0,0 +1,30 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// Test classic Diffie-Hellman key generation.
{
generateKeyPair('dh', {
primeLength: 512
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'dh');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'dh');
}));
}

View file

@ -0,0 +1,50 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// This test makes sure deprecated and new options may be used
// simultaneously so long as they're identical values.
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
saltLength: 16,
hash: 'sha256',
hashAlgorithm: 'sha256',
mgf1Hash: 'sha256',
mgf1HashAlgorithm: 'sha256'
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
});
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
});
}));
}

View file

@ -0,0 +1,36 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// Passing an empty passphrase string should not throw ERR_OSSL_CRYPTO_MALLOC_FAILURE even on OpenSSL 3.
// Regression test for https://github.com/nodejs/node/issues/41428.
generateKeyPair('rsa', {
modulusLength: 1024,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: ''
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert.strictEqual(typeof privateKey, 'string');
}));

View file

@ -0,0 +1,40 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPairSync,
} = require('crypto');
// Test sync key generation with key objects.
{
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
modulusLength: 512
});
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n
});
assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n
});
}

View file

@ -0,0 +1,50 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
generateKeyPairSync,
getCurves,
} = require('crypto');
// This test creates EC key pairs on curves without associated OIDs.
// Specifying a key encoding should not crash.
{
if (process.versions.openssl >= '1.1.1i') {
for (const namedCurve of ['Oakley-EC2N-3', 'Oakley-EC2N-4']) {
if (!getCurves().includes(namedCurve))
continue;
const expectedErrorCode =
common.hasOpenSSL3 ? 'ERR_OSSL_MISSING_OID' : 'ERR_OSSL_EC_MISSING_OID';
const params = {
namedCurve,
publicKeyEncoding: {
format: 'der',
type: 'spki'
}
};
assert.throws(() => {
generateKeyPairSync('ec', params);
}, {
code: expectedErrorCode
});
generateKeyPair('ec', params, common.mustCall((err) => {
assert.strictEqual(err.code, expectedErrorCode);
}));
}
}
}

View file

@ -0,0 +1,42 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPairSync,
} = require('crypto');
// Test sync key generation with key objects with a non-standard
// publicExponent
{
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
publicExponent: 3,
modulusLength: 512
});
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 3n
});
assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 3n
});
}

View file

@ -0,0 +1,39 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// RFC 8017, 9.1.: "Assuming that the mask generation function is based on a
// hash function, it is RECOMMENDED that the hash function be the same as the
// one that is applied to the message."
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha256',
saltLength: 16
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
}

View file

@ -0,0 +1,53 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// RFC 8017, A.2.3.: "For a given hashAlgorithm, the default value of
// saltLength is the octet length of the hash value."
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha512'
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha512',
mgf1HashAlgorithm: 'sha512',
saltLength: 64
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
// It is still possible to explicitly set saltLength to 0.
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha512',
saltLength: 0
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha512',
mgf1HashAlgorithm: 'sha512',
saltLength: 0
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
}

View file

@ -0,0 +1,43 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const Stream = require('stream');
const hasher1 = crypto.createHash('sha256');
const hasher2 = crypto.createHash('sha256');
// Calculate the expected result.
hasher1.write(Buffer.from('hello world'));
hasher1.end();
const expected = hasher1.read().toString('hex');
class OldStream extends Stream {
constructor() {
super();
this.readable = true;
}
}
const stream = new OldStream();
stream.pipe(hasher2).on('finish', common.mustCall(function() {
const hash = hasher2.read().toString('hex');
assert.strictEqual(hash, expected);
}));
stream.emit('data', Buffer.from('hello'));
stream.emit('data', Buffer.from(' world'));
stream.emit('end');

View file

@ -0,0 +1,45 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasOpenSSL3)
common.skip('this test requires OpenSSL 3.x');
const assert = require('node:assert/strict');
const crypto = require('node:crypto');
if (common.isMainThread) {
// TODO(richardlau): Decide if `crypto.setFips` should error if the
// provider named "fips" is not available.
crypto.setFips(1);
crypto.randomBytes(20, common.mustCall((err) => {
// crypto.randomBytes should either succeed or fail but not hang.
if (err) {
assert.match(err.message, /digital envelope routines::unsupported/);
const expected = /random number generator::unable to fetch drbg/;
assert(err.opensslErrorStack.some((msg) => expected.test(msg)),
`did not find ${expected} in ${err.opensslErrorStack}`);
}
}));
}
{
// Startup test. Should not hang.
const { path } = require('../common/fixtures');
const { spawnSync } = require('node:child_process');
const baseConf = path('openssl3-conf', 'base_only.cnf');
const cp = spawnSync(process.execPath,
[ `--openssl-config=${baseConf}`, '-p', '"hello"' ],
{ encoding: 'utf8' });
assert(common.nodeProcessAborted(cp.status, cp.signal),
`process did not abort, code:${cp.status} signal:${cp.signal}`);
}

View file

@ -0,0 +1,35 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const assert = require('assert');
const { generateKeyPair } = require('crypto');
if (common.isWindows) {
// Remove this conditional once the libuv change is in Node.js.
common.skip('crashing due to https://github.com/libuv/libuv/pull/2983');
}
// Regression test for a race condition: process.exit() might lead to OpenSSL
// cleaning up state from the exit() call via calling its destructor, but
// running OpenSSL operations on another thread might lead to them attempting
// to initialize OpenSSL, leading to a crash.
// This test crashed consistently on x64 Linux on Node v14.9.0.
generateKeyPair('rsa', {
modulusLength: 2048,
privateKeyEncoding: {
type: 'pkcs1',
format: 'pem'
}
}, (err/* , publicKey, privateKey */) => {
assert.ifError(err);
});
setTimeout(() => process.exit(), common.platformTimeout(10));

View file

@ -0,0 +1,67 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const iv = Buffer.from('00000000000000000000000000000000', 'hex');
const key = Buffer.from('0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef', 'hex');
function encrypt(val, pad) {
const c = crypto.createCipheriv('aes256', key, iv);
c.setAutoPadding(pad);
return c.update(val, 'utf8', 'latin1') + c.final('latin1');
}
function decrypt(val, pad) {
const c = crypto.createDecipheriv('aes256', key, iv);
c.setAutoPadding(pad);
return c.update(val, 'latin1', 'utf8') + c.final('utf8');
}
// echo 0123456789abcdef0123456789abcdef \
// | openssl enc -e -aes256 -nopad -K <key> -iv <iv> \
// | openssl enc -d -aes256 -nopad -K <key> -iv <iv>
let plaintext = '0123456789abcdef0123456789abcdef'; // Multiple of block size
let encrypted = encrypt(plaintext, false);
let decrypted = decrypt(encrypted, false);
assert.strictEqual(decrypted, plaintext);
// echo 0123456789abcdef0123456789abcde \
// | openssl enc -e -aes256 -K <key> -iv <iv> \
// | openssl enc -d -aes256 -K <key> -iv <iv>
plaintext = '0123456789abcdef0123456789abcde'; // not a multiple
encrypted = encrypt(plaintext, true);
decrypted = decrypt(encrypted, true);
assert.strictEqual(decrypted, plaintext);

View file

@ -0,0 +1,107 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
// Tests for CVE-2022-21449
// https://neilmadden.blog/2022/04/19/psychic-signatures-in-java/
// Dubbed "Psychic Signatures", these signatures bypassed the ECDSA signature
// verification implementation in Java in 15, 16, 17, and 18. OpenSSL is not
// (and was not) vulnerable so these are a precaution.
const vectors = {
'ieee-p1363': [
Buffer.from('0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
Buffer.from('ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 'hex'),
],
'der': [
Buffer.from('3046022100' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'022100' +
'0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
Buffer.from('3046022100' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551' +
'022100' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 'hex'),
],
};
const keyPair = crypto.generateKeyPairSync('ec', {
namedCurve: 'P-256',
publicKeyEncoding: {
format: 'der',
type: 'spki'
},
});
const data = Buffer.from('Hello!');
for (const [encoding, signatures] of Object.entries(vectors)) {
for (const signature of signatures) {
const key = {
key: keyPair.publicKey,
format: 'der',
type: 'spki',
dsaEncoding: encoding,
};
// one-shot sync
assert.strictEqual(
crypto.verify(
'sha256',
data,
key,
signature,
),
false,
);
// one-shot async
crypto.verify(
'sha256',
data,
key,
signature,
common.mustSucceed((verified) => assert.strictEqual(verified, false)),
);
// stream
assert.strictEqual(
crypto.createVerify('sha256')
.update(data)
.verify(key, signature),
false,
);
// webcrypto
globalThis.crypto.subtle.importKey(
'spki',
keyPair.publicKey,
{ name: 'ECDSA', namedCurve: 'P-256' },
false,
['verify'],
).then((publicKey) => {
return globalThis.crypto.subtle.verify(
{ name: 'ECDSA', hash: 'SHA-256' },
publicKey,
signature,
data,
);
}).then(common.mustCall((verified) => {
assert.strictEqual(verified, false);
}));
}
}

View file

@ -0,0 +1,48 @@
// 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.
'use strict';
const common = require('../common');
// Test for https://github.com/nodejs/node/issues/40814
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasOpenSSL3)
common.skip('only openssl3'); // https://github.com/nodejs/node/pull/42793#issuecomment-1107491901
const assert = require('assert');
const crypto = require('crypto');
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-128-ecb',
passphrase: 'abcdef'
}
});
assert.notStrictEqual(privateKey.toString(), '');
const msg = 'The quick brown fox jumps over the lazy dog';
const encryptedString = crypto.privateEncrypt({
key: privateKey,
passphrase: 'abcdef'
}, Buffer.from(msg)).toString('base64');
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, 'base64')).toString();
console.log(`Encrypted: ${encryptedString}`);
console.log(`Decrypted: ${decryptedString}`);
assert.notStrictEqual(encryptedString, '');
assert.strictEqual(decryptedString, msg);

View file

@ -0,0 +1,25 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const { randomFillSync } = require('crypto');
const { notStrictEqual } = require('assert');
const ab = new ArrayBuffer(20);
const buf = Buffer.from(ab, 10);
const before = buf.toString('hex');
randomFillSync(buf);
const after = buf.toString('hex');
notStrictEqual(before, after);

View file

@ -0,0 +1,266 @@
// 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.
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const { internalBinding } = require('internal/test/binding');
if (typeof internalBinding('crypto').ScryptJob !== 'function')
common.skip('no scrypt support');
const good = [
// Zero-length key is legal, functions as a parameter validation check.
{
pass: '',
salt: '',
keylen: 0,
N: 16,
p: 1,
r: 1,
expected: '',
},
// Test vectors from https://tools.ietf.org/html/rfc7914#page-13 that
// should pass. Note that the test vector with N=1048576 is omitted
// because it takes too long to complete and uses over 1 GiB of memory.
{
pass: '',
salt: '',
keylen: 64,
N: 16,
p: 1,
r: 1,
expected:
'77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442' +
'fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906',
},
{
pass: 'password',
salt: 'NaCl',
keylen: 64,
N: 1024,
p: 16,
r: 8,
expected:
'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
'2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640',
},
{
pass: 'pleaseletmein',
salt: 'SodiumChloride',
keylen: 64,
N: 16384,
p: 1,
r: 8,
expected:
'7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2' +
'd5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887',
},
{
pass: '',
salt: '',
keylen: 64,
cost: 16,
parallelization: 1,
blockSize: 1,
expected:
'77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442' +
'fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906',
},
{
pass: 'password',
salt: 'NaCl',
keylen: 64,
cost: 1024,
parallelization: 16,
blockSize: 8,
expected:
'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
'2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640',
},
{
pass: 'pleaseletmein',
salt: 'SodiumChloride',
keylen: 64,
cost: 16384,
parallelization: 1,
blockSize: 8,
expected:
'7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2' +
'd5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887',
},
];
// Test vectors that should fail.
const bad = [
{ N: 1, p: 1, r: 1 }, // N < 2
{ N: 3, p: 1, r: 1 }, // Not power of 2.
{ N: 1, cost: 1 }, // Both N and cost
{ p: 1, parallelization: 1 }, // Both p and parallelization
{ r: 1, blockSize: 1 }, // Both r and blocksize
];
// Test vectors where 128*N*r exceeds maxmem.
const toobig = [
{ N: 2 ** 16, p: 1, r: 1 }, // N >= 2**(r*16)
{ N: 2, p: 2 ** 30, r: 1 }, // p > (2**30-1)/r
{ N: 2 ** 20, p: 1, r: 8 },
{ N: 2 ** 10, p: 1, r: 8, maxmem: 2 ** 20 },
];
const badargs = [
{
args: [],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"password"/ },
},
{
args: [null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"password"/ },
},
{
args: [''],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"salt"/ },
},
{
args: ['', null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"salt"/ },
},
{
args: ['', ''],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"keylen"/ },
},
{
args: ['', '', null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"keylen"/ },
},
{
args: ['', '', .42],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', -42],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2 ** 31],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2147485780],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2 ** 32],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
];
for (const options of good) {
const { pass, salt, keylen, expected } = options;
const actual = crypto.scryptSync(pass, salt, keylen, options);
assert.strictEqual(actual.toString('hex'), expected);
crypto.scrypt(pass, salt, keylen, options, common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), expected);
}));
}
for (const options of bad) {
const expected = {
message: /Invalid scrypt param/,
};
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
expected);
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
expected);
}
for (const options of toobig) {
const expected = {
message: /Invalid scrypt param/
};
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
expected);
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
expected);
}
{
const defaults = { N: 16384, p: 1, r: 8 };
const expected = crypto.scryptSync('pass', 'salt', 1, defaults);
const actual = crypto.scryptSync('pass', 'salt', 1);
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
crypto.scrypt('pass', 'salt', 1, common.mustSucceed((actual) => {
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
}));
}
for (const { args, expected } of badargs) {
assert.throws(() => crypto.scrypt(...args), expected);
assert.throws(() => crypto.scryptSync(...args), expected);
}
{
const expected = { code: 'ERR_INVALID_ARG_TYPE' };
assert.throws(() => crypto.scrypt('', '', 42, null), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}, null), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}, {}), expected);
}
{
// Values for maxmem that do not fit in 32 bits but that are still safe
// integers should be allowed.
crypto.scrypt('', '', 4, { maxmem: 2 ** 52 },
common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), 'd72c87d0');
}));
// Values that exceed Number.isSafeInteger should not be allowed.
assert.throws(() => crypto.scryptSync('', '', 0, { maxmem: 2 ** 53 }), {
code: 'ERR_OUT_OF_RANGE'
});
}
{
// Regression test for https://github.com/nodejs/node/issues/28836.
function testParameter(name, value) {
let accessCount = 0;
// Find out how often the value is accessed.
crypto.scryptSync('', '', 1, {
get [name]() {
accessCount++;
return value;
}
});
// Try to crash the process on the last access.
assert.throws(() => {
crypto.scryptSync('', '', 1, {
get [name]() {
if (--accessCount === 0)
return '';
return value;
}
});
}, {
code: 'ERR_INVALID_ARG_TYPE'
});
}
[
['N', 16384], ['cost', 16384],
['r', 8], ['blockSize', 8],
['p', 1], ['parallelization', 1],
].forEach((arg) => testParameter(...arg));
}

View file

@ -0,0 +1,46 @@
// 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.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { subtle } = globalThis.crypto;
(async () => {
const k = await subtle.importKey(
'raw',
new Uint8Array(32),
{ name: 'AES-GCM' },
false,
[ 'encrypt', 'decrypt' ]);
assert(k instanceof CryptoKey);
const e = await subtle.encrypt({
name: 'AES-GCM',
iv: new Uint8Array(12),
}, k, new Uint8Array(0));
assert(e instanceof ArrayBuffer);
assert.deepStrictEqual(
Buffer.from(e),
Buffer.from([
0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b ]));
const v = await subtle.decrypt({
name: 'AES-GCM',
iv: new Uint8Array(12),
}, k, e);
assert(v instanceof ArrayBuffer);
assert.strictEqual(v.byteLength, 0);
})().then(common.mustCall()).catch((e) => {
assert.ifError(e);
});

View file

@ -0,0 +1,88 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
{
// IPv4 Test
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, common.localhostIPv4);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv4');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
});
socket.bind(0, common.localhostIPv4);
}
if (common.hasIPv6) {
// IPv6 Test
const socket = dgram.createSocket('udp6');
const localhost = '::1';
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, localhost);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv6');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
});
socket.bind(0, localhost);
}
{
// Verify that address() throws if the socket is not bound.
const socket = dgram.createSocket('udp4');
assert.throws(() => {
socket.address();
}, /^Error: getsockname EBADF$/);
}

View file

@ -0,0 +1,60 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
// Skip test in FreeBSD jails since 0.0.0.0 will resolve to default interface
if (common.inFreeBSDJail)
common.skip('In a FreeBSD jail');
const assert = require('assert');
const dgram = require('dgram');
dgram.createSocket('udp4').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
assert.strictEqual(this.address().address, '0.0.0.0');
this.close();
}));
if (!common.hasIPv6) {
common.printSkipMessage('udp6 part of test, because no IPv6 support');
return;
}
dgram.createSocket('udp6').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
let address = this.address().address;
if (address === '::ffff:0.0.0.0')
address = '::';
assert.strictEqual(address, '::');
this.close();
}));

View file

@ -0,0 +1,34 @@
// 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.
'use strict';
const common = require('../common');
const dgram = require('dgram');
// Regression test for https://github.com/nodejs/node/issues/30209
// No warning should be emitted when re-trying `.bind()` on UDP sockets
// repeatedly.
process.on('warning', common.mustNotCall());
const reservePortSocket = dgram.createSocket('udp4');
reservePortSocket.bind(() => {
const { port } = reservePortSocket.address();
const newSocket = dgram.createSocket('udp4');
let errors = 0;
newSocket.on('error', common.mustCall(() => {
if (++errors < 20) {
newSocket.bind(port, common.mustNotCall());
} else {
newSocket.close();
reservePortSocket.close();
}
}, 20));
newSocket.bind(port, common.mustNotCall());
});

View file

@ -0,0 +1,50 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
assert.throws(() => {
socket.bind();
}, {
code: 'ERR_SOCKET_ALREADY_BOUND',
name: 'Error',
message: /^Socket is already bound$/
});
socket.close();
}));
const result = socket.bind(); // Should not throw.
assert.strictEqual(result, socket); // Should have returned itself.

View file

@ -0,0 +1,46 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('assert');
const dgram = require('dgram');
const message = Buffer.from('Some bytes');
const client = dgram.createSocket('udp4');
client.send(
message,
0,
message.length,
41234,
'localhost',
function(err, bytes) {
assert.strictEqual(bytes, message.length);
client.close();
}
);

View file

@ -0,0 +1,33 @@
// 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.
'use strict';
// Ensure that if a dgram socket is closed before the sendQueue is drained
// will not crash
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
socket.on('listening', function() {
socket.close();
});
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
// Adds a listener to 'listening' to send the data when
// the socket is available
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
portGetter.close();
}));

View file

@ -0,0 +1,28 @@
// 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.
'use strict';
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
// If close callback is not function, ignore the argument.
socket.close('bad argument');
portGetter.close();
socket.on('close', common.mustCall());
}));

View file

@ -0,0 +1,63 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Flags: --expose-internals
'use strict';
// Ensure that if a dgram socket is closed before the DNS lookup completes, it
// won't crash.
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { kStateSymbol } = require('internal/dgram');
const buf = Buffer.alloc(1024, 42);
let socket = dgram.createSocket('udp4');
const { handle } = socket[kStateSymbol];
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
assert.strictEqual(socket.close(common.mustCall()), socket);
socket.on('close', common.mustCall());
socket = null;
// Verify that accessing handle after closure doesn't throw
setImmediate(function() {
setImmediate(function() {
console.log('Handle fd is: ', handle.fd);
});
});
portGetter.close();
}));

View file

@ -0,0 +1,30 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, offset, len, messageSent);
}));
}));

View file

@ -0,0 +1,27 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, onMessage);
}));
}));

View file

@ -0,0 +1,36 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustCall((err, bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.connect(port, common.mustCall(() => {
client.send([buf1, buf2], messageSent);
}));
}));
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -0,0 +1,55 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const server = dgram.createSocket('udp4');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
server.on('listening', common.mustCall(() => {
const port = server.address().port;
client.connect(port, (err) => {
assert.ifError(err);
client.send(toSend[0], 0, toSend[0].length);
client.send(toSend[1]);
client.send([toSend[2]]);
client.send(toSend[3], 0, toSend[3].length);
client.send(new Uint8Array(toSend[0]), 0, toSend[0].length);
client.send(new Uint8Array(toSend[1]));
client.send([new Uint8Array(toSend[2])]);
client.send(new Uint8Array(Buffer.from(toSend[3])),
0, toSend[3].length);
});
}));
server.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
if (received.length === toSend.length * 2) {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const expected = toSend.concat(toSend).map(String).sort();
assert.deepStrictEqual(received, expected);
client.close();
server.close();
}
}, toSend.length * 2));
server.bind(0);

View file

@ -0,0 +1,29 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.alloc(0);
assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`);
client.close();
}));
client.on('listening', common.mustCall(() => {
client.connect(client.address().port,
common.localhostIPv4,
common.mustCall(() => client.send([])));
}));
client.bind(0);

View file

@ -0,0 +1,27 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
const port = this.address().port;
client.connect(port, common.mustCall(() => {
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.mustSucceed());
}));
client.on('message', common.mustCall((buffer) => {
assert.strictEqual(buffer.length, 0);
client.close();
}));
}));

View file

@ -0,0 +1,35 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
client.connect(client.address().port, common.mustCall(() => {
client.on('message', common.mustCall(callback));
const buf = Buffer.alloc(1);
const interval = setInterval(function() {
client.send(buf, 0, 0, common.mustCall(callback));
}, 10);
function callback(firstArg) {
// If client.send() callback, firstArg should be null.
// If client.on('message') listener, firstArg should be a 0-length buffer.
if (firstArg instanceof Buffer) {
assert.strictEqual(firstArg.length, 0);
clearInterval(interval);
client.close();
}
}
}));
}));

View file

@ -0,0 +1,36 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const onMessage = common.mustCall(common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
}));
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(function() {
const toSend = [buf1, buf2];
client.connect(client.address().port, common.mustCall(() => {
client.send(toSend, onMessage);
}));
}));
client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -0,0 +1,24 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const data = ['foo', 'bar', 'baz'];
socket.on('message', common.mustCall((msg, rinfo) => {
socket.close();
assert.deepStrictEqual(msg.toString(), data.join(''));
}));
socket.bind(0, () => {
socket.connect(socket.address().port, common.mustCall(() => {
socket.send(data);
}));
});

View file

@ -0,0 +1,73 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const PORT = 12345;
const client = dgram.createSocket('udp4');
client.connect(PORT, common.mustCall(() => {
const remoteAddr = client.remoteAddress();
assert.strictEqual(remoteAddr.port, PORT);
assert.throws(() => {
client.connect(PORT, common.mustNotCall());
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
client.disconnect();
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
assert.throws(() => {
client.remoteAddress();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
client.once('connect', common.mustCall(() => client.close()));
client.connect(PORT);
}));
assert.throws(() => {
client.connect(PORT);
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
[ 0, null, 78960, undefined ].forEach((port) => {
assert.throws(() => {
client.connect(port);
}, {
name: 'RangeError',
message: /^Port should be > 0 and < 65536/,
code: 'ERR_SOCKET_BAD_PORT'
});
});

View file

@ -0,0 +1,68 @@
// 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.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const invalidTypes = [
'test',
['udp4'],
new String('udp4'),
1,
{},
true,
false,
null,
undefined,
];
const validTypes = [
'udp4',
'udp6',
{ type: 'udp4' },
{ type: 'udp6' },
];
const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/;
// Error must be thrown with invalid types
invalidTypes.forEach((invalidType) => {
assert.throws(() => {
dgram.createSocket(invalidType);
}, {
code: 'ERR_SOCKET_BAD_TYPE',
name: 'TypeError',
message: errMessage
});
});
// Error must not be thrown with valid types
validTypes.forEach((validType) => {
const socket = dgram.createSocket(validType);
socket.close();
});
// Ensure buffer sizes can be set
{
const socket = dgram.createSocket({
type: 'udp4',
recvBufferSize: 10000,
sendBufferSize: 15000
});
socket.bind(common.mustCall(() => {
// note: linux will double the buffer size
assert.ok(socket.getRecvBufferSize() === 10000 ||
socket.getRecvBufferSize() === 20000,
'SO_RCVBUF not 10000 or 20000, ' +
`was ${socket.getRecvBufferSize()}`);
assert.ok(socket.getSendBufferSize() === 15000 ||
socket.getSendBufferSize() === 30000,
'SO_SNDBUF not 15000 or 30000, ' +
`was ${socket.getRecvBufferSize()}`);
socket.close();
}));
}

View file

@ -0,0 +1,64 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
// IPv4 Test
const socket_ipv4 = dgram.createSocket('udp4');
socket_ipv4.on('listening', common.mustNotCall());
socket_ipv4.on('error', common.mustCall(function(e) {
assert.strictEqual(e.port, undefined);
assert.strictEqual(e.message, 'bind EADDRNOTAVAIL 1.1.1.1');
assert.strictEqual(e.address, '1.1.1.1');
assert.strictEqual(e.code, 'EADDRNOTAVAIL');
socket_ipv4.close();
}));
socket_ipv4.bind(0, '1.1.1.1');
// IPv6 Test
const socket_ipv6 = dgram.createSocket('udp6');
socket_ipv6.on('listening', common.mustNotCall());
socket_ipv6.on('error', common.mustCall(function(e) {
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
assert(allowed.includes(e.code), `'${e.code}' was not one of ${allowed}.`);
assert.strictEqual(e.port, undefined);
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
assert.strictEqual(e.address, '111::1');
socket_ipv6.close();
}));
socket_ipv6.bind(0, '111::1');

View file

@ -0,0 +1,53 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const dgram = require('dgram');
const source = dgram.createSocket('udp4');
const target = dgram.createSocket('udp4');
let messages = 0;
target.on('message', common.mustCall(function(buf) {
if (buf.toString() === 'abc') ++messages;
if (buf.toString() === 'def') ++messages;
if (messages === 2) {
source.close();
target.close();
}
}, 2));
target.on('listening', common.mustCall(function() {
// Second .send() call should not throw a bind error.
const port = this.address().port;
source.send(Buffer.from('abc'), 0, 3, port, '127.0.0.1');
source.send(Buffer.from('def'), 0, 3, port, '127.0.0.1');
}));
target.bind(0);

View file

@ -0,0 +1,52 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.bind();
let fired = false;
const timer = setTimeout(() => {
socket.close();
}, 100);
socket.on('listening', common.mustCall(() => {
clearTimeout(timer);
fired = true;
socket.close();
}));
socket.on('close', common.mustCall(() => {
assert(fired, 'listening should fire after bind');
}));

View file

@ -0,0 +1,46 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
// Send a too big datagram. The destination doesn't matter because it's
// not supposed to get sent out anyway.
const buf = Buffer.allocUnsafe(256 * 1024);
const sock = dgram.createSocket('udp4');
sock.send(buf, 0, buf.length, 12345, '127.0.0.1', common.mustCall(cb));
function cb(err) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'EMSGSIZE');
assert.strictEqual(err.address, '127.0.0.1');
assert.strictEqual(err.port, 12345);
assert.strictEqual(err.message, 'send EMSGSIZE 127.0.0.1:12345');
sock.close();
}

View file

@ -0,0 +1,52 @@
// 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.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// Some operating systems report errors when an UDP message is sent to an
// unreachable host. This error can be reported by sendto() and even by
// recvfrom(). Node should not propagate this error to the user.
const common = require('../common');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const buf = Buffer.from([1, 2, 3, 4]);
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
const { address, port } = portGetter.address();
portGetter.close(common.mustCall(() => {
socket.send(buf, 0, 0, port, address, common.mustNotCall());
socket.send(buf, 0, 4, port, address, common.mustNotCall());
socket.send(buf, 1, 3, port, address, common.mustNotCall());
socket.send(buf, 3, 1, port, address, common.mustNotCall());
// Since length of zero means nothing, don't error despite OOB.
socket.send(buf, 4, 0, port, address, common.mustNotCall());
socket.close();
}));
}));

View file

@ -0,0 +1,26 @@
// 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.
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { kStateSymbol } = require('internal/dgram');
const s = dgram.createSocket('udp4');
const { handle } = s[kStateSymbol];
s.on('error', common.mustCall((err) => {
s.close();
// Don't check the full error message, as the errno is not important here.
assert.match(String(err), /^Error: recvmsg/);
assert.strictEqual(err.syscall, 'recvmsg');
}));
s.on('message', common.mustNotCall('no message should be received.'));
s.bind(common.mustCall(() => handle.onmessage(-1, handle, null, null)));

Some files were not shown because too many files have changed in this diff Show more