Skip to content

Commit

Permalink
chore: move test_ffi and test_nap to tests/ [WIP] (#22394)
Browse files Browse the repository at this point in the history
Moving some additional NAPI and. FFI tests out of the tree root.
  • Loading branch information
mmastrac authored Feb 12, 2024
1 parent bd1358e commit f607200
Show file tree
Hide file tree
Showing 71 changed files with 66 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 45,7 @@
"cli/tsc/*typescript.js",
"gh-pages",
"target",
"test_ffi/tests/test.js",
"tests/ffi/tests/test.js",
"test_util/std",
"test_util/wpt",
"third_party",
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 12,9 @@ gclient_config.py_entries
/std/hash/_wasm/target
/tools/wpt/manifest.json
/third_party/
/test_napi/node_modules
/test_napi/build
/test_napi/third_party_tests/node_modules
/tests/napi/node_modules
/tests/napi/build
/tests/napi/third_party_tests/node_modules

# MacOS generated files
.DS_Store
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 28,10 @@ members = [
"ext/websocket",
"ext/webstorage",
"runtime",
"test_ffi",
"test_napi",
"test_util",
"tests",
"tests/ffi",
"tests/napi",
]
exclude = ["test_util/std/hash/_wasm"]

Expand Down
2 changes: 1 addition & 1 deletion cli/bench/napi/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { loadTestLibrary } from "../../../test_napi/common.js";
import { loadTestLibrary } from "../../../tests/napi/common.js";

const lib = loadTestLibrary();

Expand Down
2 changes: 1 addition & 1 deletion cli/bench/napi/bench_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ import { bench, run } from "mitata";
import { createRequire } from "module";

const require = createRequire(import.meta.url);
const lib = require("../../../test_napi.node");
const lib = require("../../../tests/napi.node");

bench("warmup", () => {});
bench("napi_get_undefined", () => lib.test_get_undefined(0));
Expand Down
10 changes: 5 additions & 5 deletions cli/napi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 50,11 @@ Update the generated symbol lists using the script:
deno run --allow-write tools/napi/generate_symbols_lists.js
```

Add a test in [`/test_napi`](../../test_napi/). You can also refer to Node.js
Add a test in [`/tests/napi`](../../tests/napi/). You can also refer to Node.js
test suite for Node-API.

```js
// test_napi/boolean_test.js
// tests/napi/boolean_test.js
import { assertEquals, loadTestLibrary } from "./common.js";
const lib = loadTestLibrary();
Deno.test("napi get boolean", function () {
Expand All @@ -64,7 64,7 @@ Deno.test("napi get boolean", function () {
```

```rust
// test_napi/src/boolean.rs
// tests/napi/src/boolean.rs

use napi_sys::Status::napi_ok;
use napi_sys::ValueType::napi_boolean;
Expand Down Expand Up @@ -96,7 96,7 @@ pub fn init(env: napi_env, exports: napi_value) {
```

```diff
// test_napi/src/lib.rs
// tests/napi/src/lib.rs

mod boolean;

Expand All @@ -114,4 114,4 @@ unsafe extern "C" fn napi_register_module_v1(
}
```

Run the test using `cargo test -p test_napi`.
Run the test using `cargo test -p tests/napi`.
2 changes: 1 addition & 1 deletion ext/ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 21,5 @@ MacOS.
To run benchmarks:

```bash
target/release/deno bench --allow-ffi --allow-read --unstable-ffi ./test_ffi/tests/bench.js
target/release/deno bench --allow-ffi --allow-read --unstable-ffi ./tests/ffi/tests/bench.js
```
10 changes: 9 additions & 1 deletion test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 87,16 @@ pub fn third_party_path() -> PathRef {
root_path().join("third_party")
}

pub fn ffi_tests_path() -> PathRef {
root_path().join("tests").join("ffi")
}

pub fn napi_tests_path() -> PathRef {
root_path().join("test_napi")
root_path().join("tests").join("napi")
}

pub fn deno_config_path() -> PathRef {
root_path().join("tests").join("config").join("deno.json")
}

/// Test server registry url.
Expand Down
3 changes: 2 additions & 1 deletion tests/config/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
{
"imports": {
"@test_util/": "../../test_util/"
"@test_util/": "../../test_util/",
"@std/": "../../test_util/std/"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,8 @@
use pretty_assertions::assert_eq;
use std::process::Command;
use test_util::deno_cmd;
use test_util::deno_config_path;
use test_util::ffi_tests_path;

#[cfg(debug_assertions)]
const BUILD_VARIANT: &str = "debug";
Expand All @@ -26,7 28,11 @@ fn basic() {
build();

let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi")
.arg("--allow-read")
.arg("--unstable-ffi")
Expand Down Expand Up @@ -134,7 140,11 @@ fn symbol_types() {
build();

let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("check")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--unstable-ffi")
.arg("--quiet")
.arg("tests/ffi_types.ts")
Expand All @@ -157,7 167,11 @@ fn thread_safe_callback() {
build();

let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi")
.arg("--allow-read")
.arg("--unstable-ffi")
Expand Down Expand Up @@ -191,7 205,11 @@ fn event_loop_integration() {
build();

let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi")
.arg("--allow-read")
.arg("--unstable-ffi")
Expand Down Expand Up @@ -243,7 261,11 @@ fn ffi_callback_errors_test() {
build();

let output = deno_cmd()
.current_dir(ffi_tests_path())
.arg("run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--allow-ffi")
.arg("--allow-read")
.arg("--unstable-ffi")
Expand Down
2 changes: 1 addition & 1 deletion test_ffi/tests/test.js → tests/ffi/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ import {
assertInstanceOf,
assertEquals,
assertFalse,
} from "../../test_util/std/assert/mod.ts";
} from "@std/assert/mod.ts";

const targetDir = Deno.execPath().replace(/[^\/\\] $/, "");
const [libPrefix, libSuffix] = {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/integration/js_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 120,7 @@ fn js_unit_test(test: String) {
.current_dir(util::root_path())
.arg("test")
.arg("--config")
.arg("tests/config/deno.json")
.arg(util::deno_config_path())
.arg("--no-lock")
.arg("--unstable")
.arg("--location=http://127.0.0.1:4545/")
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/node_compat_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use test_util as util;
use util::deno_config_path;
use util::env_vars_for_npm_tests;

#[test]
Expand All @@ -9,7 10,7 @@ fn node_compat_tests() {
.current_dir(util::root_path())
.arg("test")
.arg("--config")
.arg("tests/config/deno.json")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--unstable")
.arg("-A")
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/node_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@ use std::io::BufReader;
use std::time::Duration;
use std::time::Instant;
use test_util as util;
use util::deno_config_path;
use util::env_vars_for_npm_tests;

util::unit_test_factory!(
Expand Down Expand Up @@ -97,7 98,7 @@ fn node_unit_test(test: String) {
.current_dir(util::root_path())
.arg("test")
.arg("--config")
.arg("tests/config/deno.json")
.arg(deno_config_path())
.arg("--no-lock")
.arg("--unstable")
// TODO(kt3k): This option is required to pass tls_test.ts,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,9 @@ if (import.meta.main) {
const { stdout, stderr, code } = await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--config",
Deno.realPathSync("../config/deno.json"),
"--no-lock",
"--allow-read",
"--allow-run",
"--allow-ffi",
Expand All @@ -20,8 23,8 @@ if (import.meta.main) {
],
}).output();

assertEquals(code, 0);
assertEquals(new TextDecoder().decode(stderr), "");
assertEquals(code, 0);

const stdoutText = new TextDecoder().decode(stdout);
const stdoutLines = stdoutText.split("\n");
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test_napi/common.js → tests/napi/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 5,8 @@ export {
assertEquals,
assertRejects,
assertThrows,
} from "../test_util/std/assert/mod.ts";
export { fromFileUrl } from "../test_util/std/path/mod.ts";
} from "@std/assert/mod.ts";
export { fromFileUrl } from "@std/path/mod.ts";
import process from "node:process";

const targetDir = Deno.execPath().replace(/[^\/\\] $/, "");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 2,10 @@

use std::process::Command;
use test_util::deno_cmd;
use test_util::deno_config_path;
use test_util::env_vars_for_npm_tests;
use test_util::http_server;
use test_util::napi_tests_path;

#[cfg(debug_assertions)]
const BUILD_VARIANT: &str = "debug";
Expand Down Expand Up @@ -57,13 59,17 @@ fn napi_tests() {

let _http_guard = http_server();
let output = deno_cmd()
.current_dir(test_util::napi_tests_path())
.current_dir(napi_tests_path())
.env("RUST_BACKTRACE", "1")
.arg("test")
.arg("--allow-read")
.arg("--allow-env")
.arg("--allow-ffi")
.arg("--allow-run")
.arg("--config")
.arg(deno_config_path())
.arg("--no-lock")
.arg(".")
.envs(env_vars_for_npm_tests())
.spawn()
.unwrap()
Expand Down
File renamed without changes.

0 comments on commit f607200

Please sign in to comment.