Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[OV JS] Fix test async method (#34610)

Kirill Suvorov33dc88935cdb
diff --git a/src/bindings/js/node/tests/unit/async_infer_queue.test.js b/src/bindings/js/node/tests/unit/async_infer_queue.test.js
index c0171f18203..4646292251d 100644
--- a/src/bindings/js/node/tests/unit/async_infer_queue.test.js
+++ b/src/bindings/js/node/tests/unit/async_infer_queue.test.js
@@ -75,9 +75,10 @@ describe("Tests for AsyncInferQueue.", () => {
const inferQueue = new ov.AsyncInferQueue(compiledModel, numRequest);
const img = generateImage();
- await assert.rejects(async () => {
- await inferQueue.startAsync({ data: img }, "user_data");
- }, /Callback has to be set before starting inference./);
+ await assert.rejects(
+ async () => await inferQueue.startAsync({ data: img }, "user_data"),
+ /Callback has to be set before starting inference./,
+ );
});
it("Test startAsync without user data", async () => {
@@ -156,9 +157,10 @@ describe("Tests for AsyncInferQueue.", () => {
const inferQueue = new ov.AsyncInferQueue(compiledModel, numRequest);
inferQueue.setCallback(basicUserCallback);
inferQueue.release();
- await assert.rejects(async () => {
- await inferQueue.startAsync({ data: generateImage() }, "user_data");
- }, /Callback has to be set before starting inference./);
+ await assert.rejects(
+ async () => await inferQueue.startAsync({ data: generateImage() }, "user_data"),
+ /Callback has to be set before starting inference./,
+ );
});
it("Test setCallback throws and list possible signatures", async () => {
diff --git a/src/bindings/js/node/tests/unit/basic.test.js b/src/bindings/js/node/tests/unit/basic.test.js
index ef4f17bb69f..4a263cf19a7 100644
--- a/src/bindings/js/node/tests/unit/basic.test.js
+++ b/src/bindings/js/node/tests/unit/basic.test.js
@@ -183,10 +183,9 @@ describe("ov basic tests.", { skip: true }, () => {
describe("Core.compileModel()", () => {
const tput = { PERFORMANCE_HINT: "THROUGHPUT" };
- it("compileModel(model:Model, deviceName: string, config: {}) ", () => {
- core.compileModel(model, "CPU", tput).then((cm) => {
- assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
- });
+ it("compileModel(model:Model, deviceName: string, config: {}) ", async () => {
+ const cm = await core.compileModel(model, "CPU", tput);
+ assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
});
it("compileModel(model:Model) returns Promise<CompiledModel>", async () => {
@@ -203,34 +202,35 @@ describe("ov basic tests.", { skip: true }, () => {
assert.ok(cm instanceof ov.CompiledModel);
});
- it("compileModel(model_path, deviceName, config: {}) ", () => {
- core.compileModel(testModelFP32.xml, "CPU", tput).then((cm) => {
- assert.equal(cm.inputs.length, 1);
- });
+ it("compileModel(model_path, deviceName, config: {}) ", async () => {
+ const cm = await core.compileModel(testModelFP32.xml, "CPU", tput);
+ assert.equal(cm.inputs.length, 1);
});
- it("compileModel(model:model_path, deviceName: string) ", () => {
- core.compileModel(testModelFP32.xml, "CPU").then((cm) => {
- assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
- });
+ it("compileModel(model:model_path, deviceName: string) ", async () => {
+ const cm = await core.compileModel(testModelFP32.xml, "CPU");
+ assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
});
- it("compileModel(model, device, invalidconfig) throws", () => {
- assert.throws(
- () => core.compileModel(model, "CPU", "string").then(),
- "Argument #3 must be an Object.",
+ it("compileModel(model, device, invalidconfig) throws", async () => {
+ await assert.rejects(
+ async () => await core.compileModel(model, "CPU", "string"),
+ /Argument #\d+ must be an Object./,
);
});
- it("compileModel(model, device, invalidConfig) throws", () => {
- assert.throws(
- () => core.compileModel(model, "CPU", { PERFORMANCE_HINT: tput }).then(),
+ it("compileModel(model, device, invalidConfig) throws", async () => {
+ await assert.rejects(
+ async () => await core.compileModel(model, "CPU", { PERFORMANCE_HINT: tput }),
/Cannot convert to ov::Any/,
);
});
- it("compileModel(model) throws with invalid number of args", () => {
- assert.throws(() => core.compileModel(model).then(), /Invalid number of arguments/);
+ it("compileModel(model) throws with invalid number of args", async () => {
+ await assert.rejects(
+ async () => await core.compileModel(model),
+ /Invalid number of arguments/,
+ );
});
});
@@ -360,41 +360,39 @@ describe("ov basic tests.", { skip: true }, () => {
assert.ok(cm instanceof ov.CompiledModel);
});
- it("Test importModel(stream, device)", () => {
- core.importModel(userStream, "CPU").then((newCompiled) => {
- const newInferRequest = newCompiled.createInferRequest();
- const res2 = newInferRequest.infer([tensor]);
- assert.deepStrictEqual(res1["fc_out"].data[0], res2["fc_out"].data[0]);
- });
+ it("Test importModel(stream, device)", async () => {
+ const newCompiled = await core.importModel(userStream, "CPU");
+ const newInferRequest = newCompiled.createInferRequest();
+ const res2 = newInferRequest.infer([tensor]);
+ assert.deepStrictEqual(res1["fc_out"].data[0], res2["fc_out"].data[0]);
});
- it("Test importModel(stream, device, config)", () => {
- core.importModel(userStream, "CPU", { NUM_STREAMS: 1 }).then((newCompiled) => {
- const newInferRequest = newCompiled.createInferRequest();
- const res2 = newInferRequest.infer([tensor]);
+ it("Test importModel(stream, device, config)", async () => {
+ const newCompiled = await core.importModel(userStream, "CPU", { NUM_STREAMS: 1 });
+ const newInferRequest = newCompiled.createInferRequest();
+ const res2 = newInferRequest.infer([tensor]);
- assert.deepStrictEqual(res1["fc_out"].data[0], res2["fc_out"].data[0]);
- });
+ assert.deepStrictEqual(res1["fc_out"].data[0], res2["fc_out"].data[0]);
});
- it("Test importModel(stream, device) throws", () => {
- assert.throws(
- () => core.importModel(model, "CPU").then(),
+ it("Test importModel(stream, device) throws", async () => {
+ await assert.rejects(
+ async () => await core.importModel(model, "CPU"),
/'importModel' method called with incorrect parameters./,
);
});
- it("Test importModel(stream, device) throws", () => {
- assert.throws(
- () => core.importModel(userStream, tensor).then(),
+ it("Test importModel(stream, device) throws", async () => {
+ await assert.rejects(
+ async () => await core.importModel(userStream, tensor),
/'importModel' method called with incorrect parameters./,
);
});
- it("Test importModel(stream, device, config: string) throws", () => {
+ it("Test importModel(stream, device, config: string) throws", async () => {
const testString = "test";
- assert.throws(
- () => core.importModel(userStream, "CPU", testString).then(),
+ await assert.rejects(
+ async () => await core.importModel(userStream, "CPU", testString),
/'importModel' method called with incorrect parameters./,
);
});
diff --git a/src/bindings/js/node/tests/unit/core.test.js b/src/bindings/js/node/tests/unit/core.test.js
index d12274231b8..87b619546af 100644
--- a/src/bindings/js/node/tests/unit/core.test.js
+++ b/src/bindings/js/node/tests/unit/core.test.js
@@ -76,15 +76,12 @@ describe("ov.Core tests", () => {
});
it("Core.queryModel() with empty parameters should throw an error", () => {
- assert.throws(
- () => core.queryModel().then(),
- /'queryModel' method called with incorrect parameters./,
- );
+ assert.throws(() => core.queryModel(), /'queryModel' method called with incorrect parameters./);
});
it("Core.queryModel() with less arguments should throw an error", () => {
assert.throws(
- () => core.queryModel("Unexpected Argument").then(),
+ () => core.queryModel("Unexpected Argument"),
/'queryModel' method called with incorrect parameters./,
);
});
@@ -92,7 +89,7 @@ describe("ov.Core tests", () => {
it("Core.queryModel() with incorrect arguments should throw an error", () => {
const model = core.readModelSync(testModelFP32.xml);
assert.throws(
- () => core.queryModel(model, "arg1", "arg2").then(),
+ () => core.queryModel(model, "arg1", "arg2"),
/'queryModel' method called with incorrect parameters./,
);
});
diff --git a/src/bindings/js/node/tests/unit/infer_request.test.js b/src/bindings/js/node/tests/unit/infer_request.test.js
index 6e6e396f910..eac05c3b522 100644
--- a/src/bindings/js/node/tests/unit/infer_request.test.js
+++ b/src/bindings/js/node/tests/unit/infer_request.test.js
@@ -94,38 +94,36 @@ describe("ov.InferRequest tests", () => {
inferRequest = compiledModel.createInferRequest();
});
- it("Test inferAsync(inputData: { [inputName: string]: Tensor })", () => {
- inferRequest.inferAsync({ data: tensor }).then((result) => {
- assert.ok(result["fc_out"] instanceof ov.Tensor);
- assert.deepStrictEqual(Object.keys(result), ["fc_out"]);
- assert.deepStrictEqual(
- result["fc_out"].data.length,
- lengthFromShape(testModelFP32.outputShape),
- );
- });
+ it("Test inferAsync(inputData: { [inputName: string]: Tensor })", async () => {
+ const result = await inferRequest.inferAsync({ data: tensor });
+ assert.ok(result["fc_out"] instanceof ov.Tensor);
+ assert.deepStrictEqual(Object.keys(result), ["fc_out"]);
+ assert.deepStrictEqual(
+ result["fc_out"].data.length,
+ lengthFromShape(testModelFP32.outputShape),
+ );
});
- it("Test inferAsync(inputData: Tensor[])", () => {
- inferRequest.inferAsync([tensor]).then((result) => {
- assert.ok(result["fc_out"] instanceof ov.Tensor);
- assert.deepStrictEqual(Object.keys(result), ["fc_out"]);
- assert.deepStrictEqual(
- result["fc_out"].data.length,
- lengthFromShape(testModelFP32.outputShape),
- );
- });
+ it("Test inferAsync(inputData: Tensor[])", async () => {
+ const result = await inferRequest.inferAsync([tensor]);
+ assert.ok(result["fc_out"] instanceof ov.Tensor);
+ assert.deepStrictEqual(Object.keys(result), ["fc_out"]);
+ assert.deepStrictEqual(
+ result["fc_out"].data.length,
+ lengthFromShape(testModelFP32.outputShape),
+ );
});
- it("Test inferAsync([data]) throws", () => {
- assert.throws(
- () => inferRequest.inferAsync(["string"]).then(),
+ it("Test inferAsync([data]) throws", async () => {
+ await assert.rejects(
+ async () => await inferRequest.inferAsync(["string"]),
/Cannot create a tensor from the passed Napi::Value./,
);
});
- it('Test inferAsync({ data: "string"}) throws', () => {
- assert.throws(
- () => inferRequest.inferAsync({ data: "string" }).then(),
+ it('Test inferAsync({ data: "string"}) throws', async () => {
+ await assert.rejects(
+ async () => await inferRequest.inferAsync({ data: "string" }),
/Cannot create a tensor from the passed Napi::Value./,
);
});
@@ -400,9 +398,8 @@ describe("ov.InferRequest tests with missing outputs names", () => {
assert.deepStrictEqual(Object.keys(result).length, 1);
});
- it("Test inferAsync(inputData: Tensor[])", () => {
- inferRequest.inferAsync([tensor]).then((result) => {
- assert.deepStrictEqual(Object.keys(result).length, 1);
- });
+ it("Test inferAsync(inputData: Tensor[])", async () => {
+ const result = await inferRequest.inferAsync([tensor]);
+ assert.deepStrictEqual(Object.keys(result).length, 1);
});
});
diff --git a/src/bindings/js/node/tests/unit/model.test.js b/src/bindings/js/node/tests/unit/model.test.js
index 02577015d95..3db66cbf1ab 100644
--- a/src/bindings/js/node/tests/unit/model.test.js
+++ b/src/bindings/js/node/tests/unit/model.test.js
@@ -182,7 +182,7 @@ describe("ov.Model tests", () => {
it("should not accept any arguments", () => {
assert.throws(
- () => model.clone("Unexpected argument").then(),
+ () => model.clone("Unexpected argument"),
/'clone' method called with incorrect parameters./,
);
});
@@ -296,7 +296,7 @@ describe("ov.Model tests", () => {
it("should not accept any arguments", () => {
assert.throws(
- () => model.getOps("Unexpected argument").then(),
+ () => model.getOps("Unexpected argument"),
/'getOps' method called with incorrect parameters./,
);
});