Skip to content

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

[OV JS] Remove extra assets from tests (#25712)

Alicja Miloszewskaa07e2bc449a9
diff --git a/src/bindings/js/node/.gitignore b/src/bindings/js/node/.gitignore
index 6bbca841fe2..38782682575 100644
--- a/src/bindings/js/node/.gitignore
+++ b/src/bindings/js/node/.gitignore
@@ -3,6 +3,7 @@ dist
build
types
ov_runtime
+tests/unit/test_models
*.exp
diff --git a/src/bindings/js/node/package.json b/src/bindings/js/node/package.json
index 43f0a264571..a3544a6136c 100644
--- a/src/bindings/js/node/package.json
+++ b/src/bindings/js/node/package.json
@@ -18,7 +18,8 @@
"build": "npm run tsc",
"prepare": "npm run build",
"lint": "eslint .",
- "test": "node --test ./tests/unit/*.test.js",
+ "test_setup": "node ./tests/unit/setup.js",
+ "test": "npm run test_setup && node --test ./tests/unit/*.test.js",
"test:e2e": "mocha ./tests/e2e/electron-app.test.js",
"tsc": "tsc",
"postinstall": "npm run install_runtime",
diff --git a/src/bindings/js/node/scripts/download_runtime.js b/src/bindings/js/node/scripts/download_runtime.js
index f3aa3dce849..775b4aa6c75 100644
--- a/src/bindings/js/node/scripts/download_runtime.js
+++ b/src/bindings/js/node/scripts/download_runtime.js
@@ -61,7 +61,7 @@ class RuntimeExistsError extends Error {
async function downloadRuntime(destinationPath, config = { force: false, ignoreIfExists: true, proxy: null }) {
const { version } = packageJson;
const osInfo = await getOsInfo();
- const isRuntimeDirectoryExists = await checkIfDirectoryExists(destinationPath);
+ const isRuntimeDirectoryExists = await checkIfPathExists(destinationPath);
if (isRuntimeDirectoryExists && !config.force) {
if (config.ignoreIfExists) {
@@ -87,7 +87,7 @@ async function downloadRuntime(destinationPath, config = { force: false, ignoreI
await fs.mkdir(tempDirectoryPath);
console.log('Downloading OpenVINO runtime archive...');
- await downloadFile(runtimeArchiveUrl, filename, tempDirectoryPath, config.proxy);
+ await downloadFile(runtimeArchiveUrl, tempDirectoryPath, filename, config.proxy);
console.log('OpenVINO runtime archive downloaded.');
await removeDirectory(destinationPath);
@@ -139,16 +139,16 @@ async function getOsInfo() {
}
/**
- * Check if directory exists.
+ * Check if path exists.
*
* @async
- * @function checkIfDirectoryExists
- * @param {string} directoryPath - The directory path.
+ * @function checkIfPathExists
+ * @param {string} path - The path to directory or file.
* @returns {Promise<boolean>}
*/
-async function checkIfDirectoryExists(directoryPath) {
+async function checkIfPathExists(path) {
try {
- await fs.access(directoryPath);
+ await fs.access(path);
return true;
} catch (error) {
if (error.code === codeENOENT) {
@@ -210,7 +210,7 @@ async function removeDirectory(path) {
* @param {string} [proxy=null] - (Optional) The proxy URL.
* @returns {Promise<void>}
*/
-function downloadFile(url, filename, destination, proxy = null) {
+function downloadFile(url, destination, filename, proxy = null) {
const timeout = 5000;
const fullPath = path.resolve(destination, filename);
const file = createWriteStream(fullPath);
@@ -281,4 +281,4 @@ function unarchive(tarFilePath, dest) {
});
}
-module.exports = { downloadRuntime };
+module.exports = { downloadRuntime, downloadFile, checkIfPathExists };
diff --git a/src/bindings/js/node/tests/unit/basic.test.js b/src/bindings/js/node/tests/unit/basic.test.js
index e7447b3c863..4b4913fb52b 100644
--- a/src/bindings/js/node/tests/unit/basic.test.js
+++ b/src/bindings/js/node/tests/unit/basic.test.js
@@ -4,78 +4,83 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
+const { describe, it, before } = require('node:test');
+const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
-const testXml = getModelPath().xml;
-const core = new ov.Core();
-const model = core.readModelSync(testXml);
-const compiledModel = core.compileModelSync(model, 'CPU');
-const modelLike = [[model],
- [compiledModel]];
+describe('ov basic tests.', () => {
-it('Core.getAvailableDevices()', () => {
- const devices = core.getAvailableDevices();
-
- assert.ok(devices.includes('CPU'));
-});
-
-describe('Core.getVersions()', () => {
-
- it('getVersions(validDeviceName: string)', () => {
- const deviceVersion = core.getVersions('CPU');
- assert.strictEqual(typeof deviceVersion, 'object');
- assert.strictEqual(typeof deviceVersion.CPU, 'object');
- assert.strictEqual(typeof deviceVersion.CPU.buildNumber, 'string');
- assert.strictEqual(typeof deviceVersion.CPU.description, 'string');
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
});
- it('getVersions() throws if no arguments are passed into the function', () => {
- assert.throws(
- () => core.getVersions(),
- { message: 'getVersions() method expects 1 argument of string type.' }
- );
- });
+ const testXml = getModelPath().xml;
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
+ const compiledModel = core.compileModelSync(model, 'CPU');
+ const modelLike = [[model],
+ [compiledModel]];
- it('getVersions() throws if non string coercable arguments are passed into the function', () => {
- assert.throws(
- () => core.getVersions({ deviceName: 'CPU' }),
- { message: 'The argument in getVersions() method must be a string or convertible to a string.' }
- );
- });
+ it('Core.getAvailableDevices()', () => {
+ const devices = core.getAvailableDevices();
-});
+ assert.ok(devices.includes('CPU'));
+ });
+ describe('Core.getVersions()', () => {
-it('CompiledModel type', () => {
- assert.ok(compiledModel instanceof ov.CompiledModel);
-});
+ it('getVersions(validDeviceName: string)', () => {
+ const deviceVersion = core.getVersions('CPU');
+ assert.strictEqual(typeof deviceVersion, 'object');
+ assert.strictEqual(typeof deviceVersion.CPU, 'object');
+ assert.strictEqual(typeof deviceVersion.CPU.buildNumber, 'string');
+ assert.strictEqual(typeof deviceVersion.CPU.description, 'string');
+ });
-it('compileModel.createInferRequest()', () => {
- const ir = compiledModel.createInferRequest();
- assert.ok(ir instanceof ov.InferRequest);
-});
+ it('getVersions() throws if no arguments are passed into the function', () => {
+ assert.throws(
+ () => core.getVersions(),
+ { message: 'getVersions() method expects 1 argument of string type.' }
+ );
+ });
-describe('Core.compileModelSync()', () => {
- const tput = { 'PERFORMANCE_HINT': 'THROUGHPUT' };
+ it('getVersions() throws if non string coercable arguments are passed into the function', () => {
+ assert.throws(
+ () => core.getVersions({ deviceName: 'CPU' }),
+ { message: 'The argument in getVersions() method must be a string or convertible to a string.' }
+ );
+ });
- it('compileModelSync(model:Model, deviceName: string, config: {}) ', () => {
- const cm = core.compileModelSync(model, 'CPU', tput);
- assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
});
- it('compileModelSync(model:model_path, deviceName: string, config: {}) ', () => {
- const cm = core.compileModelSync(testXml, 'CPU', tput);
- assert.equal(cm.inputs.length, 1);
+ it('CompiledModel type', () => {
+ assert.ok(compiledModel instanceof ov.CompiledModel);
});
- it('compileModelSync(model:model_path, deviceName: string) ', () => {
- const cm = core.compileModelSync(testXml, 'CPU');
- assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
+ it('compileModel.createInferRequest()', () => {
+ const ir = compiledModel.createInferRequest();
+ assert.ok(ir instanceof ov.InferRequest);
});
- it('compileModelSync(model, device, config) throws when config is a string', () => {
- const expectedMsg = ("'compileModelSync' method called with incorrect parameters.\n" +
+ describe('Core.compileModelSync()', () => {
+ const tput = { 'PERFORMANCE_HINT': 'THROUGHPUT' };
+
+ it('compileModelSync(model:Model, deviceName: string, config: {}) ', () => {
+ const cm = core.compileModelSync(model, 'CPU', tput);
+ assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
+ });
+
+ it('compileModelSync(model:model_path, deviceName: string, config: {}) ', () => {
+ const cm = core.compileModelSync(testXml, 'CPU', tput);
+ assert.equal(cm.inputs.length, 1);
+ });
+
+ it('compileModelSync(model:model_path, deviceName: string) ', () => {
+ const cm = core.compileModelSync(testXml, 'CPU');
+ assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
+ });
+
+ it('compileModelSync(model, device, config) throws when config is a string', () => {
+ const expectedMsg = ('\'compileModelSync\' method called with incorrect parameters.\n' +
'Provided signature: (object, string, string) \n' +
'Allowed signatures:\n' +
'- (string, string)\n' +
@@ -83,21 +88,21 @@ describe('Core.compileModelSync()', () => {
'- (string, string, object)\n' +
'- (Model, string, object)\n').replace(/[()]/g, '\\$&');
- assert.throws(
- () => core.compileModelSync(model, 'CPU', 'string'),
- new RegExp(expectedMsg),
- );
- });
+ assert.throws(
+ () => core.compileModelSync(model, 'CPU', 'string'),
+ new RegExp(expectedMsg),
+ );
+ });
- it('compileModelSync(model, device, config) throws when config value is not a string', () => {
- assert.throws(
- () => core.compileModelSync(model, 'CPU', { 'PERFORMANCE_HINT': tput }),
- /Cannot convert to ov::Any/
- );
- });
+ it('compileModelSync(model, device, config) throws when config value is not a string', () => {
+ assert.throws(
+ () => core.compileModelSync(model, 'CPU', { 'PERFORMANCE_HINT': tput }),
+ /Cannot convert to ov::Any/
+ );
+ });
- it('compileModelSync(model) throws if the number of arguments is invalid', () => {
- const expectedMsg = ("'compileModelSync' method called with incorrect parameters.\n" +
+ it('compileModelSync(model) throws if the number of arguments is invalid', () => {
+ const expectedMsg = ('\'compileModelSync\' method called with incorrect parameters.\n' +
'Provided signature: (object) \n' +
'Allowed signatures:\n' +
'- (string, string)\n' +
@@ -105,228 +110,230 @@ describe('Core.compileModelSync()', () => {
'- (string, string, object)\n' +
'- (Model, string, object)\n').replace(/[()]/g, '\\$&');
- assert.throws(
- () => core.compileModelSync(model),
- new RegExp(expectedMsg),
- );
- });
-});
-
-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]);
+ assert.throws(
+ () => core.compileModelSync(model),
+ new RegExp(expectedMsg),
+ );
});
-
});
- it('compileModel(model:model_path, deviceName: string, config: {}) ', () => {
- core.compileModel(testXml, 'CPU', tput).then(cm => {
- assert.equal(cm.inputs.length, 1);
- });
+ 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_path, deviceName: string) ', () => {
- core.compileModel(testXml, 'CPU').then(cm => {
- assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
});
- });
-
- it('compileModel(model, device, config) throws when config isn\'t an object', () => {
- assert.throws(
- () => core.compileModel(model, 'CPU', 'string').then(),
- "Argument #3 must be an Object."
- );
- });
-
- it('compileModel(model, device, config) throws when config value is not a string', () => {
- assert.throws(
- () => core.compileModel(model, 'CPU', { 'PERFORMANCE_HINT': tput }).then(),
- /Cannot convert to ov::Any/
- );
- });
-
- it('compileModel(model) throws if the number of arguments is invalid', () => {
- assert.throws(
- () => core.compileModel(model).then(),
- /Invalid number of arguments/
- );
- });
-
-});
+ it('compileModel(model:model_path, deviceName: string, config: {}) ', () => {
+ core.compileModel(testXml, 'CPU', tput).then(cm => {
+ assert.equal(cm.inputs.length, 1);
+ });
-describe('Output class', () => {
+ });
- it('Output type', () => {
- assert.ok(model.output() instanceof ov.Output);
- });
+ it('compileModel(model:model_path, deviceName: string) ', () => {
+ core.compileModel(testXml, 'CPU').then(cm => {
+ assert.deepStrictEqual(cm.output(0).shape, [1, 10]);
+ });
- it('ConstOutput type', () => {
- assert.ok(compiledModel.output() instanceof ov.ConstOutput);
- });
+ });
- modelLike.forEach(([obj]) => {
- it('Output getters and properties', () => {
- assert.strictEqual(obj.outputs.length, 1);
- // tests for an obj with one output
- assert.strictEqual(obj.output().toString(), 'fc_out');
- assert.strictEqual(obj.output(0).toString(), 'fc_out');
- assert.strictEqual(obj.output('fc_out').toString(), 'fc_out');
- assert.deepStrictEqual(obj.output(0).shape, [1, 10]);
- assert.deepStrictEqual(obj.output(0).getShape(), [1, 10]);
- assert.strictEqual(obj.output().getAnyName(), 'fc_out');
- assert.strictEqual(obj.output().anyName, 'fc_out');
+ it('compileModel(model, device, config) throws when config isn\'t an object', () => {
+ assert.throws(
+ () => core.compileModel(model, 'CPU', 'string').then(),
+ 'Argument #3 must be an Object.'
+ );
});
- });
-});
+ it('compileModel(model, device, config) throws when config value is not a string', () => {
+ assert.throws(
+ () => core.compileModel(model, 'CPU', { 'PERFORMANCE_HINT': tput }).then(),
+ /Cannot convert to ov::Any/
+ );
+ });
-describe('Input class for ov::Input<const ov::Node>', () => {
+ it('compileModel(model) throws if the number of arguments is invalid', () => {
+ assert.throws(
+ () => core.compileModel(model).then(),
+ /Invalid number of arguments/
+ );
+ });
- it('Output type', () => {
- assert.ok(model.input() instanceof ov.Output);
});
- it('ConstOutput type', () => {
- assert.ok(compiledModel.input() instanceof ov.ConstOutput);
- });
+ describe('Output class', () => {
- modelLike.forEach(([obj]) => {
- it('input() is typeof object', () => {
- assert.strictEqual(typeof obj.input(), 'object');
+ it('Output type', () => {
+ assert.ok(model.output() instanceof ov.Output);
});
- it('inputs property', () => {
- assert.strictEqual(obj.inputs.length, 1);
+ it('ConstOutput type', () => {
+ assert.ok(compiledModel.output() instanceof ov.ConstOutput);
});
- it('input().toString()', () => {
- assert.strictEqual(obj.input().toString(), 'data');
+ modelLike.forEach(([obj]) => {
+ it('Output getters and properties', () => {
+ assert.strictEqual(obj.outputs.length, 1);
+ // tests for an obj with one output
+ assert.strictEqual(obj.output().toString(), 'fc_out');
+ assert.strictEqual(obj.output(0).toString(), 'fc_out');
+ assert.strictEqual(obj.output('fc_out').toString(), 'fc_out');
+ assert.deepStrictEqual(obj.output(0).shape, [1, 10]);
+ assert.deepStrictEqual(obj.output(0).getShape(), [1, 10]);
+ assert.strictEqual(obj.output().getAnyName(), 'fc_out');
+ assert.strictEqual(obj.output().anyName, 'fc_out');
+ });
});
- it('input(idx: number).ToString() method', () => {
- assert.strictEqual(obj.input(0).toString(), 'data');
- });
+ });
- it('input(tensorName: string).ToString() method', () => {
- assert.strictEqual(obj.input('data').toString(), 'data');
- });
+ describe('Input class for ov::Input<const ov::Node>', () => {
- it('input().getAnyName() and anyName', () => {
- assert.strictEqual(obj.input().getAnyName(), 'data');
- assert.strictEqual(obj.input().anyName, 'data');
+ it('Output type', () => {
+ assert.ok(model.input() instanceof ov.Output);
});
- it('input(idx).shape property with dimensions', () => {
- assert.deepStrictEqual(obj.input(0).shape, [1, 3, 32, 32]);
- assert.deepStrictEqual(obj.input(0).getShape(), [1, 3, 32, 32]);
+ it('ConstOutput type', () => {
+ assert.ok(compiledModel.input() instanceof ov.ConstOutput);
});
- });
-});
+ modelLike.forEach(([obj]) => {
+ it('input() is typeof object', () => {
+ assert.strictEqual(typeof obj.input(), 'object');
+ });
-describe('Test exportModel()/importModel()', () => {
- const userStream = compiledModel.exportModelSync();
- const epsilon = 0.5;
- const tensor = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
- const inferRequest = compiledModel.createInferRequest();
- const res1 = inferRequest.infer([tensor]);
+ it('inputs property', () => {
+ assert.strictEqual(obj.inputs.length, 1);
+ });
- it('Test importModelSync(stream, device)', () => {
- const newCompiled = core.importModelSync(userStream, 'CPU');
- const newInferRequest = newCompiled.createInferRequest();
- const res2 = newInferRequest.infer([tensor]);
+ it('input().toString()', () => {
+ assert.strictEqual(obj.input().toString(), 'data');
+ });
- assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
- });
+ it('input(idx: number).ToString() method', () => {
+ assert.strictEqual(obj.input(0).toString(), 'data');
+ });
- it('Test importModelSync(stream, device, config)', () => {
- const newCompiled = core.importModelSync(userStream, 'CPU', { 'NUM_STREAMS': 1 });
- const newInferRequest = newCompiled.createInferRequest();
- const res2 = newInferRequest.infer([tensor]);
+ it('input(tensorName: string).ToString() method', () => {
+ assert.strictEqual(obj.input('data').toString(), 'data');
+ });
- assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
- });
+ it('input().getAnyName() and anyName', () => {
+ assert.strictEqual(obj.input().getAnyName(), 'data');
+ assert.strictEqual(obj.input().anyName, 'data');
+ });
- it('Test importModelSync(stream, device) throws', () => {
- assert.throws(
- () => core.importModelSync(epsilon, 'CPU'),
- /The first argument must be of type Buffer./
- );
- });
+ it('input(idx).shape property with dimensions', () => {
+ assert.deepStrictEqual(obj.input(0).shape, [1, 3, 32, 32]);
+ assert.deepStrictEqual(obj.input(0).getShape(), [1, 3, 32, 32]);
+ });
+ });
- it('Test importModelSync(stream, device) throws', () => {
- assert.throws(
- () => core.importModelSync(userStream, tensor),
- /The second argument must be of type String./
- );
- });
- it('Test importModelSync(stream, device, config: tensor) throws', () => {
- assert.throws(
- () => core.importModelSync(userStream, 'CPU', tensor),
- /NotFound: Unsupported property 0 by CPU plugin./
- );
});
- it('Test importModelSync(stream, device, config: string) throws', () => {
- const testString = 'test';
- assert.throws(
- () => core.importModelSync(userStream, 'CPU', testString),
- /Passed Napi::Value must be an object./
- );
- });
+ describe('Test exportModel()/importModel()', () => {
+ const userStream = compiledModel.exportModelSync();
+ const epsilon = 0.5;
+ const tensor = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
+ const inferRequest = compiledModel.createInferRequest();
+ const res1 = inferRequest.infer([tensor]);
- it('Test importModelSync(stream, device, config: unsupported property) \
- throws', () => {
- const tmpDir = '/tmp';
- assert.throws(
- () => core.importModelSync(userStream, 'CPU', { 'CACHE_DIR': tmpDir }),
- /Unsupported property CACHE_DIR by CPU plugin./
- );
- });
+ it('Test importModelSync(stream, device)', () => {
+ const newCompiled = core.importModelSync(userStream, 'CPU');
+ const newInferRequest = newCompiled.createInferRequest();
+ const res2 = newInferRequest.infer([tensor]);
- it('Test importModel(stream, device)', () => {
- core.importModel(userStream, 'CPU').then(newCompiled => {
+ assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
+ });
+
+ it('Test importModelSync(stream, device, config)', () => {
+ const newCompiled = core.importModelSync(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]);
});
- });
- it('Test importModel(stream, device, config)', () => {
- core.importModel(userStream, 'CPU', { 'NUM_STREAMS': 1 }).then(
- newCompiled => {
+ it('Test importModelSync(stream, device) throws', () => {
+ assert.throws(
+ () => core.importModelSync(epsilon, 'CPU'),
+ /The first argument must be of type Buffer./
+ );
+ });
+
+ it('Test importModelSync(stream, device) throws', () => {
+ assert.throws(
+ () => core.importModelSync(userStream, tensor),
+ /The second argument must be of type String./
+ );
+ });
+ it('Test importModelSync(stream, device, config: tensor) throws', () => {
+ assert.throws(
+ () => core.importModelSync(userStream, 'CPU', tensor),
+ /NotFound: Unsupported property 0 by CPU plugin./
+ );
+ });
+
+ it('Test importModelSync(stream, device, config: string) throws', () => {
+ const testString = 'test';
+ assert.throws(
+ () => core.importModelSync(userStream, 'CPU', testString),
+ /Passed Napi::Value must be an object./
+ );
+ });
+
+ it('Test importModelSync(stream, device, config: unsupported property) \
+ throws', () => {
+ const tmpDir = '/tmp';
+ assert.throws(
+ () => core.importModelSync(userStream, 'CPU', { 'CACHE_DIR': tmpDir }),
+ /Unsupported property CACHE_DIR by CPU plugin./
+ );
+ });
+
+ 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) throws', () => {
- assert.throws(
- () => core.importModel(epsilon, 'CPU').then(),
- /'importModel' method called with incorrect parameters./
- );
- });
+ 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) throws', () => {
- assert.throws(
- () => core.importModel(userStream, tensor).then(),
- /'importModel' method called with incorrect parameters./
- );
- });
+ assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
+ });
+ });
+
+ it('Test importModel(stream, device) throws', () => {
+ assert.throws(
+ () => core.importModel(epsilon, 'CPU').then(),
+ /'importModel' method called with incorrect parameters./
+ );
+ });
+
+ it('Test importModel(stream, device) throws', () => {
+ assert.throws(
+ () => core.importModel(userStream, tensor).then(),
+ /'importModel' method called with incorrect parameters./
+ );
+ });
+
+ it('Test importModel(stream, device, config: string) throws', () => {
+ const testString = 'test';
+ assert.throws(
+ () => core.importModel(userStream, 'CPU', testString).then(),
+ /'importModel' method called with incorrect parameters./
+ );
+ });
- it('Test importModel(stream, device, config: string) throws', () => {
- const testString = 'test';
- assert.throws(
- () => core.importModel(userStream, 'CPU', testString).then(),
- /'importModel' method called with incorrect parameters./
- );
});
});
diff --git a/src/bindings/js/node/tests/unit/compiled_model.test.js b/src/bindings/js/node/tests/unit/compiled_model.test.js
index 6b33296131b..2d1169b0783 100644
--- a/src/bindings/js/node/tests/unit/compiled_model.test.js
+++ b/src/bindings/js/node/tests/unit/compiled_model.test.js
@@ -4,17 +4,21 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
+const { describe, it, before } = require('node:test');
+const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
-const testXml = getModelPath().xml;
-const core = new ov.Core();
-const properties = {
- "AUTO_BATCH_TIMEOUT": '1'
-};
-const compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);
+describe('ov.CompiledModel tests', () => {
-describe('setProperty() / getProperty()', () => {
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
+ });
+
+ const testXml = getModelPath().xml;
+ const core = new ov.Core();
+ const properties = {
+ 'AUTO_BATCH_TIMEOUT': '1',
+ };
+ const compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);
describe('getProperty()', () => {
it('returns the value of property from compiled model', () => {
@@ -26,7 +30,7 @@ describe('setProperty() / getProperty()', () => {
/'getProperty' method called with incorrect parameters/
);
});
- it('throws an error when called with property name that does not exists', ()=>{
+ it('throws an error when called with property name that does not exists', () => {
assert.throws(
() => compiledModel.getProperty('PROPERTY_THAT_DOES_NOT_EXIST')
);
@@ -35,10 +39,10 @@ describe('setProperty() / getProperty()', () => {
describe('setProperty()', () => {
it('sets a properties for compiled model', () => {
- properties["AUTO_BATCH_TIMEOUT"] = '1000';
+ properties['AUTO_BATCH_TIMEOUT'] = '1000';
assert.doesNotThrow(() => compiledModel.setProperty(properties));
});
-
+
it('throws an error when called without an object argument', () => {
assert.throws(
() => compiledModel.setProperty(),
@@ -47,30 +51,30 @@ describe('setProperty() / getProperty()', () => {
});
it('throws an error when called with wrong argument', () => {
assert.throws(
- () => compiledModel.setProperty(123),
- /'setProperty' method called with incorrect parameters/
+ () => compiledModel.setProperty(123),
+ /'setProperty' method called with incorrect parameters/
);
});
-
+
it('throws an error when called with multiple arguments', () => {
assert.throws(
- () => compiledModel.setProperty({"PERFORMANCE_HINT": "THROUGHPUT"}, {"NUM_STREAMS": "AUTO"}),
+ () => compiledModel.setProperty({'PERFORMANCE_HINT': 'THROUGHPUT'}, {'NUM_STREAMS': 'AUTO'}),
/'setProperty' method called with incorrect parameters/
);
});
-
+
it('returns the set property of the compiled model', () => {
- properties["AUTO_BATCH_TIMEOUT"] = '123';
+ properties['AUTO_BATCH_TIMEOUT'] = '123';
compiledModel.setProperty(properties);
assert.strictEqual(compiledModel.getProperty('AUTO_BATCH_TIMEOUT'), 123);
});
-
+
it('retains the last set property when set multiple times', () => {
- compiledModel.setProperty({"AUTO_BATCH_TIMEOUT": '321'});
+ compiledModel.setProperty({'AUTO_BATCH_TIMEOUT': '321'});
compiledModel.setProperty({'AUTO_BATCH_TIMEOUT': '132'});
assert.strictEqual(compiledModel.getProperty('AUTO_BATCH_TIMEOUT'), 132);
});
-
+
it('allows to pass empty object', () => {
assert.doesNotThrow(() => compiledModel.setProperty({}));
});
diff --git a/src/bindings/js/node/tests/unit/core.test.js b/src/bindings/js/node/tests/unit/core.test.js
index 2c70428b66b..69d8720d97a 100644
--- a/src/bindings/js/node/tests/unit/core.test.js
+++ b/src/bindings/js/node/tests/unit/core.test.js
@@ -6,64 +6,67 @@ const { addon: ov } = require('../..');
const assert = require('assert');
const { describe, it } = require('node:test');
-const core = new ov.Core();
+describe('ov.Core tests', () => {
-it('Core.setProperty()', () => {
- const tmpDir = '/tmp';
+ const core = new ov.Core();
- core.setProperty({ 'CACHE_DIR': tmpDir });
+ it('Core.setProperty()', () => {
+ const tmpDir = '/tmp';
- const cacheDir = core.getProperty('CACHE_DIR');
+ core.setProperty({ 'CACHE_DIR': tmpDir });
- assert.equal(cacheDir, tmpDir);
-});
+ const cacheDir = core.getProperty('CACHE_DIR');
-it('Core.setProperty(\'CPU\')', () => {
- const tmpDir = '/tmp';
+ assert.equal(cacheDir, tmpDir);
+ });
- core.setProperty('CPU', { 'CACHE_DIR': tmpDir });
+ it('Core.setProperty(\'CPU\')', () => {
+ const tmpDir = '/tmp';
- const cacheDir = core.getProperty('CPU', 'CACHE_DIR');
+ core.setProperty('CPU', { 'CACHE_DIR': tmpDir });
- assert.equal(cacheDir, tmpDir);
-});
+ const cacheDir = core.getProperty('CPU', 'CACHE_DIR');
-it('Core.getProperty(\'CPU\', \'SUPPORTED_PROPERTIES\') is Array', () => {
- const supportedPropertiesArray = core.getProperty('CPU', 'SUPPORTED_PROPERTIES');
+ assert.equal(cacheDir, tmpDir);
+ });
- assert.ok(Array.isArray(supportedPropertiesArray));
-});
+ it('Core.getProperty(\'CPU\', \'SUPPORTED_PROPERTIES\') is Array', () => {
+ const supportedPropertiesArray = core.getProperty('CPU', 'SUPPORTED_PROPERTIES');
-it('Core.setProperty(\'CPU\', { \'NUM_STREAMS\': 5 })', () => {
- const streams = 5;
+ assert.ok(Array.isArray(supportedPropertiesArray));
+ });
- core.setProperty('CPU', { 'NUM_STREAMS': streams });
- const result = core.getProperty('CPU', 'NUM_STREAMS');
+ it('Core.setProperty(\'CPU\', { \'NUM_STREAMS\': 5 })', () => {
+ const streams = 5;
- assert.equal(result, streams);
-});
+ core.setProperty('CPU', { 'NUM_STREAMS': streams });
+ const result = core.getProperty('CPU', 'NUM_STREAMS');
-it('Core.setProperty(\'CPU\', { \'INFERENCE_NUM_THREADS\': 3 })', () => {
- const threads = 3;
+ assert.equal(result, streams);
+ });
- core.setProperty('CPU', { 'INFERENCE_NUM_THREADS': threads });
- const result = core.getProperty('CPU', 'INFERENCE_NUM_THREADS');
+ it('Core.setProperty(\'CPU\', { \'INFERENCE_NUM_THREADS\': 3 })', () => {
+ const threads = 3;
- assert.equal(result, threads);
-});
+ core.setProperty('CPU', { 'INFERENCE_NUM_THREADS': threads });
+ const result = core.getProperty('CPU', 'INFERENCE_NUM_THREADS');
-it('Core.addExtension() with empty parameters', () => {
- assert.throws(
- () => core.addExtension(),
- /addExtension method applies one argument of string type/
- );
-});
+ assert.equal(result, threads);
+ });
+
+ it('Core.addExtension() with empty parameters', () => {
+ assert.throws(
+ () => core.addExtension(),
+ /addExtension method applies one argument of string type/
+ );
+ });
-it('Core.addExtension(\'not_exists\') with non-existed library', () => {
- const notExistsExt = 'not_exists';
+ it('Core.addExtension(\'not_exists\') with non-existed library', () => {
+ const notExistsExt = 'not_exists';
- assert.throws(
- () => core.addExtension(notExistsExt),
- /Cannot load library 'not_exists'/
- );
+ assert.throws(
+ () => core.addExtension(notExistsExt),
+ /Cannot load library 'not_exists'/
+ );
+ });
});
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 bdc54fc4f4d..8dc16cd1954 100644
--- a/src/bindings/js/node/tests/unit/infer_request.test.js
+++ b/src/bindings/js/node/tests/unit/infer_request.test.js
@@ -4,277 +4,286 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
+const { describe, it, before } = require('node:test');
+const { testModels, isModelAvailable, getModelPath } = require('./utils.js');
const epsilon = 0.5; // To avoid very small numbers
const testXml = getModelPath().xml;
-const core = new ov.Core();
-const model = core.readModelSync(testXml);
-const compiledModel = core.compileModelSync(model, 'CPU');
-
-const inferRequest = compiledModel.createInferRequest();
-const inferRequestAsync = compiledModel.createInferRequest();
-
-const tensorData = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
-const tensor = new ov.Tensor(
- ov.element.f32,
- [1, 3, 32, 32],
- tensorData,
-);
-const resTensor = new ov.Tensor(
- ov.element.f32,
- [1, 10],
- tensorData.slice(-10),
-);
-
-const tensorLike = [[tensor],
- [tensorData]];
-
-describe('InferRequest', () => {
-
- tensorLike.forEach(([tl]) => {
- const result = inferRequest.infer({ data: tl });
- const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
- it(`Test infer(inputData: { [inputName: string]: ${label} })`, () => {
- assert.deepStrictEqual(Object.keys(result), ['fc_out']);
- assert.deepStrictEqual(result['fc_out'].data.length, 10);
- });
- });
- tensorLike.forEach(([tl]) => {
- const result = inferRequest.infer([tl]);
- const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
- it(`Test infer(inputData: ${label})`, () => {
- assert.deepStrictEqual(Object.keys(result), ['fc_out']);
- assert.deepStrictEqual(result['fc_out'].data.length, 10);
- });
+describe('ov.InferRequest tests', () => {
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
});
- it('Test infer(TypedArray) throws', () => {
- assert.throws(
- () => inferRequest.infer(tensorData),
- {message: /TypedArray cannot be passed directly into infer\(\) method./});
- });
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
+ const compiledModel = core.compileModelSync(model, 'CPU');
- const buffer = new ArrayBuffer(tensorData.length);
- const inputMessagePairs = [
- ['string', 'Cannot create a tensor from the passed Napi::Value.'],
- [tensorData.slice(-10), 'Memory allocated using shape and element::type mismatch passed data\'s size'],
- [new Float32Array(buffer, 4), 'TypedArray.byteOffset has to be equal to zero.'],
- [{}, /Invalid argument/], // Test for object that is not Tensor
- ];
+ const inferRequest = compiledModel.createInferRequest();
+ const inferRequestAsync = compiledModel.createInferRequest();
+
+ const tensorData = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
+ const tensor = new ov.Tensor(
+ ov.element.f32,
+ [1, 3, 32, 32],
+ tensorData,
+ );
+ const resTensor = new ov.Tensor(
+ ov.element.f32,
+ [1, 10],
+ tensorData.slice(-10),
+ );
+
+ const tensorLike = [[tensor],
+ [tensorData]];
+
+ describe('InferRequest', () => {
+
+ tensorLike.forEach(([tl]) => {
+ const result = inferRequest.infer({ data: tl });
+ const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
+ it(`Test infer(inputData: { [inputName: string]: ${label} })`, () => {
+ assert.deepStrictEqual(Object.keys(result), ['fc_out']);
+ assert.deepStrictEqual(result['fc_out'].data.length, 10);
+ });
+ });
+
+ tensorLike.forEach(([tl]) => {
+ const result = inferRequest.infer([tl]);
+ const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
+ it(`Test infer(inputData: ${label})`, () => {
+ assert.deepStrictEqual(Object.keys(result), ['fc_out']);
+ assert.deepStrictEqual(result['fc_out'].data.length, 10);
+ });
- inputMessagePairs.forEach( ([tl, msg]) => {
- it(`Test infer([data]) throws ${msg}`, () => {
- assert.throws(
- () => inferRequest.infer([tl]),
- {message: new RegExp(msg)});
});
- it(`Test infer({ data: tl}) throws ${msg}`, () => {
+
+ it('Test infer(TypedArray) throws', () => {
assert.throws(
- () => inferRequest.infer({data: tl}),
- {message: new RegExp(msg)});
+ () => inferRequest.infer(tensorData),
+ {message: /TypedArray cannot be passed directly into infer\(\) method./});
});
- });
- it('Test inferAsync(inputData: { [inputName: string]: Tensor })', () => {
- inferRequestAsync.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, 10);}
- );
- });
+ const buffer = new ArrayBuffer(tensorData.length);
+ const inputMessagePairs = [
+ ['string', 'Cannot create a tensor from the passed Napi::Value.'],
+ [tensorData.slice(-10), 'Memory allocated using shape and element::type mismatch passed data\'s size'],
+ [new Float32Array(buffer, 4), 'TypedArray.byteOffset has to be equal to zero.'],
+ [{}, /Invalid argument/], // Test for object that is not Tensor
+ ];
+
+ inputMessagePairs.forEach( ([tl, msg]) => {
+ it(`Test infer([data]) throws ${msg}`, () => {
+ assert.throws(
+ () => inferRequest.infer([tl]),
+ {message: new RegExp(msg)});
+ });
+ it(`Test infer({ data: tl}) throws ${msg}`, () => {
+ assert.throws(
+ () => inferRequest.infer({data: tl}),
+ {message: new RegExp(msg)});
+ });
+ });
- it('Test inferAsync(inputData: Tensor[])', () => {
- inferRequestAsync.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, 10);
+ it('Test inferAsync(inputData: { [inputName: string]: Tensor })', () => {
+ inferRequestAsync.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, 10);}
+ );
});
- });
- it('Test inferAsync([data]) throws: Cannot create a tensor from the passed Napi::Value.', () => {
- assert.throws(
- () => inferRequestAsync.inferAsync(['string']).then(),
- /Cannot create a tensor from the passed Napi::Value./
- );
- });
+ it('Test inferAsync(inputData: Tensor[])', () => {
+ inferRequestAsync.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, 10);
+ });
+ });
- it('Test inferAsync({ data: "string"}) throws: Cannot create a tensor from the passed Napi::Value.', () => {
- assert.throws(
- () => inferRequestAsync.inferAsync({data: 'string'}).then(),
- /Cannot create a tensor from the passed Napi::Value./
- );
- });
+ it('Test inferAsync([data]) throws: Cannot create a tensor from the passed Napi::Value.', () => {
+ assert.throws(
+ () => inferRequestAsync.inferAsync(['string']).then(),
+ /Cannot create a tensor from the passed Napi::Value./
+ );
+ });
- it('Test setInputTensor(tensor)', () => {
- inferRequest.setInputTensor(tensor);
- const t1 = inferRequest.getInputTensor();
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ it('Test inferAsync({ data: "string"}) throws: Cannot create a tensor from the passed Napi::Value.', () => {
+ assert.throws(
+ () => inferRequestAsync.inferAsync({data: 'string'}).then(),
+ /Cannot create a tensor from the passed Napi::Value./
+ );
+ });
- it('Test setInputTensor(object) throws when passed object is not a Tensor.', () => {
- assert.throws(
- () => inferRequest.setInputTensor({}),
- {message: /Argument #[0-9]+ must be a Tensor./}
- );
- });
+ it('Test setInputTensor(tensor)', () => {
+ inferRequest.setInputTensor(tensor);
+ const t1 = inferRequest.getInputTensor();
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
- it('Test setInputTensor(idx, tensor)', () => {
- inferRequest.setInputTensor(0, tensor);
- const t1 = inferRequest.getInputTensor();
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ it('Test setInputTensor(object) throws when passed object is not a Tensor.', () => {
+ assert.throws(
+ () => inferRequest.setInputTensor({}),
+ {message: /Argument #[0-9]+ must be a Tensor./}
+ );
+ });
- it('Test setInputTensor(idx, tensor) throws', () => {
- const testIdx = 10;
- assert.throws (
- () => inferRequest.setInputTensor(testIdx, tensor),
- {message: /Input port for index [0-9]+ was not found!/}
- );
- });
+ it('Test setInputTensor(idx, tensor)', () => {
+ inferRequest.setInputTensor(0, tensor);
+ const t1 = inferRequest.getInputTensor();
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
- it('Test setInputTensor(idx, object) throws when passed object is not a Tensor.', () => {
- assert.throws(
- () => inferRequest.setInputTensor(0, {}),
- {message: /Argument #[0-9]+ must be a Tensor./}
- );
- });
+ it('Test setInputTensor(idx, tensor) throws', () => {
+ const testIdx = 10;
+ assert.throws (
+ () => inferRequest.setInputTensor(testIdx, tensor),
+ {message: /Input port for index [0-9]+ was not found!/}
+ );
+ });
- it('Test setInputTensor(tensor, tensor) throws', () => {
- assert.throws(
- () => inferRequest.setInputTensor(resTensor, tensor),
- {message: / invalid argument./}
- );
- });
+ it('Test setInputTensor(idx, object) throws when passed object is not a Tensor.', () => {
+ assert.throws(
+ () => inferRequest.setInputTensor(0, {}),
+ {message: /Argument #[0-9]+ must be a Tensor./}
+ );
+ });
- it('Test setOutputTensor(tensor)', () => {
- inferRequest.setOutputTensor(resTensor);
- const res2 = inferRequest.getOutputTensor();
- assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
- });
+ it('Test setInputTensor(tensor, tensor) throws', () => {
+ assert.throws(
+ () => inferRequest.setInputTensor(resTensor, tensor),
+ {message: / invalid argument./}
+ );
+ });
- it('Test setOutputTensor(object) throws when passed object is not a Tensor.', () => {
- assert.throws(
- () => inferRequest.setOutputTensor({}),
- {message: /Argument #[0-9]+ must be a Tensor./}
- );
- });
+ it('Test setOutputTensor(tensor)', () => {
+ inferRequest.setOutputTensor(resTensor);
+ const res2 = inferRequest.getOutputTensor();
+ assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
+ });
- it('Test setOutputTensor(idx, tensor) throws', () => {
- const testIdx = 10;
- assert.throws (
- () => inferRequest.setOutputTensor(testIdx, tensor),
- {message: /Output port for index [0-9]+ was not found!/}
- );
- });
+ it('Test setOutputTensor(object) throws when passed object is not a Tensor.', () => {
+ assert.throws(
+ () => inferRequest.setOutputTensor({}),
+ {message: /Argument #[0-9]+ must be a Tensor./}
+ );
+ });
- it('Test setOutputTensor(idx, tensor)', () => {
- inferRequest.setOutputTensor(0, resTensor);
- const res2 = inferRequest.getOutputTensor();
- assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
- });
+ it('Test setOutputTensor(idx, tensor) throws', () => {
+ const testIdx = 10;
+ assert.throws (
+ () => inferRequest.setOutputTensor(testIdx, tensor),
+ {message: /Output port for index [0-9]+ was not found!/}
+ );
+ });
- it('Test setOutputTensor(idx, tensor) throws when passed object is not a Tensor.', () => {
- assert.throws(
- () => inferRequest.setOutputTensor(0, {}),
- {message: /Argument #[0-9]+ must be a Tensor./}
- );
- });
+ it('Test setOutputTensor(idx, tensor)', () => {
+ inferRequest.setOutputTensor(0, resTensor);
+ const res2 = inferRequest.getOutputTensor();
+ assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
+ });
- it('Test setOutputTensor() - pass two tensors', () => {
- assert.throws(
- () => inferRequest.setOutputTensor(resTensor, tensor),
- {message: / invalid argument./});
- });
+ it('Test setOutputTensor(idx, tensor) throws when passed object is not a Tensor.', () => {
+ assert.throws(
+ () => inferRequest.setOutputTensor(0, {}),
+ {message: /Argument #[0-9]+ must be a Tensor./}
+ );
+ });
- it('Test setTensor(string, tensor)', () => {
- inferRequest.setTensor('fc_out', resTensor);
- const res2 = inferRequest.getTensor('fc_out');
- assert.ok(res2 instanceof ov.Tensor);
- assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
- });
+ it('Test setOutputTensor() - pass two tensors', () => {
+ assert.throws(
+ () => inferRequest.setOutputTensor(resTensor, tensor),
+ {message: / invalid argument./});
+ });
- it('Test setTensor(string, object) - throws', () => {
- const testName = 'testName';
- assert.throws(
- () => inferRequest.setTensor(testName, tensor),
- {message: /Port for tensor name testName was not found./});
- });
+ it('Test setTensor(string, tensor)', () => {
+ inferRequest.setTensor('fc_out', resTensor);
+ const res2 = inferRequest.getTensor('fc_out');
+ assert.ok(res2 instanceof ov.Tensor);
+ assert.deepStrictEqual(resTensor.data[0], res2.data[0]);
+ });
- it('Test setTensor(string, object) - throws', () => {
- assert.throws(
- () => inferRequest.setTensor('fc_out', {}),
- {message: /Argument #[0-9]+ must be a Tensor./});
- });
+ it('Test setTensor(string, object) - throws', () => {
+ const testName = 'testName';
+ assert.throws(
+ () => inferRequest.setTensor(testName, tensor),
+ {message: /Port for tensor name testName was not found./});
+ });
- it('Test setTensor(string, tensor) - pass one arg', () => {
- assert.throws(
- () => inferRequest.setTensor('fc_out'),
- {message: / invalid argument./}
- );
- });
+ it('Test setTensor(string, object) - throws', () => {
+ assert.throws(
+ () => inferRequest.setTensor('fc_out', {}),
+ {message: /Argument #[0-9]+ must be a Tensor./});
+ });
- it('Test setTensor(string, tensor) - pass args in wrong order', () => {
- assert.throws(
- () => inferRequest.setTensor(resTensor, 'fc_out'),
- {message: / invalid argument./}
- );
- });
+ it('Test setTensor(string, tensor) - pass one arg', () => {
+ assert.throws(
+ () => inferRequest.setTensor('fc_out'),
+ {message: / invalid argument./}
+ );
+ });
- it('Test setTensor(string, tensor) - pass number as first arg', () => {
- assert.throws(
- () => inferRequest.setTensor(123, 'fc_out'),
- {message: / invalid argument/}
- );
- });
+ it('Test setTensor(string, tensor) - pass args in wrong order', () => {
+ assert.throws(
+ () => inferRequest.setTensor(resTensor, 'fc_out'),
+ {message: / invalid argument./}
+ );
+ });
- const irGetters = compiledModel.createInferRequest();
- irGetters.setInputTensor(tensor);
- irGetters.infer();
+ it('Test setTensor(string, tensor) - pass number as first arg', () => {
+ assert.throws(
+ () => inferRequest.setTensor(123, 'fc_out'),
+ {message: / invalid argument/}
+ );
+ });
- it('Test getTensor(tensorName)', () => {
- const t1 = irGetters.getTensor('data');
- assert.ok(t1 instanceof ov.Tensor);
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ const irGetters = compiledModel.createInferRequest();
+ irGetters.setInputTensor(tensor);
+ irGetters.infer();
- it('Test getTensor(Output)', () => {
- const input = irGetters.getCompiledModel().input();
- const t1 = irGetters.getTensor(input);
- assert.ok(t1 instanceof ov.Tensor);
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ it('Test getTensor(tensorName)', () => {
+ const t1 = irGetters.getTensor('data');
+ assert.ok(t1 instanceof ov.Tensor);
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
- it('Test getInputTensor()', () => {
- const t1 = irGetters.getInputTensor();
- assert.ok(t1 instanceof ov.Tensor);
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ it('Test getTensor(Output)', () => {
+ const input = irGetters.getCompiledModel().input();
+ const t1 = irGetters.getTensor(input);
+ assert.ok(t1 instanceof ov.Tensor);
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
- it('Test getInputTensor(idx)', () => {
- const t1 = irGetters.getInputTensor(0);
- assert.ok(t1 instanceof ov.Tensor);
- assert.deepStrictEqual(tensor.data[0], t1.data[0]);
- });
+ it('Test getInputTensor()', () => {
+ const t1 = irGetters.getInputTensor();
+ assert.ok(t1 instanceof ov.Tensor);
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
- it('Test getOutputTensor(idx?)', () => {
- const res1 = irGetters.getOutputTensor();
- const res2 = irGetters.getOutputTensor(0);
- assert.ok(res1 instanceof ov.Tensor);
- assert.ok(res2 instanceof ov.Tensor);
- assert.deepStrictEqual(res1.data[0], res2.data[0]);
- });
+ it('Test getInputTensor(idx)', () => {
+ const t1 = irGetters.getInputTensor(0);
+ assert.ok(t1 instanceof ov.Tensor);
+ assert.deepStrictEqual(tensor.data[0], t1.data[0]);
+ });
+
+ it('Test getOutputTensor(idx?)', () => {
+ const res1 = irGetters.getOutputTensor();
+ const res2 = irGetters.getOutputTensor(0);
+ assert.ok(res1 instanceof ov.Tensor);
+ assert.ok(res2 instanceof ov.Tensor);
+ assert.deepStrictEqual(res1.data[0], res2.data[0]);
+ });
- it('Test getCompiledModel()', () => {
- const ir = compiledModel.createInferRequest();
- const cm = ir.getCompiledModel();
- assert.ok(cm instanceof ov.CompiledModel);
- const ir2 = cm.createInferRequest();
- const res2 = ir2.infer([tensorData]);
- const res1 = ir.infer([tensorData]);
- assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
+ it('Test getCompiledModel()', () => {
+ const ir = compiledModel.createInferRequest();
+ const cm = ir.getCompiledModel();
+ assert.ok(cm instanceof ov.CompiledModel);
+ const ir2 = cm.createInferRequest();
+ const res2 = ir2.infer([tensorData]);
+ const res1 = ir.infer([tensorData]);
+ assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
+ });
});
+
});
diff --git a/src/bindings/js/node/tests/unit/model.test.js b/src/bindings/js/node/tests/unit/model.test.js
index 7728f13a25d..e374c0b3ab3 100644
--- a/src/bindings/js/node/tests/unit/model.test.js
+++ b/src/bindings/js/node/tests/unit/model.test.js
@@ -4,45 +4,51 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
-const testXml = getModelPath().xml;
-const core = new ov.Core();
-const model = core.readModelSync(testXml);
-const clonedModel = model.clone();
-
-describe('Node.js Model.isDynamic()', () => {
- it('should return a boolean value indicating if the model is dynamic', () => {
- const result = model.isDynamic();
- assert.strictEqual(
- typeof result,
- 'boolean',
- 'isDynamic() should return a boolean value'
- );
- });
+const { describe, it, before } = require('node:test');
+const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
+
+describe('ov.Model tests', () => {
- it('should not accept any arguments', () => {
- assert.throws(
- () => {
- model.isDynamic('unexpected argument');
- },
- /^Error: isDynamic\(\) does not accept any arguments\.$/,
- 'Expected isDynamic to throw an error when called with arguments'
- );
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
});
- it('returns false for a static model', () => {
- const expectedStatus = false;
- assert.strictEqual(
- model.isDynamic(),
- expectedStatus,
- 'Expected isDynamic to return false for a static model'
- );
+ const testXml = getModelPath().xml;
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
+ const clonedModel = model.clone();
+
+ describe('Model.isDynamic()', () => {
+ it('should return a boolean value indicating if the model is dynamic', () => {
+ const result = model.isDynamic();
+ assert.strictEqual(
+ typeof result,
+ 'boolean',
+ 'isDynamic() should return a boolean value'
+ );
+ });
+
+ it('should not accept any arguments', () => {
+ assert.throws(
+ () => {
+ model.isDynamic('unexpected argument');
+ },
+ /^Error: isDynamic\(\) does not accept any arguments\.$/,
+ 'Expected isDynamic to throw an error when called with arguments'
+ );
+ });
+
+ it('returns false for a static model', () => {
+ const expectedStatus = false;
+ assert.strictEqual(
+ model.isDynamic(),
+ expectedStatus,
+ 'Expected isDynamic to return false for a static model'
+ );
+ });
});
-});
-describe('Node.js getFriendlyName() / setFriendlyName()', () => {
- describe('getFriendlyName()', () => {
+ describe('Model.getFriendlyName()', () => {
it('returns the unique name of the model if no friendly name is set', () => {
const expectedName = 'test_model';
assert.strictEqual(model.getFriendlyName(), expectedName);
@@ -54,7 +60,7 @@ describe('Node.js getFriendlyName() / setFriendlyName()', () => {
);
});
});
- describe('setFriendlyName()', () => {
+ describe('Model.setFriendlyName()', () => {
it('sets a friendly name for the model', () => {
assert.doesNotThrow(() => model.setFriendlyName('MyFriendlyName'));
});
@@ -94,84 +100,85 @@ describe('Node.js getFriendlyName() / setFriendlyName()', () => {
assert.strictEqual(model.getFriendlyName(), 'Model1');
});
});
-});
-describe('Model.getOutputSize()', () => {
+ describe('Model.getOutputSize()', () => {
- it('should return a number indicating number of outputs for the model', () => {
- const result = model.getOutputSize();
- assert.strictEqual(typeof result, 'number', 'getOutputSize() should return a number');
- });
+ it('should return a number indicating number of outputs for the model', () => {
+ const result = model.getOutputSize();
+ assert.strictEqual(typeof result, 'number', 'getOutputSize() should return a number');
+ });
- it('should not accept any arguments', () => {
- assert.throws(() => {
- model.getOutputSize('unexpected argument');
- }, /^Error: getOutputSize\(\) does not accept any arguments\.$/, 'Expected getOutputSize to throw an error when called with arguments');
- });
+ it('should not accept any arguments', () => {
+ assert.throws(() => {
+ model.getOutputSize('unexpected argument');
+ }, /^Error: getOutputSize\(\) does not accept any arguments\.$/, 'Expected getOutputSize to throw an error when called with arguments');
+ });
- it('should return 1 for the default model', () => {
- assert.strictEqual(model.getOutputSize(), 1, 'Expected getOutputSize to return 1 for the default model');
+ it('should return 1 for the default model', () => {
+ assert.strictEqual(model.getOutputSize(), 1, 'Expected getOutputSize to return 1 for the default model');
+ });
});
-});
-describe('Model.getOutputElementType()', () => {
- it('should return a string for the element type ', () => {
- const result = model.getOutputElementType(0);
- assert.strictEqual(typeof result, 'string',
- 'getOutputElementType() should return a string');
- });
+ describe('Model.getOutputElementType()', () => {
+ it('should return a string for the element type ', () => {
+ const result = model.getOutputElementType(0);
+ assert.strictEqual(typeof result, 'string',
+ 'getOutputElementType() should return a string');
+ });
- it('should accept a single integer argument', () => {
- assert.throws(() => {
- model.getOutputElementType();
- }, /'getOutputElementType' method called with incorrect parameters/,
- 'Should throw when called without arguments');
-
- assert.throws(() => {
- model.getOutputElementType('unexpected argument');
- }, /'getOutputElementType' method called with incorrect parameters/,
- 'Should throw on non-number argument');
-
- assert.throws(() => {
- model.getOutputElementType(0, 1);
- }, /'getOutputElementType' method called with incorrect parameters/,
- 'Should throw on multiple arguments');
-
- assert.throws(() => {
- model.getOutputElementType(3.14);
- }, /'getOutputElementType' method called with incorrect parameters/,
- 'Should throw on non-integer number');
- });
+ it('should accept a single integer argument', () => {
+ assert.throws(() => {
+ model.getOutputElementType();
+ }, /'getOutputElementType' method called with incorrect parameters/,
+ 'Should throw when called without arguments');
+
+ assert.throws(() => {
+ model.getOutputElementType('unexpected argument');
+ }, /'getOutputElementType' method called with incorrect parameters/,
+ 'Should throw on non-number argument');
+
+ assert.throws(() => {
+ model.getOutputElementType(0, 1);
+ }, /'getOutputElementType' method called with incorrect parameters/,
+ 'Should throw on multiple arguments');
+
+ assert.throws(() => {
+ model.getOutputElementType(3.14);
+ }, /'getOutputElementType' method called with incorrect parameters/,
+ 'Should throw on non-integer number');
+ });
- it('should return a valid element type for the default model', () => {
- const elementType = model.getOutputElementType(0);
- assert.ok(typeof elementType === 'string' && elementType.length > 0,
- `Expected a non-empty string, got ${elementType}`);
- });
+ it('should return a valid element type for the default model', () => {
+ const elementType = model.getOutputElementType(0);
+ assert.ok(typeof elementType === 'string' && elementType.length > 0,
+ `Expected a non-empty string, got ${elementType}`);
+ });
- it('should throw an error for out-of-range index', () => {
- const outputSize = model.getOutputSize();
- assert.throws(
- () => { model.getOutputElementType(outputSize); },
- /^Error: /,
- 'Should throw for out-of-range index'
- );
+ it('should throw an error for out-of-range index', () => {
+ const outputSize = model.getOutputSize();
+ assert.throws(
+ () => { model.getOutputElementType(outputSize); },
+ /^Error: /,
+ 'Should throw for out-of-range index'
+ );
+ });
});
-});
-describe('Model.clone()', () => {
- it('should return an object of type model', () => {
- assert.ok(clonedModel instanceof ov.Model, 'clone() should return a model');
- });
+ describe('Model.clone()', () => {
+ it('should return an object of type model', () => {
+ assert.ok(clonedModel instanceof ov.Model, 'clone() should return a model');
+ });
- it('should return a model that is a clone of the calling model', () => {
- assert.deepStrictEqual(clonedModel, model, "Cloned Model should be exactly equal to the calling model");
- });
-
- it('should not accept any arguments', () => {
- assert.throws(
- () => model.clone("Unexpected argument").then(),
- /'clone' method called with incorrect parameters./
- );
+ it('should return a model that is a clone of the calling model', () => {
+ assert.deepStrictEqual(clonedModel, model, 'Cloned Model should be exactly equal to the calling model');
+ });
+
+ it('should not accept any arguments', () => {
+ assert.throws(
+ () => model.clone('Unexpected argument').then(),
+ /'clone' method called with incorrect parameters./
+ );
+ });
});
+
});
diff --git a/src/bindings/js/node/tests/unit/partial_shape.test.js b/src/bindings/js/node/tests/unit/partial_shape.test.js
index 98f7d372ce8..e46af099f03 100644
--- a/src/bindings/js/node/tests/unit/partial_shape.test.js
+++ b/src/bindings/js/node/tests/unit/partial_shape.test.js
@@ -9,46 +9,46 @@ const { describe, it } = require('node:test');
const staticShape = '1, 3, 224, 224';
const dynamicShape = '?, -1, 1..3, 224';
-describe('PartialShape', () => {
- it('Allows create empty shape', () => {
+describe('ov.PartialShape tests', () => {
+ it('allows create empty shape', () => {
const partialShape = new ov.PartialShape();
assert.strictEqual(partialShape.toString(), '[]');
});
- it('Should detect static shape', () => {
+ it('should detect static shape', () => {
const partialShape = new ov.PartialShape(staticShape);
assert.ok(partialShape.isStatic());
});
- it('Should detect dynamic shape', () => {
+ it('should detect dynamic shape', () => {
const partialShape = new ov.PartialShape(dynamicShape);
assert.strictEqual(partialShape.isStatic(), false);
});
- it('Should return shape as string for static shape', () => {
+ it('should return shape as string for static shape', () => {
const partialShape = new ov.PartialShape(staticShape);
assert.strictEqual(partialShape.toString(), '[1,3,224,224]');
});
- it('Should return shape as string for dynamic shape', () => {
+ it('should return shape as string for dynamic shape', () => {
const partialShape = new ov.PartialShape(dynamicShape);
assert.strictEqual(partialShape.toString(), '[?,?,1..3,224]');
});
- it('Should return array with dimensions for dynamic shape', () => {
+ it('should return array with dimensions for dynamic shape', () => {
const partialShape = new ov.PartialShape(staticShape);
- assert.deepStrictEqual(partialShape.getDimensions(), [1,3,224,224]);
+ assert.deepStrictEqual(partialShape.getDimensions(), [1, 3, 224, 224]);
});
- it('Should return array with dimensions for dynamic shape', () => {
+ it('should return array with dimensions for dynamic shape', () => {
const partialShape = new ov.PartialShape(dynamicShape);
- assert.deepStrictEqual(partialShape.getDimensions(), [-1,-1,[1,3],224]);
+ assert.deepStrictEqual(partialShape.getDimensions(), [-1, -1, [1, 3], 224]);
});
});
diff --git a/src/bindings/js/node/tests/unit/pre_post_processor.test.js b/src/bindings/js/node/tests/unit/pre_post_processor.test.js
index a4570ce5fdd..f3068f52581 100644
--- a/src/bindings/js/node/tests/unit/pre_post_processor.test.js
+++ b/src/bindings/js/node/tests/unit/pre_post_processor.test.js
@@ -4,161 +4,167 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
+const { describe, it, before } = require('node:test');
+const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
-const testXml = getModelPath().xml;
-const core = new ov.Core();
-const model = core.readModelSync(testXml);
+describe('ov.preprocess.PrePostProcessor tests', () => {
-describe('PrePostProcess', () => {
-
- it('input() ', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input());
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
});
- it('input(size_t input_index)', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0));
- });
+ const testXml = getModelPath().xml;
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
- it('input(const std::string& tensor_name)', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input('data'));
- });
+ describe('PrePostProcess', () => {
- it('output() ', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).output());
- });
+ it('input() ', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input());
+ });
- it('output(size_t output_index)', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).output(0));
- });
+ it('input(size_t input_index)', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0));
+ });
- it('output(const std::string& tensor_name)', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).output('fc_out'));
- });
+ it('input(const std::string& tensor_name)', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input('data'));
+ });
-});
+ it('output() ', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).output());
+ });
-describe('InputInfo', () => {
- it('tensor()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor());
- });
+ it('output(size_t output_index)', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).output(0));
+ });
- it('preprocess()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).preprocess());
- });
+ it('output(const std::string& tensor_name)', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).output('fc_out'));
+ });
- it('model()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).model());
});
- it('tensor(param) throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor(0),
+ describe('InputInfo', () => {
+ it('tensor()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor());
+ });
+
+ it('preprocess()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).preprocess());
+ });
+
+ it('model()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).model());
+ });
+
+ it('tensor(param) throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor(0),
/Function does not take any parameters./);
- });
+ });
- it('preprocess(param) throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).preprocess(0),
+ it('preprocess(param) throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).preprocess(0),
/Function does not take any parameters./);
- });
+ });
- it('model(param) throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).model(0),
+ it('model(param) throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).model(0),
/Function does not take any parameters./);
- });
+ });
- it('tensor().setElementType()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType(ov.element.u8));
- });
+ it('tensor().setElementType()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType(ov.element.u8));
+ });
- it('tensor().setElementType() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType(),
+ it('tensor().setElementType() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType(),
/Wrong number of parameters./);
- });
+ });
- it('tensor().setElementType() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType('invalidType'),
+ it('tensor().setElementType() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setElementType('invalidType'),
/Cannot create ov::element::Type/);
- });
+ });
- it('tensor().SetShape()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setShape([1, 10]));
- });
+ it('tensor().SetShape()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setShape([1, 10]));
+ });
- it('tensor().SetShape() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setShape(),
+ it('tensor().SetShape() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setShape(),
/Wrong number of parameters./);
- });
+ });
- it('tensor().setLayout()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setLayout('NHWC'));
- });
+ it('tensor().setLayout()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setLayout('NHWC'));
+ });
- it('tensor().setLayout() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).tensor().setLayout(),
+ it('tensor().setLayout() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).tensor().setLayout(),
/Wrong number of parameters./);
- });
+ });
- it('preprocess().resize()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(
- ov.preprocess.resizeAlgorithm.RESIZE_LINEAR,
- ));
- });
+ it('preprocess().resize()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(
+ ov.preprocess.resizeAlgorithm.RESIZE_LINEAR,
+ ));
+ });
- it('preprocess().resize() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(
- ov.preprocess.resizeAlgorithm.RESIZE_LINEAR, 'extraArg',
- ),
+ it('preprocess().resize() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(
+ ov.preprocess.resizeAlgorithm.RESIZE_LINEAR, 'extraArg',
+ ),
/Wrong number of parameters./);
- });
+ });
- it('preprocess().resize() no arg throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(),
+ it('preprocess().resize() no arg throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).preprocess().resize(),
/Wrong number of parameters./);
- });
+ });
- it('model().setLayout()', () => {
- assert.doesNotThrow(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('NCHW'));
- });
+ it('model().setLayout()', () => {
+ assert.doesNotThrow(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('NCHW'));
+ });
- it('model().setLayout() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('NCHW', 'extraArg'),
+ it('model().setLayout() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('NCHW', 'extraArg'),
/Wrong number of parameters./);
- });
+ });
- it('model().setLayout() throws', () => {
- assert.throws(() =>
- new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('invalidLayout')
- );
- });
+ it('model().setLayout() throws', () => {
+ assert.throws(() =>
+ new ov.preprocess.PrePostProcessor(model).input(0).model().setLayout('invalidLayout')
+ );
+ });
-});
+ });
-describe('OutputInfo', () => {
+ describe('OutputInfo', () => {
it('tensor()', () => {
assert.doesNotThrow(() =>
new ov.preprocess.PrePostProcessor(model).output(0).tensor());
@@ -167,7 +173,7 @@ describe('OutputInfo', () => {
it('tensor(param) throws', () => {
assert.throws(() =>
new ov.preprocess.PrePostProcessor(model).output(0).tensor(0),
- /Function does not take any parameters./);
+ /Function does not take any parameters./);
});
it('tensor().setElementType()', () => {
@@ -178,13 +184,13 @@ describe('OutputInfo', () => {
it('tensor().setElementType() throws', () => {
assert.throws(() =>
new ov.preprocess.PrePostProcessor(model).output(0).tensor().setElementType(),
- /Wrong number of parameters./);
+ /Wrong number of parameters./);
});
it('tensor().setElementType() throws', () => {
assert.throws(() =>
new ov.preprocess.PrePostProcessor(model).output(0).tensor().setElementType('invalidType'),
- /Cannot create ov::element::Type/);
+ /Cannot create ov::element::Type/);
});
it('tensor().setLayout()', () => {
@@ -195,7 +201,9 @@ describe('OutputInfo', () => {
it('tensor().setLayout() throws', () => {
assert.throws(() =>
new ov.preprocess.PrePostProcessor(model).output(0).tensor().setLayout(),
- /Wrong number of parameters./);
+ /Wrong number of parameters./);
});
});
+
+});
diff --git a/src/bindings/js/node/tests/unit/read_model.test.js b/src/bindings/js/node/tests/unit/read_model.test.js
index dbc9fc2e876..47fc584fe54 100644
--- a/src/bindings/js/node/tests/unit/read_model.test.js
+++ b/src/bindings/js/node/tests/unit/read_model.test.js
@@ -5,81 +5,90 @@
const fs = require('node:fs');
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
-const { getModelPath } = require('./utils.js');
+const { describe, it, before } = require('node:test');
+const { testModels, isModelAvailable, getModelPath } = require('./utils.js');
const { xml: modelPath, bin: weightsPath } = getModelPath();
-const modelFile = fs.readFileSync(modelPath);
-const modelStr = fs.readFileSync(modelPath, 'utf8');
-const weightsFile = fs.readFileSync(weightsPath);
-const weightsTensor = new ov.Tensor(ov.element.u8, [weightsFile.buffer.byteLength], new Uint8Array(weightsFile.buffer));
-
-const core = new ov.Core();
-
-describe('Core.readModeSync', () => {
- it('readModeSync(xmlPath) ', () => {
- const model = core.readModelSync(modelPath);
- assert.ok(model instanceof ov.Model);
- assert.equal(model.inputs.length, 1);
- });
- it('readModeSync(xmlPath, weightsPath) ', () => {
- const model = core.readModelSync(modelPath, weightsPath);
- assert.ok(model instanceof ov.Model);
- assert.equal(model.inputs.length, 1);
- });
+describe('Tests for reading model.', () => {
- it('readModeSync throws', () => {
- assert.throws(
- () => core.readModelSync(core),
- /'readModelSync' method called with incorrect parameters./,
- )
+ before(async () => {
+ await isModelAvailable(testModels.testModelFP32);
});
- it('readModelSync(modelString, weightsTensor) ', () => {
- const model = core.readModelSync(
- modelStr,
- weightsTensor,
- );
- assert.ok(model instanceof ov.Model);
- assert.equal(model.inputs.length, 1);
- });
+ const modelFile = fs.readFileSync(modelPath);
+ const modelStr = fs.readFileSync(modelPath, 'utf8');
+ const weightsFile = fs.readFileSync(weightsPath);
+ const weightsTensor = new ov.Tensor(ov.element.u8, [weightsFile.buffer.byteLength], new Uint8Array(weightsFile.buffer));
- it('readModelSync(modelUint8ArrayBuffer, weightsUint8ArrayBuffer) ', () => {
- const model = core.readModelSync(
- new Uint8Array(modelFile.buffer),
- new Uint8Array(weightsFile.buffer),
- );
- assert.ok(model instanceof ov.Model);
- assert.equal(model.inputs.length, 1);
- });
-});
+ const core = new ov.Core();
-describe('Core.readModel', () => {
- it('readModel(xmlPath) ', async () => {
- const model = await core.readModel(modelPath);
- assert.equal(model.inputs.length, 1);
- });
+ describe('Core.readModeSync', () => {
+ it('readModeSync(xmlPath) ', () => {
+ const model = core.readModelSync(modelPath);
+ assert.ok(model instanceof ov.Model);
+ assert.equal(model.inputs.length, 1);
+ });
- it('readModel(xmlPath, weightsPath) ', async () => {
- const model = await core.readModel(modelPath, weightsPath);
- assert.equal(model.inputs.length, 1);
- });
+ it('readModeSync(xmlPath, weightsPath) ', () => {
+ const model = core.readModelSync(modelPath, weightsPath);
+ assert.ok(model instanceof ov.Model);
+ assert.equal(model.inputs.length, 1);
+ });
- it('readModel(modelString, weightsTensor) ', async () => {
- const model = await core.readModel(
- modelStr,
- weightsTensor,
- );
- assert.ok(model instanceof ov.Model);
- assert.equal(model.inputs.length, 1);
+ it('readModeSync throws', () => {
+ assert.throws(
+ () => core.readModelSync(core),
+ /'readModelSync' method called with incorrect parameters./,
+ );
+ });
+
+ it('readModelSync(modelString, weightsTensor) ', () => {
+ const model = core.readModelSync(
+ modelStr,
+ weightsTensor,
+ );
+ assert.ok(model instanceof ov.Model);
+ assert.equal(model.inputs.length, 1);
+ });
+
+ it('readModelSync(modelUint8ArrayBuffer, weightsUint8ArrayBuffer) ', () => {
+ const model = core.readModelSync(
+ new Uint8Array(modelFile.buffer),
+ new Uint8Array(weightsFile.buffer),
+ );
+ assert.ok(model instanceof ov.Model);
+ assert.equal(model.inputs.length, 1);
+ });
});
- it('readModel(modelUint8ArrayBuffer, weightsUint8ArrayBuffer) ', async () => {
- const model = await core.readModel(
- new Uint8Array(modelFile.buffer),
- new Uint8Array(weightsFile.buffer),
- );
- assert.equal(model.inputs.length, 1);
+ describe('Core.readModel', () => {
+ it('readModel(xmlPath) ', async () => {
+ const model = await core.readModel(modelPath);
+ assert.equal(model.inputs.length, 1);
+ });
+
+ it('readModel(xmlPath, weightsPath) ', async () => {
+ const model = await core.readModel(modelPath, weightsPath);
+ assert.equal(model.inputs.length, 1);
+ });
+
+ it('readModel(modelString, weightsTensor) ', async () => {
+ const model = await core.readModel(
+ modelStr,
+ weightsTensor,
+ );
+ assert.ok(model instanceof ov.Model);
+ assert.equal(model.inputs.length, 1);
+ });
+
+ it('readModel(modelUint8ArrayBuffer, weightsUint8ArrayBuffer) ', async () => {
+ const model = await core.readModel(
+ new Uint8Array(modelFile.buffer),
+ new Uint8Array(weightsFile.buffer),
+ );
+ assert.equal(model.inputs.length, 1);
+ });
});
+
});
diff --git a/src/bindings/js/node/tests/unit/setup.js b/src/bindings/js/node/tests/unit/setup.js
new file mode 100644
index 00000000000..b4885d24157
--- /dev/null
+++ b/src/bindings/js/node/tests/unit/setup.js
@@ -0,0 +1,9 @@
+const { testModels, downloadTestModel } = require('./utils.js');
+
+if (require.main === module) {
+ main();
+}
+
+async function main() {
+ await downloadTestModel(testModels.testModelFP32);
+}
diff --git a/src/bindings/js/node/tests/unit/tensor.test.js b/src/bindings/js/node/tests/unit/tensor.test.js
index 79e0a66a9cd..45d974f54cd 100644
--- a/src/bindings/js/node/tests/unit/tensor.test.js
+++ b/src/bindings/js/node/tests/unit/tensor.test.js
@@ -7,243 +7,246 @@ const assert = require('assert');
const { test, describe, it } = require('node:test');
const getRandomBigInt = require('random-bigint');
-const shape = [1, 3, 224, 224];
-const elemNum = 1 * 3 * 224 * 224;
-const data = Float32Array.from({ length: elemNum }, () => Math.random() );
-const params = [
- [ov.element.i8, 'i8', Int8Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u8, 'u8', Uint8Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i16, 'i16', Int16Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u16, 'u16', Uint16Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i32, 'i32', Int32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u32, 'u32', Uint32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.f32, 'f32', Float32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.f64, 'f64', Float64Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i64, 'i64', BigInt64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
- [ov.element.u64, 'u64', BigUint64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
-];
-
-test('Test for number of arguments in tensor', () => {
- assert.throws( () => new ov.Tensor(ov.element.f32, shape, data, params),
- {message: /Invalid number of arguments for Tensor constructor./});
-});
-
-describe('Tensor without data parameters', () => {
- it('Tensor should have array with zeros and numbers of elements according to the shape', () => {
- const tensor = new ov.Tensor(ov.element.f32, shape);
- assert.strictEqual(tensor.data.length, elemNum);
+describe('ov.Tensor tests', () => {
+
+ const shape = [1, 3, 224, 224];
+ const elemNum = 1 * 3 * 224 * 224;
+ const data = Float32Array.from({ length: elemNum }, () => Math.random() );
+ const params = [
+ [ov.element.i8, 'i8', Int8Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u8, 'u8', Uint8Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i16, 'i16', Int16Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u16, 'u16', Uint16Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i32, 'i32', Int32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u32, 'u32', Uint32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.f32, 'f32', Float32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.f64, 'f64', Float64Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i64, 'i64', BigInt64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
+ [ov.element.u64, 'u64', BigUint64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
+ ];
+
+ test('Test for number of arguments in tensor', () => {
+ assert.throws( () => new ov.Tensor(ov.element.f32, shape, data, params),
+ {message: /Invalid number of arguments for Tensor constructor./});
+ });
+
+ describe('Tensor without data parameters', () => {
+ it('Tensor should have array with zeros and numbers of elements according to the shape', () => {
+ const tensor = new ov.Tensor(ov.element.f32, shape);
+ assert.strictEqual(tensor.data.length, elemNum);
+ });
});
-});
-describe('Tensor data', () => {
+ describe('Tensor data', () => {
- params.forEach(([type, stringType, data]) => {
- it(`Set tensor data with ${stringType} element type`, () => {
- const tensor = new ov.Tensor(type, shape, data);
- assert.deepStrictEqual(tensor.data, data);
+ params.forEach(([type, stringType, data]) => {
+ it(`set tensor data with ${stringType} element type`, () => {
+ const tensor = new ov.Tensor(type, shape, data);
+ assert.deepStrictEqual(tensor.data, data);
+ });
});
- });
- it('Create string tensor', () => {
- const str_arr = ['text', 'more text', 'even more text'];
- const tensor = new ov.Tensor(str_arr);
- assert.deepStrictEqual(tensor.data, str_arr);
- });
+ it('create string tensor', () => {
+ const str_arr = ['text', 'more text', 'even more text'];
+ const tensor = new ov.Tensor(str_arr);
+ assert.deepStrictEqual(tensor.data, str_arr);
+ });
- it('Create string tensor', () => {
- const str_arr = ['text', 'more text', 'even more text'];
- const tensor = new ov.Tensor(str_arr);
- assert.deepStrictEqual(tensor.data, str_arr);
- });
+ it('create string tensor', () => {
+ const str_arr = ['text', 'more text', 'even more text'];
+ const tensor = new ov.Tensor(str_arr);
+ assert.deepStrictEqual(tensor.data, str_arr);
+ });
- it('String tensor - passed array does not contain string elements', () => {
- const str_arr = ['text', true];
- assert.throws(() => { new ov.Tensor(str_arr);},
- /The array passed to create string tensor must contain only strings./
- );
- });
+ it('string tensor - passed array does not contain string elements', () => {
+ const str_arr = ['text', true];
+ assert.throws(() => { new ov.Tensor(str_arr);},
+ /The array passed to create string tensor must contain only strings./
+ );
+ });
- it('Set string tensor data', () => {
- const str_arr = ['H', 'e', 'l', 'l', 'o'];
- const tensor = new ov.Tensor(ov.element.string, [1, 1, 1, 5]);
- tensor.data = str_arr;
- assert.deepStrictEqual(tensor.data, str_arr);
- });
+ it('set string tensor data', () => {
+ const str_arr = ['H', 'e', 'l', 'l', 'o'];
+ const tensor = new ov.Tensor(ov.element.string, [1, 1, 1, 5]);
+ tensor.data = str_arr;
+ assert.deepStrictEqual(tensor.data, str_arr);
+ });
- it('Test tensor getData()', () => {
- const tensor = new ov.Tensor(ov.element.f32, shape, data);
- assert.deepStrictEqual(tensor.getData(), data);
- });
+ it('test tensor getData()', () => {
+ const tensor = new ov.Tensor(ov.element.f32, shape, data);
+ assert.deepStrictEqual(tensor.getData(), data);
+ });
- it('Test tensor.data setter - different element type throws', () => {
- const float64_data = Float64Array.from([1, 2, 3] );
- const tensor = new ov.Tensor(ov.element.f32, [1, 3]);
- assert.throws(() => {
- tensor.data = float64_data;},
- /Passed array must have the same size as the Tensor!/
- );
- });
+ it('test tensor.data setter - different element type throws', () => {
+ const float64_data = Float64Array.from([1, 2, 3] );
+ const tensor = new ov.Tensor(ov.element.f32, [1, 3]);
+ assert.throws(() => {
+ tensor.data = float64_data;},
+ /Passed array must have the same size as the Tensor!/
+ );
+ });
- it('Test tensor.data setter - different element length throws', () => {
- const float64_data = Float64Array.from([1, 2, 3] );
- const tensor = new ov.Tensor(ov.element.f64, [1, 2]);
- assert.throws(() => {
- tensor.data = float64_data;},
- /Passed array must have the same size as the Tensor!/
- );
- });
+ it('test tensor.data setter - different element length throws', () => {
+ const float64_data = Float64Array.from([1, 2, 3] );
+ const tensor = new ov.Tensor(ov.element.f64, [1, 2]);
+ assert.throws(() => {
+ tensor.data = float64_data;},
+ /Passed array must have the same size as the Tensor!/
+ );
+ });
- it('Test tensor.data setter', () => {
- const testString = 'test';
- const tensor = new ov.Tensor(ov.element.f64, [1, 2]);
- assert.throws(() => {
- tensor.data = testString;},
- /Passed argument must be TypedArray, or Array if the tensor type is string./
- );
- });
+ it('test tensor.data setter', () => {
+ const testString = 'test';
+ const tensor = new ov.Tensor(ov.element.f64, [1, 2]);
+ assert.throws(() => {
+ tensor.data = testString;},
+ /Passed argument must be TypedArray, or Array if the tensor type is string./
+ );
+ });
- it('Test tensor.data setter', () => {
- const tensor = new ov.Tensor(ov.element.f32, shape);
- tensor.data = data;
- assert.deepStrictEqual(tensor.getData(), data);
- });
+ it('test tensor.data setter', () => {
+ const tensor = new ov.Tensor(ov.element.f32, shape);
+ tensor.data = data;
+ assert.deepStrictEqual(tensor.getData(), data);
+ });
- it('Set tensor data with Float32Array created from ArrayBuffer', () => {
- const size = elemNum * 4;
- const buffer = new ArrayBuffer(size);
- const view = new Float32Array(buffer);
- view.set(data);
- const tensor = new ov.Tensor(ov.element.f32, shape, view);
- assert.deepStrictEqual(tensor.data, data);
- });
+ it('set tensor data with Float32Array created from ArrayBuffer', () => {
+ const size = elemNum * 4;
+ const buffer = new ArrayBuffer(size);
+ const view = new Float32Array(buffer);
+ view.set(data);
+ const tensor = new ov.Tensor(ov.element.f32, shape, view);
+ assert.deepStrictEqual(tensor.data, data);
+ });
- it('Set tensor data with too big Float32Array', () => {
- const size = elemNum * 8;
- const buffer = new ArrayBuffer(size);
- const view = new Float32Array(buffer);
- view.set(data);
- assert.throws( () => new ov.Tensor(ov.element.f32, shape, view),
- {message: /Memory allocated using shape and element::type mismatch/});
- });
+ it('set tensor data with too big Float32Array', () => {
+ const size = elemNum * 8;
+ const buffer = new ArrayBuffer(size);
+ const view = new Float32Array(buffer);
+ view.set(data);
+ assert.throws( () => new ov.Tensor(ov.element.f32, shape, view),
+ {message: /Memory allocated using shape and element::type mismatch/});
+ });
- it('Third argument of a tensor cannot be an ArrayBuffer', () => {
- assert.throws(
- () => new ov.Tensor(ov.element.f32, shape, new ArrayBuffer(1234)),
- {message: /Third argument of a tensor must be TypedArray./});
- });
+ it('third argument of a tensor cannot be an ArrayBuffer', () => {
+ assert.throws(
+ () => new ov.Tensor(ov.element.f32, shape, new ArrayBuffer(1234)),
+ {message: /Third argument of a tensor must be TypedArray./});
+ });
- it('Third argument of a tensor cannot be an array object', () => {
- assert.throws(
- () => new ov.Tensor(ov.element.f32, shape, [1, 2, 3, 4]),
- {message: /Third argument of a tensor must be TypedArray./});
+ it('third argument of a tensor cannot be an array object', () => {
+ assert.throws(
+ () => new ov.Tensor(ov.element.f32, shape, [1, 2, 3, 4]),
+ {message: /Third argument of a tensor must be TypedArray./});
+ });
});
-});
-describe('Tensor shape', () => {
+ describe('Tensor shape', () => {
- it('ov::Shape from an array object', () => {
- const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data);
- assert.deepStrictEqual(tensor.getShape(), [1, 3, 224, 224]);
- });
+ it('ov::Shape from an array object', () => {
+ const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data);
+ assert.deepStrictEqual(tensor.getShape(), [1, 3, 224, 224]);
+ });
- it('ov::Shape from an array object with floating point numbers', () => {
- const tensor =
+ it('ov::Shape from an array object with floating point numbers', () => {
+ const tensor =
new ov.Tensor(ov.element.f32, [1, 3.0, 224.8, 224.4], data);
- assert.deepStrictEqual(tensor.getShape(), [1, 3, 224, 224]);
- });
+ assert.deepStrictEqual(tensor.getShape(), [1, 3, 224, 224]);
+ });
- it('Array argument to create ov::Shape can only contain numbers', () => {
- assert.throws(
- () => new ov.Tensor(ov.element.f32, ['1', 3, 224, 224], data),
- {message: /Passed array must contain only numbers/});
- });
+ it('array argument to create ov::Shape can only contain numbers', () => {
+ assert.throws(
+ () => new ov.Tensor(ov.element.f32, ['1', 3, 224, 224], data),
+ {message: /Passed array must contain only numbers/});
+ });
- it('ov::Shape from TypedArray -> Int32Array', () => {
- const shp = Int32Array.from([1, 224, 224, 3]);
- const tensor = new ov.Tensor(ov.element.f32, shp, data);
- assert.deepStrictEqual(tensor.getShape(), [1, 224, 224, 3]);
- });
+ it('ov::Shape from TypedArray -> Int32Array', () => {
+ const shp = Int32Array.from([1, 224, 224, 3]);
+ const tensor = new ov.Tensor(ov.element.f32, shp, data);
+ assert.deepStrictEqual(tensor.getShape(), [1, 224, 224, 3]);
+ });
- it('Cannot create ov::Shape from Float32Array', () => {
- const shape = Float32Array.from([1, 224, 224, 3]);
- assert.throws(
- () => new ov.Tensor(ov.element.f32, shape, data),
- /Passed argument must be an Int32Array or a Uint32Array./
- );
- });
+ it('cannot create ov::Shape from Float32Array', () => {
+ const shape = Float32Array.from([1, 224, 224, 3]);
+ assert.throws(
+ () => new ov.Tensor(ov.element.f32, shape, data),
+ /Passed argument must be an Int32Array or a Uint32Array./
+ );
+ });
- it('Cannot create ov::Shape from ArrayBuffer', () => {
- const shape = Int32Array.from([1, 224, 224, 3]);
- assert.throws(
- () => new ov.Tensor(ov.element.f32, shape.buffer, data),
- /Passed argument must be of type Array or TypedArray./
- );
- });
+ it('cannot create ov::Shape from ArrayBuffer', () => {
+ const shape = Int32Array.from([1, 224, 224, 3]);
+ assert.throws(
+ () => new ov.Tensor(ov.element.f32, shape.buffer, data),
+ /Passed argument must be of type Array or TypedArray./
+ );
+ });
- it('getShape() method does not accept parameters', () => {
- const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data);
- assert.throws(
- () => tensor.getShape(1, 2, 3),
- { message: 'No parameters are allowed for the getShape() method.'}
- );
+ it('getShape() method does not accept parameters', () => {
+ const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data);
+ assert.throws(
+ () => tensor.getShape(1, 2, 3),
+ { message: 'No parameters are allowed for the getShape() method.'}
+ );
+ });
});
-});
-describe('Tensor element type', () => {
- params.forEach(([elemType, val]) => {
- it(`Comparison of ov.element.${elemType} to string ${val}`, () => {
- assert.strictEqual(elemType, val);
+ describe('Tensor element type', () => {
+ params.forEach(([elemType, val]) => {
+ it(`comparison of ov.element.${elemType} to string ${val}`, () => {
+ assert.strictEqual(elemType, val);
+ });
});
- });
- params.forEach(([elemType, , data]) => {
- it(`Comparison of ov.element ${elemType} got from Tensor object`, () => {
- const tensor = new ov.Tensor(elemType, shape, data);
- assert.strictEqual(tensor.getElementType(), elemType);
+ params.forEach(([elemType, , data]) => {
+ it(`comparison of ov.element ${elemType} got from Tensor object`, () => {
+ const tensor = new ov.Tensor(elemType, shape, data);
+ assert.strictEqual(tensor.getElementType(), elemType);
+ });
});
});
-});
-describe('Tensor getSize', () => {
+ describe('Tensor getSize', () => {
- it('getSize returns the correct total number of elements', () => {
- const tensor = new ov.Tensor(ov.element.f32, shape, data);
- const expectedSize = shape.reduce((acc, dim) => acc * dim, 1);
- assert.strictEqual(tensor.getSize(), expectedSize);
- });
+ it('getSize returns the correct total number of elements', () => {
+ const tensor = new ov.Tensor(ov.element.f32, shape, data);
+ const expectedSize = shape.reduce((acc, dim) => acc * dim, 1);
+ assert.strictEqual(tensor.getSize(), expectedSize);
+ });
- it('getSize should throw an error if arguments are provided', () => {
- const tensor = new ov.Tensor(ov.element.f32, shape, data);
- assert.throws(
- () => tensor.getSize(1),
- { message: 'getSize() does not accept any arguments.' }
- );
+ it('getSize should throw an error if arguments are provided', () => {
+ const tensor = new ov.Tensor(ov.element.f32, shape, data);
+ assert.throws(
+ () => tensor.getSize(1),
+ { message: 'getSize() does not accept any arguments.' }
+ );
+ });
});
-});
-describe('Tensor getSize for various shapes', () => {
+ describe('Tensor getSize for various shapes', () => {
- it('calculates size correctly for a common image data shape [3, 224, 224]', () => {
- const shape = [3, 224, 224];
- const expectedSize = 3*224*224;
- const tensorData = new Float32Array(expectedSize).fill(0);
- const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
- assert.strictEqual(tensor.getSize(), expectedSize);
- });
+ it('calculates size correctly for a common image data shape [3, 224, 224]', () => {
+ const shape = [3, 224, 224];
+ const expectedSize = 3*224*224;
+ const tensorData = new Float32Array(expectedSize).fill(0);
+ const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
+ assert.strictEqual(tensor.getSize(), expectedSize);
+ });
- it('calculates size correctly for a scalar wrapped in a tensor [1]', () => {
- const shape = [1];
- const expectedSize = 1;
- const tensorData = new Float32Array(expectedSize).fill(0);
- const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
- assert.strictEqual(tensor.getSize(), expectedSize);
- });
+ it('calculates size correctly for a scalar wrapped in a tensor [1]', () => {
+ const shape = [1];
+ const expectedSize = 1;
+ const tensorData = new Float32Array(expectedSize).fill(0);
+ const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
+ assert.strictEqual(tensor.getSize(), expectedSize);
+ });
- it('calculates size correctly for a vector [10]', () => {
- const shape = [10];
- const expectedSize = 10;
- const tensorData = new Float32Array(expectedSize).fill(0);
- const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
- assert.strictEqual(tensor.getSize(), expectedSize);
+ it('calculates size correctly for a vector [10]', () => {
+ const shape = [10];
+ const expectedSize = 10;
+ const tensorData = new Float32Array(expectedSize).fill(0);
+ const tensor = new ov.Tensor(ov.element.f32, shape, tensorData);
+ assert.strictEqual(tensor.getSize(), expectedSize);
+ });
});
});
diff --git a/src/bindings/js/node/tests/unit/test_models/test_model_fp32.bin b/src/bindings/js/node/tests/unit/test_models/test_model_fp32.bin
deleted file mode 100644
index b5f85e41083..00000000000
Binary files a/src/bindings/js/node/tests/unit/test_models/test_model_fp32.bin and /dev/null differ
diff --git a/src/bindings/js/node/tests/unit/test_models/test_model_fp32.xml b/src/bindings/js/node/tests/unit/test_models/test_model_fp32.xml
deleted file mode 100644
index dcf0cd74b06..00000000000
--- a/src/bindings/js/node/tests/unit/test_models/test_model_fp32.xml
+++ /dev/null
@@ -1,467 +0,0 @@
-<?xml version="1.0" ?>
-<net name="test_model" version="10">
- <layers>
- <layer id="0" name="data" type="Parameter" version="opset1">
- <data element_type="f32" shape="1,3,32,32"/>
- <output>
- <port id="0" precision="FP32">
- <dim>1</dim>
- <dim>3</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </output>
- </layer>
- <layer id="1" name="20/mean/Fused_Mul_614616_const" type="Const" version="opset1">
- <data element_type="f32" offset="0" shape="16,3,5,5" size="4800"/>
- <output>
- <port id="1" precision="FP32">
- <dim>16</dim>
- <dim>3</dim>
- <dim>5</dim>
- <dim>5</dim>
- </port>
- </output>
- </layer>
- <layer id="2" name="19/WithoutBiases" type="Convolution" version="opset1">
- <data dilations="1,1" output_padding="0,0" pads_begin="2,2" pads_end="2,2" strides="1,1"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>3</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- <port id="1">
- <dim>16</dim>
- <dim>3</dim>
- <dim>5</dim>
- <dim>5</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </output>
- </layer>
- <layer id="3" name="data_add_575/copy_const" type="Const" version="opset1">
- <data element_type="f32" offset="4800" shape="1,16,1,1" size="64"/>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>16</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </output>
- </layer>
- <layer id="4" name="19/Fused_Add_" type="Add" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- <port id="1">
- <dim>1</dim>
- <dim>16</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </output>
- </layer>
- <layer id="5" name="21" type="ReLU" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </input>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </output>
- </layer>
- <layer id="6" name="22" type="MaxPool" version="opset1">
- <data kernel="2,2" pads_begin="0,0" pads_end="0,0" rounding_type="floor" strides="2,2"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>16</dim>
- <dim>32</dim>
- <dim>32</dim>
- </port>
- </input>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>16</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- </output>
- </layer>
- <layer id="7" name="onnx_initializer_node_8/Output_0/Data__const" type="Const" version="opset1">
- <data element_type="f32" offset="4864" shape="32,16,5,5" size="51200"/>
- <output>
- <port id="1" precision="FP32">
- <dim>32</dim>
- <dim>16</dim>
- <dim>5</dim>
- <dim>5</dim>
- </port>
- </output>
- </layer>
- <layer id="8" name="23/WithoutBiases" type="Convolution" version="opset1">
- <data dilations="1,1" output_padding="0,0" pads_begin="2,2" pads_end="2,2" strides="1,1"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>16</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- <port id="1">
- <dim>32</dim>
- <dim>16</dim>
- <dim>5</dim>
- <dim>5</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>32</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- </output>
- </layer>
- <layer id="9" name="23/Dims357/copy_const" type="Const" version="opset1">
- <data element_type="f32" offset="56064" shape="1,32,1,1" size="128"/>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>32</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </output>
- </layer>
- <layer id="10" name="23" type="Add" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>32</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- <port id="1">
- <dim>1</dim>
- <dim>32</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>32</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- </output>
- </layer>
- <layer id="11" name="25/mean/Fused_Mul_618620_const" type="Const" version="opset1">
- <data element_type="f32" offset="56192" shape="64,32,3,3" size="73728"/>
- <output>
- <port id="1" precision="FP32">
- <dim>64</dim>
- <dim>32</dim>
- <dim>3</dim>
- <dim>3</dim>
- </port>
- </output>
- </layer>
- <layer id="12" name="24/WithoutBiases" type="Convolution" version="opset1">
- <data dilations="1,1" output_padding="0,0" pads_begin="2,2" pads_end="2,2" strides="1,1"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>32</dim>
- <dim>16</dim>
- <dim>16</dim>
- </port>
- <port id="1">
- <dim>64</dim>
- <dim>32</dim>
- <dim>3</dim>
- <dim>3</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- </output>
- </layer>
- <layer id="13" name="data_add_578583/copy_const" type="Const" version="opset1">
- <data element_type="f32" offset="129920" shape="1,64,1,1" size="256"/>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>64</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </output>
- </layer>
- <layer id="14" name="24/Fused_Add_" type="Add" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- <port id="1">
- <dim>1</dim>
- <dim>64</dim>
- <dim>1</dim>
- <dim>1</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- </output>
- </layer>
- <layer id="15" name="26" type="ReLU" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- </input>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- </output>
- </layer>
- <layer id="16" name="27" type="MaxPool" version="opset1">
- <data kernel="2,2" pads_begin="0,0" pads_end="0,0" rounding_type="floor" strides="2,2"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>64</dim>
- <dim>18</dim>
- <dim>18</dim>
- </port>
- </input>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>64</dim>
- <dim>9</dim>
- <dim>9</dim>
- </port>
- </output>
- </layer>
- <layer id="17" name="28/Reshape/Cast_1955_const" type="Const" version="opset1">
- <data element_type="i64" offset="130176" shape="2" size="16"/>
- <output>
- <port id="1" precision="I64">
- <dim>2</dim>
- </port>
- </output>
- </layer>
- <layer id="18" name="28/Reshape" type="Reshape" version="opset1">
- <data special_zero="True"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>64</dim>
- <dim>9</dim>
- <dim>9</dim>
- </port>
- <port id="1">
- <dim>2</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>5184</dim>
- </port>
- </output>
- </layer>
- <layer id="19" name="onnx_initializer_node_17/Output_0/Data__const" type="Const" version="opset1">
- <data element_type="f32" offset="130192" shape="10,5184" size="207360"/>
- <output>
- <port id="1" precision="FP32">
- <dim>10</dim>
- <dim>5184</dim>
- </port>
- </output>
- </layer>
- <layer id="20" name="29/WithoutBiases" type="MatMul" version="opset1">
- <data transpose_a="0" transpose_b="1"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>5184</dim>
- </port>
- <port id="1">
- <dim>10</dim>
- <dim>5184</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </output>
- </layer>
- <layer id="21" name="onnx_initializer_node_18/Output_0/Data_/copy_const" type="Const" version="opset1">
- <data element_type="f32" offset="337552" shape="1,10" size="40"/>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </output>
- </layer>
- <layer id="22" name="29" type="Add" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- <port id="1">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </input>
- <output>
- <port id="2" precision="FP32">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </output>
- </layer>
- <layer id="23" name="fc_out" type="SoftMax" version="opset1">
- <data axis="1"/>
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </input>
- <output>
- <port id="1" precision="FP32">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </output>
- </layer>
- <layer id="24" name="fc_out/sink_port_0" type="Result" version="opset1">
- <input>
- <port id="0">
- <dim>1</dim>
- <dim>10</dim>
- </port>
- </input>
- </layer>
- </layers>
- <edges>
- <edge from-layer="0" from-port="0" to-layer="2" to-port="0"/>
- <edge from-layer="1" from-port="1" to-layer="2" to-port="1"/>
- <edge from-layer="2" from-port="2" to-layer="4" to-port="0"/>
- <edge from-layer="3" from-port="1" to-layer="4" to-port="1"/>
- <edge from-layer="4" from-port="2" to-layer="5" to-port="0"/>
- <edge from-layer="5" from-port="1" to-layer="6" to-port="0"/>
- <edge from-layer="6" from-port="1" to-layer="8" to-port="0"/>
- <edge from-layer="7" from-port="1" to-layer="8" to-port="1"/>
- <edge from-layer="8" from-port="2" to-layer="10" to-port="0"/>
- <edge from-layer="9" from-port="1" to-layer="10" to-port="1"/>
- <edge from-layer="10" from-port="2" to-layer="12" to-port="0"/>
- <edge from-layer="11" from-port="1" to-layer="12" to-port="1"/>
- <edge from-layer="12" from-port="2" to-layer="14" to-port="0"/>
- <edge from-layer="13" from-port="1" to-layer="14" to-port="1"/>
- <edge from-layer="14" from-port="2" to-layer="15" to-port="0"/>
- <edge from-layer="15" from-port="1" to-layer="16" to-port="0"/>
- <edge from-layer="16" from-port="1" to-layer="18" to-port="0"/>
- <edge from-layer="17" from-port="1" to-layer="18" to-port="1"/>
- <edge from-layer="18" from-port="2" to-layer="20" to-port="0"/>
- <edge from-layer="19" from-port="1" to-layer="20" to-port="1"/>
- <edge from-layer="20" from-port="2" to-layer="22" to-port="0"/>
- <edge from-layer="21" from-port="1" to-layer="22" to-port="1"/>
- <edge from-layer="22" from-port="2" to-layer="23" to-port="0"/>
- <edge from-layer="23" from-port="1" to-layer="24" to-port="0"/>
- </edges>
- <meta_data>
- <MO_version value="unknown version"/>
- <cli_parameters>
- <blobs_as_inputs value="True"/>
- <data_type value="FP32"/>
- <disable_resnet_optimization value="False"/>
- <disable_weights_compression value="False"/>
- <enable_concat_optimization value="False"/>
- <extensions value="DIR"/>
- <framework value="onnx"/>
- <freeze_placeholder_with_value value="{}"/>
- <generate_deprecated_IR_V2 value="False"/>
- <generate_deprecated_IR_V7 value="False"/>
- <generate_experimental_IR_V10 value="True"/>
- <input_model value="DIR/test_model.onnx"/>
- <keep_quantize_ops_in_IR value="True"/>
- <keep_shape_ops value="False"/>
- <log_level value="ERROR"/>
- <mean_scale_values value="{}"/>
- <mean_values value="()"/>
- <model_name value="test_model"/>
- <move_to_preprocess value="False"/>
- <output_dir value="DIR"/>
- <placeholder_data_types value="{}"/>
- <progress value="False"/>
- <reverse_input_channels value="False"/>
- <scale_values value="()"/>
- <silent value="False"/>
- <stream_output value="False"/>
- <unset unset_cli_parameters="batch, disable_fusing, disable_gfusing, finegrain_fusing, input, input_shape, output, placeholder_shapes, scale, transformations_config"/>
- </cli_parameters>
- </meta_data>
-</net>
diff --git a/src/bindings/js/node/tests/unit/utils.js b/src/bindings/js/node/tests/unit/utils.js
index ebe126d6c74..cf541a332b1 100644
--- a/src/bindings/js/node/tests/unit/utils.js
+++ b/src/bindings/js/node/tests/unit/utils.js
@@ -3,15 +3,67 @@
// SPDX-License-Identifier: Apache-2.0
const path = require('path');
+const fs = require('node:fs/promises');
+const { downloadFile, checkIfPathExists } = require('../../scripts/download_runtime');
-module.exports = { getModelPath };
+const modelDir = 'tests/unit/test_models/';
+const testModels = {
+ testModelFP32: {
+ xml: 'test_model_fp32.xml',
+ bin: 'test_model_fp32.bin',
+ xmlURL:
+ 'https://raw.githubusercontent.com/openvinotoolkit/testdata/master/models/test_model/test_model_fp32.xml',
+ binURL:
+ 'https://media.githubusercontent.com/media/openvinotoolkit/testdata/master/models/test_model/test_model_fp32.bin',
+ },
+};
+
+module.exports = {
+ getModelPath,
+ downloadTestModel,
+ isModelAvailable,
+ testModels,
+};
function getModelPath(isFP16=false) {
- const basePath = 'tests/unit/test_models/';
const modelName = `test_model_fp${isFP16 ? 16 : 32}`;
return {
- xml: path.join(basePath, `${modelName}.xml`),
- bin: path.join(basePath, `${modelName}.bin`),
+ xml: path.join(modelDir, `${modelName}.xml`),
+ bin: path.join(modelDir, `${modelName}.bin`),
};
}
+
+async function downloadTestModel(model) {
+ const modelsDir = './tests/unit/test_models';
+ try {
+ const ifModelsDirectoryExists = await checkIfPathExists(modelsDir);
+ if (!ifModelsDirectoryExists) {
+ await fs.mkdir(modelDir);
+ }
+
+ const modelPath = path.join(modelsDir, model.xml);
+ const modelExists = await checkIfPathExists(modelPath);
+ if (modelExists) return;
+
+ const { env } = process;
+ const proxyUrl = env.http_proxy || env.HTTP_PROXY || env.npm_config_proxy;
+
+ await downloadFile(model.xmlURL, modelsDir, model.xml, proxyUrl);
+ await downloadFile(model.binURL, modelsDir, model.bin, proxyUrl);
+ } catch(error) {
+ console.error(`Failed to download the model: ${error}.`);
+ throw error;
+ }
+}
+
+async function isModelAvailable(model) {
+ const baseArtifactsDir = './tests/unit/test_models';
+ const modelPath = path.join(baseArtifactsDir, model.xml);
+ const modelExists = await checkIfPathExists(modelPath);
+ if (modelExists) return;
+
+ console.log('\n\nTestModel cannot be found.\nPlease run `npm run test_setup`.\n\n');
+ process.exit(1);
+
+}