Skip to content

Commit d4aea18

Browse files
committed
lint & format
1 parent f3a52db commit d4aea18

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

js/node/test/standalone/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ These tests verify that the ORT Node.js binding handles various process exit sce
1313
## How It Works
1414

1515
Each test runs in a separate Node.js process to isolate the test environment. Tests use command-line flags to control behavior:
16+
1617
- `--process-exit`: Triggers `process.exit(0)`
1718
- `--throw-exception`: Throws an uncaught exception
1819
- `--release`: Calls `session.release()` before exit

js/node/test/standalone/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import * as assert from 'assert';
66
import * as path from 'path';
77

88
describe('Standalone Process Tests', () => {
9-
109
// Helper function to run test script in a separate process
11-
const runTest = (args: string[] = []): Promise<{code: number, stdout: string, stderr: string}> => {
12-
return new Promise((resolve, reject) => {
10+
const runTest = async (args: string[] = []): Promise<{ code: number; stdout: string; stderr: string }> =>
11+
new Promise((resolve, reject) => {
1312
// Use the compiled main.js file from the lib directory
1413
const testFile = path.join(__dirname, './main.js');
1514

@@ -18,19 +17,18 @@ describe('Standalone Process Tests', () => {
1817
let stdout = '';
1918
let stderr = '';
2019

21-
child.stdout.on('data', (data) => stdout += data.toString());
22-
child.stderr.on('data', (data) => stderr += data.toString());
20+
child.stdout.on('data', (data) => (stdout += data.toString()));
21+
child.stderr.on('data', (data) => (stderr += data.toString()));
2322

2423
child.on('close', (code) => {
2524
resolve({ code: code || 0, stdout, stderr });
2625
});
2726

2827
child.on('error', reject);
2928
});
30-
};
3129

3230
// Helper function to check basic success criteria
33-
const assertSuccess = (result: {code: number, stdout: string, stderr: string}) => {
31+
const assertSuccess = (result: { code: number; stdout: string; stderr: string }) => {
3432
assert.strictEqual(result.code, 0);
3533
assert.ok(result.stdout.includes('SUCCESS: Inference completed'));
3634
assert.ok(!result.stderr.includes('mutex lock failed'));

js/node/test/standalone/main.ts

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,47 @@ import * as path from 'path';
55
const ort = require(path.join(__dirname, '../../'));
66
import * as process from 'process';
77

8-
const modelData = 'CAMSDGJhY2tlbmQtdGVzdDpiChEKAWEKAWISAWMiBk1hdE11bBIOdGVzdF9tYXRtdWxfMmRaEwoBYRIOCgwIARIICgIIAwoCCARaEwoBYhIOCgwIARIICgIIBAoCCANiEwoBYxIOCgwIARIICgIIAwoCCANCAhAJ';
8+
const modelData =
9+
'CAMSDGJhY2tlbmQtdGVzdDpiChEKAWEKAWISAWMiBk1hdE11bBIOdGVzdF9tYXRtdWxfMmRaEwoBYRIOCgwIARIICgIIAwoCCARaEwoBYhIOCgwIARIICgIIBAoCCANiEwoBYxIOCgwIARIICgIIAwoCCANCAhAJ';
910
const shouldProcessExit = process.argv.includes('--process-exit');
1011
const shouldThrowException = process.argv.includes('--throw-exception');
1112
const shouldRelease = process.argv.includes('--release');
1213

1314
async function main() {
14-
try {
15-
const modelBuffer = Buffer.from(modelData, 'base64');
16-
const session = await ort.InferenceSession.create(modelBuffer);
17-
18-
const dataA = Float32Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
19-
const dataB = Float32Array.from([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]);
20-
const tensorA = new ort.Tensor('float32', dataA, [3, 4]);
21-
const tensorB = new ort.Tensor('float32', dataB, [4, 3]);
22-
23-
const results = await session.run({ a: tensorA, b: tensorB });
24-
console.log('SUCCESS: Inference completed');
25-
console.log(`Result: ${results.c.data}`);
26-
27-
if (shouldRelease) {
28-
await session.release();
29-
console.log('Session released');
30-
} else {
31-
console.log('Session NOT released (testing cleanup behavior)');
32-
}
33-
34-
if (shouldThrowException) {
35-
setTimeout(() => { throw new Error('Test exception'); }, 10);
36-
return;
37-
}
38-
39-
if (shouldProcessExit) {
40-
process.exit(0);
41-
}
42-
} catch (e) {
43-
console.error(`ERROR: ${e}`);
44-
process.exit(1);
15+
try {
16+
const modelBuffer = Buffer.from(modelData, 'base64');
17+
const session = await ort.InferenceSession.create(modelBuffer);
18+
19+
const dataA = Float32Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
20+
const dataB = Float32Array.from([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]);
21+
const tensorA = new ort.Tensor('float32', dataA, [3, 4]);
22+
const tensorB = new ort.Tensor('float32', dataB, [4, 3]);
23+
24+
const results = await session.run({ a: tensorA, b: tensorB });
25+
console.log('SUCCESS: Inference completed');
26+
console.log(`Result: ${results.c.data}`);
27+
28+
if (shouldRelease) {
29+
await session.release();
30+
console.log('Session released');
31+
} else {
32+
console.log('Session NOT released (testing cleanup behavior)');
4533
}
34+
35+
if (shouldThrowException) {
36+
setTimeout(() => {
37+
throw new Error('Test exception');
38+
}, 10);
39+
return;
40+
}
41+
42+
if (shouldProcessExit) {
43+
process.exit(0);
44+
}
45+
} catch (e) {
46+
console.error(`ERROR: ${e}`);
47+
process.exit(1);
48+
}
4649
}
4750

48-
main();
51+
void main();

0 commit comments

Comments
 (0)