Comparing version 1.1.0 to 1.1.1
@@ -26,5 +26,5 @@ // Copyright 2021 Google LLC | ||
// - Some methods were added and existing ones were modified or deleted to enhance usability. | ||
// - Most methods were deleted, | ||
// - The namespace has been changed from '$' to 'SH'. | ||
// Modified by: jorrit.duin+sh[AT]gmail.com | ||
/** @type {assert} */ | ||
import assert from 'node:assert'; | ||
@@ -31,0 +31,0 @@ import SHDispatch from './SHDispatch.js'; |
import assert from 'node:assert/strict'; | ||
import { jsType } from './SH.js' | ||
const FNC = ['Function', 'AsyncFunction', 'Promise']; | ||
const FNC = ['Function', 'AsyncFunction']; | ||
// Settle async calls in a SYNC function | ||
const SETTLE_ASYNC = 100; | ||
const SETTLE_ASYNC = 50; | ||
/** | ||
* @typedef {(function(): Promise<any>)} AsyncFunction | ||
*/ | ||
/** | ||
* @typedef {Object} testDefinition | ||
* @prop {string} description | ||
* @prop {function|asyncfunction} callback | ||
* @prop {Function|AsyncFunction} callback - syc/ async function | ||
*/ | ||
@@ -28,2 +32,3 @@ | ||
* Get the current time | ||
* used for calculating a duration | ||
* @returns {number} | ||
@@ -36,3 +41,3 @@ */ | ||
/** | ||
* Get the duration | ||
* Get the duration based on a previous gathered start time | ||
* @param {number} start - start time | ||
@@ -81,3 +86,3 @@ * @returns {number} | ||
const errListener = (err) => { | ||
this._handleError(err) | ||
this.#handleError(err) | ||
} | ||
@@ -87,3 +92,3 @@ if (active) { | ||
process.on('uncaughtException', errListener); | ||
this.catchErrors = true; | ||
this.#catchErrors = true; | ||
} | ||
@@ -93,3 +98,3 @@ } else { | ||
process.removeListener('uncaughtException', errListener); | ||
this.catchErrors = false; | ||
this.#catchErrors = false; | ||
} | ||
@@ -103,3 +108,3 @@ } | ||
* @param {string} description | ||
* @param {Function|AsyncFunction|Promise} callback | ||
* @param {Function|AsyncFunction} callback - sync / async function | ||
* @throws Error when conditions are not met | ||
@@ -112,3 +117,3 @@ */ | ||
if (!FNC.includes(jsType(callback))) { | ||
throw new Error(`'callback' should be a (async) function or Promise`) | ||
throw new Error(`'callback' should be a (async) Function`) | ||
} | ||
@@ -143,4 +148,2 @@ this.#tests.push({ description, callback }); | ||
start = start + this.#TO; | ||
} else if (type === 'Promise') { | ||
await Promise.all([cb.callback]); | ||
} else { | ||
@@ -158,3 +161,3 @@ await cb.callback(); | ||
if (error) { | ||
this._handleError(error); | ||
this.#handleError(error); | ||
} | ||
@@ -208,6 +211,8 @@ this.#reports[i] = { description: cb.description, duration }; | ||
/** | ||
* @private | ||
* Handle an error outside the callstack | ||
* for the current test | ||
* @param {Error} | ||
*/ | ||
_handleError(err) { | ||
#handleError(err) { | ||
if (this.#currentTest > -1) { | ||
@@ -214,0 +219,0 @@ // Register this error |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Execute shell commands on Linux-based systems from javascript", | ||
@@ -25,3 +25,5 @@ "main": "lib/SH.js", | ||
"license": "Apache License, Version 2.0", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@types/node": "^22.10.10" | ||
}, | ||
"bugs": { | ||
@@ -52,2 +54,2 @@ "url": "https://codeberg.org/duin/sh/issues" | ||
] | ||
} | ||
} |
@@ -161,10 +161,13 @@ # @j-o-r/sh | ||
}); | ||
test.add('Test is test in a promise', | ||
new Promise((resolve, _reject) => { | ||
test.add('Test is test in async, returning a promise', async () => { | ||
return new Promise((resolve, _reject) => { | ||
assert.strictEqual(jsType(test), 'Test'); | ||
resolve(); | ||
}) | ||
) | ||
await test.run(); | ||
}); | ||
}); | ||
const report = await test.run(); | ||
if (report.errors > 0) { | ||
process.exit(1); | ||
} | ||
// await test.run([0,3]); // only run test 0 and 3 | ||
``` | ||
@@ -171,0 +174,0 @@ |
@@ -90,7 +90,8 @@ /** | ||
* @param {any} fn - Any let type | ||
* @returns {string} The object / let type name | ||
* @returns {string} The "real" object / typeof name | ||
*/ | ||
export function jsType(fn: any): string; | ||
import Test from './Test.js'; | ||
import assert from 'node:assert'; | ||
import SHDispatch from './SHDispatch.js'; | ||
export { Test, assert }; |
@@ -39,3 +39,3 @@ export default SHDispatch; | ||
*/ | ||
env?: any; | ||
env?: NodeJS.ProcessEnv | undefined; | ||
/** | ||
@@ -42,0 +42,0 @@ * - The shell to use for execution. |
@@ -12,3 +12,3 @@ export default SHExecute; | ||
*/ | ||
runSync(payload?: string | undefined): any; | ||
runSync(payload?: string | undefined): import("child_process").SpawnSyncReturns<Buffer> & import("child_process").SpawnSyncReturns<string> & import("child_process").SpawnSyncReturns<string | Buffer>; | ||
/** | ||
@@ -15,0 +15,0 @@ * @param {string} [payload] - data to write |
export default Test; | ||
export type AsyncFunction = (() => Promise<any>); | ||
export type testDefinition = { | ||
description: string; | ||
callback: Function | asyncfunction; | ||
/** | ||
* - syc/ async function | ||
*/ | ||
callback: Function | AsyncFunction; | ||
}; | ||
@@ -40,10 +44,9 @@ export type testReport = { | ||
syncTimeout(timeout: number): void; | ||
catchErrors: boolean | undefined; | ||
/** | ||
* | ||
* @param {string} description | ||
* @param {Function|AsyncFunction|Promise} callback | ||
* @param {Function|AsyncFunction} callback - sync / async function | ||
* @throws Error when conditions are not met | ||
*/ | ||
add(description: string, callback: Function | AsyncFunction | Promise<any>): void; | ||
add(description: string, callback: Function | AsyncFunction): void; | ||
/** | ||
@@ -59,8 +62,3 @@ * Execute tests | ||
reset(): void; | ||
/** | ||
* Handle an error outside the callstack | ||
* for the current test | ||
*/ | ||
_handleError(err: any): void; | ||
#private; | ||
} |
48159
1048
177
1
+ Added@types/node@^22.10.10
+ Added@types/node@22.13.4(transitive)
+ Addedundici-types@6.20.0(transitive)