deno/tests/napi/init_test.js
snek 0d838faf17
Some checks failed
ci / pre-build (push) Has been cancelled
ci / test debug windows-x86_64 (push) Has been cancelled
ci / test release windows-x86_64 (push) Has been cancelled
ci / test debug linux-aarch64 (push) Has been cancelled
ci / test release linux-aarch64 (push) Has been cancelled
ci / test debug macos-aarch64 (push) Has been cancelled
ci / test release macos-aarch64 (push) Has been cancelled
ci / bench release linux-x86_64 (push) Has been cancelled
ci / test debug linux-x86_64 (push) Has been cancelled
ci / test release linux-x86_64 (push) Has been cancelled
ci / test debug macos-x86_64 (push) Has been cancelled
ci / test release macos-x86_64 (push) Has been cancelled
ci / lint debug linux-x86_64 (push) Has been cancelled
ci / lint debug macos-x86_64 (push) Has been cancelled
ci / lint debug windows-x86_64 (push) Has been cancelled
ci / build libs (push) Has been cancelled
ci / publish canary (push) Has been cancelled
fix(ext/napi): suppress deprecated Buffer warnings (#31245)
2025-11-11 15:02:29 +09:00

50 lines
1.5 KiB
JavaScript

// Copyright 2018-2025 the Deno authors. MIT license.
import { Buffer } from "node:buffer";
import { assert, libSuffix } from "./common.js";
import { Worker } from "node:worker_threads";
const ops = Deno[Deno.internal].core.ops;
Deno.test("ctr initialization (napi_module_register)", {
ignore: Deno.build.os == "windows",
}, function () {
const path = new URL(`./module.${libSuffix}`, import.meta.url).pathname;
const obj = ops.op_napi_open(path, {}, Buffer.from, reportError);
assert(obj != null);
assert(typeof obj === "object");
});
Deno.test("ctr initialization by multiple threads (napi_module_register)", {
ignore: Deno.build.os == "windows",
}, async function () {
const path = new URL(`./module.${libSuffix}`, import.meta.url).pathname;
const obj = ops.op_napi_open(path, {}, Buffer.from, reportError);
const common = import.meta.resolve("./common.js");
assert(obj != null);
assert(typeof obj === "object");
const worker = new Worker(
`
import { Buffer } from "node:buffer";
import { parentPort } from "node:worker_threads";
import { assert } from "${common}";
const ops = Deno[Deno.internal].core.ops;
const obj = ops.op_napi_open("${path}", {}, Buffer.from, reportError);
assert(obj != null);
assert(typeof obj === "object");
parentPort.postMessage("ok");
`,
{
eval: true,
},
);
const p = Promise.withResolvers();
worker.on("message", (_m) => {
p.resolve();
});
await p.promise;
});