@iobroker/testing
Advanced tools
Comparing version 3.0.2 to 4.0.0
@@ -49,4 +49,4 @@ "use strict"; | ||
resolve({ | ||
exitCode: code !== null && code !== void 0 ? code : undefined, | ||
signal: signal !== null && signal !== void 0 ? signal : undefined, | ||
exitCode: code ?? undefined, | ||
signal: signal ?? undefined, | ||
stdout: bufferedStdout, | ||
@@ -53,0 +53,0 @@ stderr: bufferedStderr, |
@@ -13,2 +13,11 @@ /// <reference types="iobroker" /> | ||
} | ||
export interface TestSuiteFn { | ||
(name: string, fn: (getHarness: () => TestHarness) => void): void; | ||
} | ||
export interface TestSuite extends TestSuiteFn { | ||
/** Only runs the tests inside this `suite` for the current file */ | ||
only: TestSuiteFn; | ||
/** Skips running the tests inside this `suite` for the current file */ | ||
skip: TestSuiteFn; | ||
} | ||
export interface TestContext { | ||
@@ -21,3 +30,3 @@ /** | ||
*/ | ||
suite: (name: string, fn: (getHarness: () => TestHarness) => void) => void; | ||
suite: TestSuite; | ||
describe: Mocha.SuiteFunction; | ||
@@ -24,0 +33,0 @@ it: Mocha.TestFunction; |
@@ -51,3 +51,2 @@ "use strict"; | ||
async function prepareTests() { | ||
var _a; | ||
// Installation may take a while - especially if rsa-compat needs to be installed | ||
@@ -67,3 +66,3 @@ const oneMinute = 60000; | ||
await adapterSetup.installAdapterInTestDir(); | ||
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug")); | ||
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug")); | ||
await dbConnection.start(); | ||
@@ -87,5 +86,4 @@ controllerSetup.setupSystemConfig(dbConnection); | ||
async function resetDbAndStartHarness() { | ||
var _a, _b; | ||
this.timeout(30000); | ||
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug")); | ||
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug")); | ||
// Clean up before every single test | ||
@@ -104,3 +102,3 @@ await Promise.all([ | ||
enabled: true, | ||
loglevel: (_b = options.loglevel) !== null && _b !== void 0 ? _b : "debug", | ||
loglevel: options.loglevel ?? "debug", | ||
}, | ||
@@ -117,5 +115,4 @@ }); | ||
it("The adapter starts", function () { | ||
var _a; | ||
this.timeout(60000); | ||
const allowedExitCodes = new Set((_a = options.allowedExitCodes) !== null && _a !== void 0 ? _a : []); | ||
const allowedExitCodes = new Set(options.allowedExitCodes ?? []); | ||
// Adapters with these modes are allowed to "immediately" exit with code 0 | ||
@@ -183,13 +180,22 @@ switch (harness.getAdapterExecutionMode()) { | ||
global.it = patchedIt; | ||
// a test suite is a special describe which sets up and tears down the test environment before and after ALL tests | ||
const suiteBody = (fn) => { | ||
isInSuite = true; | ||
before(resetDbAndStartHarness); | ||
fn(() => harness); | ||
after(shutdownTests); | ||
isInSuite = false; | ||
}; | ||
const suite = ((name, fn) => { | ||
describe(name, () => suiteBody(fn)); | ||
}); | ||
// Support .skip and .only | ||
suite.skip = (name, fn) => { | ||
describe.skip(name, () => suiteBody(fn)); | ||
}; | ||
suite.only = (name, fn) => { | ||
describe.only(name, () => suiteBody(fn)); | ||
}; | ||
const args = { | ||
// a test suite is a special describe which sets up and tears down the test environment before and after ALL tests | ||
suite: (name, fn) => { | ||
describe(name, () => { | ||
isInSuite = true; | ||
before(resetDbAndStartHarness); | ||
fn(() => harness); | ||
after(shutdownTests); | ||
isInSuite = false; | ||
}); | ||
}, | ||
suite, | ||
describe, | ||
@@ -196,0 +202,0 @@ it: patchedIt, |
/// <reference types="iobroker" /> | ||
/// <reference types="iobroker" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import EventEmitter from "events"; | ||
@@ -4,0 +6,0 @@ export declare type ObjectsDB = Record<string, ioBroker.Object>; |
@@ -155,3 +155,2 @@ "use strict"; | ||
async stop() { | ||
var _a, _b, _c, _d; | ||
if (!this._isRunning) { | ||
@@ -163,6 +162,6 @@ debug("No DB instance is running, nothing to stop..."); | ||
// Stop clients before servers | ||
await ((_a = this._objectsClient) === null || _a === void 0 ? void 0 : _a.destroy()); | ||
await ((_b = this._objectsServer) === null || _b === void 0 ? void 0 : _b.destroy()); | ||
await ((_c = this._statesClient) === null || _c === void 0 ? void 0 : _c.destroy()); | ||
await ((_d = this._statesServer) === null || _d === void 0 ? void 0 : _d.destroy()); | ||
await this._objectsClient?.destroy(); | ||
await this._objectsServer?.destroy(); | ||
await this._statesClient?.destroy(); | ||
await this._statesServer?.destroy(); | ||
this._objectsClient = null; | ||
@@ -284,18 +283,16 @@ this._objectsServer = null; | ||
async getStateIDs(pattern = "*") { | ||
var _a, _b, _c, _d; | ||
if (!this._statesClient) { | ||
throw new Error("States DB is not running"); | ||
} | ||
return (((_b = (_a = this._statesClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) || | ||
((_d = (_c = this._statesClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern))); | ||
return (this._statesClient.getKeysAsync?.(pattern) || | ||
this._statesClient.getKeys?.(pattern)); | ||
} | ||
async getObjectIDs(pattern = "*") { | ||
var _a, _b, _c, _d; | ||
if (!this._objectsClient) { | ||
throw new Error("Objects DB is not running"); | ||
} | ||
return (((_b = (_a = this._objectsClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) || | ||
((_d = (_c = this._objectsClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern))); | ||
return (this._objectsClient.getKeysAsync?.(pattern) || | ||
this._objectsClient.getKeys?.(pattern)); | ||
} | ||
} | ||
exports.DBConnection = DBConnection; |
/// <reference types="iobroker" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="iobroker" /> | ||
/// <reference types="node" /> | ||
import { ChildProcess } from "child_process"; | ||
@@ -4,0 +7,0 @@ import { EventEmitter } from "events"; |
@@ -193,3 +193,2 @@ "use strict"; | ||
return new Promise(async (resolve) => { | ||
var _a; | ||
const onClose = (code, signal) => { | ||
@@ -218,3 +217,3 @@ if (!this._adapterProcess) | ||
// DB connection may be closed already, kill the process | ||
(_a = this._adapterProcess) === null || _a === void 0 ? void 0 : _a.kill("SIGTERM"); | ||
this._adapterProcess?.kill("SIGTERM"); | ||
} | ||
@@ -221,0 +220,0 @@ }); |
@@ -13,4 +13,3 @@ "use strict"; | ||
function createLogger(loglevel) { | ||
var _a; | ||
const loglevelNumeric = (_a = LoglevelOrder[loglevel !== null && loglevel !== void 0 ? loglevel : "debug"]) !== null && _a !== void 0 ? _a : LoglevelOrder.debug; | ||
const loglevelNumeric = LoglevelOrder[loglevel ?? "debug"] ?? LoglevelOrder.debug; | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
@@ -17,0 +16,0 @@ const ignore = () => { }; |
@@ -133,3 +133,2 @@ "use strict"; | ||
describe(`Check contents of io-package.json`, () => { | ||
var _a; | ||
beforeEach(function () { | ||
@@ -182,9 +181,8 @@ skipIfInvalid.call(this, "io-package.json"); | ||
iopackContent.common.noConfig === "true" || | ||
((_a = iopackContent.common.adminUI) === null || _a === void 0 ? void 0 : _a.config) === "none"; | ||
iopackContent.common.adminUI?.config === "none"; | ||
if (!hasNoConfigPage) { | ||
it("The adapter uses Material UI or JSON Config for the admin UI", () => { | ||
var _a, _b; | ||
const hasSupportedUI = !!iopackContent.common.materialize || | ||
((_a = iopackContent.common.adminUI) === null || _a === void 0 ? void 0 : _a.config) === "json" || | ||
((_b = iopackContent.common.adminUI) === null || _b === void 0 ? void 0 : _b.config) === "materialize"; | ||
iopackContent.common.adminUI?.config === "json" || | ||
iopackContent.common.adminUI?.config === "materialize"; | ||
(0, chai_1.expect)(hasSupportedUI, "Unsupported Admin UI, must be materialize or json config!").to.be.true; | ||
@@ -191,0 +189,0 @@ }); |
/// <reference types="iobroker" /> | ||
/// <reference types="iobroker" /> | ||
import type { MockAdapter } from "./mockAdapter"; | ||
@@ -3,0 +4,0 @@ /** |
@@ -7,3 +7,3 @@ /// <reference types="sinon" /> | ||
}> = NoAny[keyof NoAny]; | ||
export declare type Mock<T> = Overwrite<T, { | ||
export declare type Mock<T extends {}> = Overwrite<T, { | ||
[K in MockableMethods<T>]: sinon.SinonStub; | ||
@@ -10,0 +10,0 @@ }>; |
{ | ||
"name": "@iobroker/testing", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"description": "Shared utilities for adapter and module testing in ioBroker", | ||
@@ -44,25 +44,25 @@ "main": "build/index.js", | ||
"@iobroker/adapter-core": "^2.6.0", | ||
"@tsconfig/node12": "^1.0.9", | ||
"@types/chai": "^4.3.1", | ||
"@tsconfig/node14": "^1.0.3", | ||
"@types/chai": "^4.3.3", | ||
"@types/chai-as-promised": "^7.1.5", | ||
"@types/debug": "4.1.7", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/iobroker": "^4.0.2", | ||
"@types/iobroker": "^4.0.4", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^12.20.50", | ||
"@types/sinon": "^10.0.11", | ||
"@types/node": "^14.18.26", | ||
"@types/sinon": "^10.0.13", | ||
"@types/sinon-chai": "^3.2.8", | ||
"@typescript-eslint/eslint-plugin": "^5.22.0", | ||
"@typescript-eslint/parser": "^5.22.0", | ||
"eslint": "^8.15.0", | ||
"@typescript-eslint/eslint-plugin": "^5.35.1", | ||
"@typescript-eslint/parser": "^5.35.1", | ||
"eslint": "^8.23.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"prettier": "^2.6.2", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"prettier": "^2.7.1", | ||
"rimraf": "^3.0.2", | ||
"source-map-support": "^0.5.21", | ||
"ts-node": "^10.7.0", | ||
"typescript": "~4.6.4" | ||
"ts-node": "^10.9.1", | ||
"typescript": "~4.8.2" | ||
}, | ||
"dependencies": { | ||
"alcalzone-shared": "~4.0.1", | ||
"alcalzone-shared": "~4.0.3", | ||
"chai": "^4.3.6", | ||
@@ -72,6 +72,6 @@ "chai-as-promised": "^7.1.1", | ||
"fs-extra": "^10.1.0", | ||
"mocha": "^9.2.2", | ||
"sinon": "^13.0.1", | ||
"mocha": "^10.0.0", | ||
"sinon": "^14.0.0", | ||
"sinon-chai": "^3.7.0" | ||
} | ||
} |
@@ -73,2 +73,11 @@ # @iobroker/testing | ||
}); | ||
// While developing the tests, you can run only a single suite using `suite.only`... | ||
suite.only("Only this will run", (getHarness) => { | ||
// ... | ||
}); | ||
// ...or prevent a suite from running using `suite.skip`: | ||
suite.skip("This will never run", (getHarness) => { | ||
// ... | ||
}); | ||
}, | ||
@@ -75,0 +84,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3203
202
143452
45
+ Added@sinonjs/commons@2.0.0(transitive)
+ Added@sinonjs/samsam@7.0.1(transitive)
+ Addedansi-colors@4.1.3(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addeddiff@5.2.0(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedmocha@10.8.2(transitive)
+ Addedserialize-javascript@6.0.2(transitive)
+ Addedsinon@14.0.2(transitive)
+ Addedworkerpool@6.5.1(transitive)
+ Addedyargs-parser@20.2.9(transitive)
- Removed@sinonjs/samsam@6.1.3(transitive)
- Removed@ungap/promise-all-settled@1.1.2(transitive)
- Removedansi-colors@4.1.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchokidar@3.5.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug@4.3.3(transitive)
- Removeddiff@5.0.0(transitive)
- Removedglob@7.2.0(transitive)
- Removedgrowl@1.10.5(transitive)
- Removedisexe@2.0.0(transitive)
- Removedminimatch@3.1.24.2.1(transitive)
- Removedmocha@9.2.2(transitive)
- Removedms@2.1.2(transitive)
- Removednanoid@3.3.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedserialize-javascript@6.0.0(transitive)
- Removedsinon@13.0.2(transitive)
- Removedwhich@2.0.2(transitive)
- Removedworkerpool@6.2.0(transitive)
- Removedyargs-parser@20.2.4(transitive)
Updatedalcalzone-shared@~4.0.3
Updatedmocha@^10.0.0
Updatedsinon@^14.0.0