@iobroker/testing
Advanced tools
Comparing version
@@ -5,2 +5,4 @@ /// <reference types="iobroker" /> | ||
export interface StartMockAdapterOptions { | ||
/** A specific directory to use as the adapter dir. If none is given, all paths are relative */ | ||
adapterDir?: string; | ||
/** Whether the adapter should be started in compact mode */ | ||
@@ -7,0 +9,0 @@ compact?: boolean; |
@@ -12,4 +12,13 @@ "use strict"; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const objects_1 = require("alcalzone-shared/objects"); | ||
const chai_1 = require("chai"); | ||
const path = __importStar(require("path")); | ||
const mockAdapterCore_1 = require("../mocks/mockAdapterCore"); | ||
@@ -46,5 +55,15 @@ const mockDatabase_1 = require("../mocks/mockDatabase"); | ||
}, | ||
adapterDir: options.adapterDir, | ||
}); | ||
// Replace the following modules with mocks | ||
const mockedModules = Object.assign({}, options.additionalMockedModules, { "@iobroker/adapter-core": adapterCoreMock }); | ||
const mockedModules = {}; | ||
if (options.additionalMockedModules) { | ||
for (let [mdl, mock] of objects_1.entries(options.additionalMockedModules)) { | ||
mdl = mdl.replace("{CONTROLLER_DIR}", adapterCoreMock.controllerDir); | ||
if (mdl.startsWith(".") || path.isAbsolute(mdl)) | ||
mdl = path.normalize(mdl); | ||
mockedModules[mdl] = mock; | ||
} | ||
} | ||
mockedModules["@iobroker/adapter-core"] = adapterCoreMock; | ||
// If the adapter supports compact mode and should be executed in "normal" mode, | ||
@@ -51,0 +70,0 @@ // we need to trick it into thinking it was not required |
@@ -48,2 +48,3 @@ "use strict"; | ||
defineMockBehavior: options.defineMockBehavior, | ||
adapterDir, | ||
}); | ||
@@ -62,2 +63,3 @@ assertValidExitCode(options.allowedExitCodes || [], processExitCode); | ||
defineMockBehavior: options.defineMockBehavior, | ||
adapterDir, | ||
}); | ||
@@ -64,0 +66,0 @@ // In compact mode, only "adapter.terminate" may be called |
@@ -10,2 +10,3 @@ /// <reference types="iobroker" /> | ||
onAdapterCreated?: (adapter: MockAdapter) => void; | ||
adapterDir?: string; | ||
} | ||
@@ -12,0 +13,0 @@ export declare function mockAdapterCore(database: MockDatabase, options?: MockAdapterCoreOptions): { |
"use strict"; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = __importStar(require("path")); | ||
const mockAdapter_1 = require("./mockAdapter"); | ||
@@ -9,3 +17,3 @@ function mockAdapterCore(database, options = {}) { | ||
*/ | ||
const controllerDir = "../iobroker.js-controller"; | ||
const controllerDir = path.join(options.adapterDir || "", "..", "iobroker.js-controller"); | ||
/** Reads the configuration file of JS-Controller */ | ||
@@ -12,0 +20,0 @@ function getConfig() { |
{ | ||
"name": "@iobroker/testing", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "Shared utilities for adapter and module testing in ioBroker", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -57,2 +57,5 @@ # @iobroker/testing | ||
"@abandonware/noble": nobleMock, | ||
// Use the {CONTROLLER_DIR} placeholder to access the path where JS-Controller would be installed. | ||
// Don't forget to provide mocks for every module you need, as they don't exist in unit tests | ||
"{CONTROLLER_DIR}/lib/tools.js": {}, | ||
}, | ||
@@ -59,0 +62,0 @@ |
147418
1.15%3102
1.04%206
1.48%