Skip to content

Commit 6beae75

Browse files
committed
Corrected removed functions
1 parent 88808dd commit 6beae75

33 files changed

+259
-207
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PLACEHOLDER for the next version:
55
## **WORK IN PROGRESS**
66
-->
7-
## 5.0.2 (2025-01-21)
7+
## **WORK IN PROGRESS**
88
* Packages were updated
99

1010
## 5.0.0 (2024-09-14)

build/lib/adapterTools.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
/**
22
* Loads an adapter's package.json
3+
*
34
* @param adapterDir The directory the adapter resides in
45
*/
56
export declare function loadNpmPackage(adapterDir: string): Record<string, any>;
67
/**
78
* Loads an adapter's io-package.json
9+
*
810
* @param adapterDir The directory the adapter resides in
911
*/
1012
export declare function loadIoPackage(adapterDir: string): Record<string, any>;
1113
export declare function getAdapterExecutionMode(adapterDir: string): ioBroker.AdapterCommon['mode'];
1214
/**
1315
* Locates an adapter's main file
16+
*
1417
* @param adapterDir The directory the adapter resides in
1518
*/
1619
export declare function locateAdapterMainFile(adapterDir: string): Promise<string>;
1720
/**
1821
* Locates an adapter's config to populate the `adapter.config` object with
22+
*
1923
* @param adapterDir The directory the adapter resides in
2024
*/
2125
export declare function loadAdapterConfig(adapterDir: string): Record<string, any>;
2226
/**
2327
* Loads the adapter's common configuration from `io-package.json`
28+
*
2429
* @param adapterDir The directory the adapter resides in
2530
*/
2631
export declare function loadAdapterCommon(adapterDir: string): Record<string, any>;
2732
/**
2833
* Loads the instanceObjects for an adapter from its `io-package.json`
34+
*
2935
* @param adapterDir The directory the adapter resides in
3036
*/
3137
export declare function loadInstanceObjects(adapterDir: string): ioBroker.Object[];

build/lib/adapterTools.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,25 @@ exports.getAdapterName = getAdapterName;
4848
exports.getAdapterFullName = getAdapterFullName;
4949
exports.getAdapterDependencies = getAdapterDependencies;
5050
// Add debug logging for tests
51-
// @ts-expect-error no types
5251
const typeguards_1 = require("alcalzone-shared/typeguards");
5352
const debug_1 = __importDefault(require("debug"));
5453
const fs_extra_1 = require("fs-extra");
5554
const path = __importStar(require("path"));
5655
const debug = (0, debug_1.default)('testing:unit:adapterTools');
5756
/**
5857
* Loads an adapter's package.json
58+
*
5959
* @param adapterDir The directory the adapter resides in
6060
*/
6161
function loadNpmPackage(adapterDir) {
62-
// eslint-disable-next-line @typescript-eslint/no-require-imports
6362
return require(path.join(adapterDir, 'package.json'));
6463
}
6564
/**
6665
* Loads an adapter's io-package.json
66+
*
6767
* @param adapterDir The directory the adapter resides in
6868
*/
6969
function loadIoPackage(adapterDir) {
70-
// eslint-disable-next-line @typescript-eslint/no-require-imports
7170
return require(path.join(adapterDir, 'io-package.json'));
7271
}
7372
function getAdapterExecutionMode(adapterDir) {
@@ -76,6 +75,7 @@ function getAdapterExecutionMode(adapterDir) {
7675
}
7776
/**
7877
* Locates an adapter's main file
78+
*
7979
* @param adapterDir The directory the adapter resides in
8080
*/
8181
async function locateAdapterMainFile(adapterDir) {
@@ -95,7 +95,7 @@ async function locateAdapterMainFile(adapterDir) {
9595
return ret;
9696
}
9797
// If both don't exist, JS-Controller uses <adapter name>.js as another fallback
98-
ret = path.join(adapterDir, ioPackage.common.name + '.js');
98+
ret = path.join(adapterDir, `${ioPackage.common.name}.js`);
9999
debug(` => trying ${ret}`);
100100
if (await (0, fs_extra_1.pathExists)(ret)) {
101101
debug(` => found ${mainFile}`);
@@ -105,6 +105,7 @@ async function locateAdapterMainFile(adapterDir) {
105105
}
106106
/**
107107
* Locates an adapter's config to populate the `adapter.config` object with
108+
*
108109
* @param adapterDir The directory the adapter resides in
109110
*/
110111
function loadAdapterConfig(adapterDir) {
@@ -113,6 +114,7 @@ function loadAdapterConfig(adapterDir) {
113114
}
114115
/**
115116
* Loads the adapter's common configuration from `io-package.json`
117+
*
116118
* @param adapterDir The directory the adapter resides in
117119
*/
118120
function loadAdapterCommon(adapterDir) {
@@ -121,6 +123,7 @@ function loadAdapterCommon(adapterDir) {
121123
}
122124
/**
123125
* Loads the instanceObjects for an adapter from its `io-package.json`
126+
*
124127
* @param adapterDir The directory the adapter resides in
125128
*/
126129
function loadInstanceObjects(adapterDir) {
@@ -153,8 +156,9 @@ function getAdapterDependencies(adapterDir) {
153156
}
154157
else if ((0, typeguards_1.isObject)(dep)) {
155158
const key = Object.keys(dep)[0];
156-
if (key)
159+
if (key) {
157160
ret[key] = dep[key] || 'latest';
161+
}
158162
}
159163
}
160164
}

build/lib/executeCommand.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface ExecuteCommandResult {
2323
export declare function executeCommand(command: string, options?: Partial<ExecuteCommandOptions>): Promise<ExecuteCommandResult>;
2424
/**
2525
* Executes a command and returns the exit code and (if requested) the stdout
26+
*
2627
* @param command The command to execute
2728
* @param args The command line arguments for the command
2829
* @param options (optional) Some options for the command execution

build/lib/executeCommand.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ function executeCommand(command, argsOrOptions, options) {
1313
// no args were given
1414
options = argsOrOptions;
1515
}
16-
if (options == null)
16+
if (options == null) {
1717
options = {};
18-
if (args == null)
18+
}
19+
if (args == null) {
1920
args = [];
21+
}
2022
const spawnOptions = {
2123
stdio: [options.stdin || process.stdin, options.stdout || process.stdout, options.stderr || process.stderr],
2224
windowsHide: true,
2325
};
24-
if (options.cwd != null)
26+
if (options.cwd != null) {
2527
spawnOptions.cwd = options.cwd;
28+
}
2629
// Fix npm / node executable paths on Windows
2730
if (isWindows) {
2831
if (command === 'npm') {
@@ -35,10 +38,11 @@ function executeCommand(command, argsOrOptions, options) {
3538
command += '.exe';
3639
}
3740
}
38-
if (options.logCommandExecution == null)
41+
if (options.logCommandExecution == null) {
3942
options.logCommandExecution = false;
43+
}
4044
if (options.logCommandExecution) {
41-
console.log('executing: ' + `${command} ${args.join(' ')}`);
45+
console.log(`executing: ${command} ${args.join(' ')}`);
4246
}
4347
// Now execute the npm process and avoid throwing errors
4448
try {
@@ -56,16 +60,18 @@ function executeCommand(command, argsOrOptions, options) {
5660
if (options.stdout === 'pipe') {
5761
bufferedStdout = '';
5862
cmd.stdout.on('data', (chunk) => {
59-
if (Buffer.isBuffer(chunk))
63+
if (Buffer.isBuffer(chunk)) {
6064
chunk = chunk.toString('utf8');
65+
}
6166
bufferedStdout += chunk;
6267
});
6368
}
6469
if (options.stderr === 'pipe') {
6570
bufferedStderr = '';
6671
cmd.stderr.on('data', (chunk) => {
67-
if (Buffer.isBuffer(chunk))
72+
if (Buffer.isBuffer(chunk)) {
6873
chunk = chunk.toString('utf8');
74+
}
6975
bufferedStderr += chunk;
7076
});
7177
}

build/lib/testAdapter.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

build/lib/testAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
// TODO: Do we need this file?
33
// import * as utils from "@iobroker/adapter-core";
4+
Object.defineProperty(exports, "__esModule", { value: true });
45
// const adapter = utils.adapter({
56
// name: "foo",
67
// ready() {

build/tests/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { testAdapterWithMocks } from './unit';
44
import { createMocks } from './unit/harness/createMocks';
55
import { createAsserts } from './unit/mocks/mockDatabase';
66
export { TestHarness as IntegrationTestHarness } from './integration/lib/harness';
7-
export { MockAdapter } from './unit/mocks/mockAdapter';
7+
export type { MockAdapter } from './unit/mocks/mockAdapter';
88
export { MockDatabase } from './unit/mocks/mockDatabase';
99
/** Predefined test sets */
1010
export declare const tests: {
@@ -19,6 +19,6 @@ export declare const utils: {
1919
createMocks: typeof createMocks;
2020
createAsserts: typeof createAsserts;
2121
/** @deprecated Adapter startup unit tests are no longer supported */
22-
startMockAdapter: () => {};
22+
startMockAdapter: () => any;
2323
};
2424
};

build/tests/integration/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ function testAdapter(adapterDir, options = {}) {
121121
// Adapters with these modes are allowed to "immediately" exit with code 0
122122
switch (harness.getAdapterExecutionMode()) {
123123
case 'schedule':
124+
allowedExitCodes.add(0);
125+
break;
124126
case 'once':
127+
allowedExitCodes.add(0);
128+
break;
125129
// @ts-expect-error subscribe was deprecated
126130
case 'subscribe':
127131
allowedExitCodes.add(0);
132+
break;
128133
}
129134
return new Promise((resolve, reject) => {
130135
// Register a handler to check the alive state and exit codes
@@ -147,7 +152,7 @@ function testAdapter(adapterDir, options = {}) {
147152
resolve(`The expected ${typeof code === 'number' ? 'exit code' : 'signal'} ${code} was received.`);
148153
}
149154
});
150-
harness.startAdapter();
155+
void harness.startAdapter();
151156
}).then(msg => console.log(msg));
152157
});
153158
});

build/tests/integration/lib/adapterSetup.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3838
Object.defineProperty(exports, "__esModule", { value: true });
3939
exports.AdapterSetup = void 0;
4040
// Add debug logging for tests
41-
// @ts-expect-error no types
42-
const objects_1 = require("alcalzone-shared/objects");
4341
const debug_1 = __importDefault(require("debug"));
4442
const fs_extra_1 = require("fs-extra");
4543
const path = __importStar(require("path"));
@@ -78,8 +76,9 @@ class AdapterSetup {
7876
const packResult = await (0, executeCommand_1.executeCommand)('npm', ['pack', '--loglevel', 'silent'], {
7977
stdout: 'pipe',
8078
});
81-
if (packResult.exitCode !== 0 || typeof packResult.stdout !== 'string')
79+
if (packResult.exitCode !== 0 || typeof packResult.stdout !== 'string') {
8280
throw new Error(`Packing the adapter tarball failed!`);
81+
}
8382
// The last non-empty line of `npm pack`s STDOUT contains the tarball path
8483
const stdoutLines = packResult.stdout.trim().split(/[\r\n]+/);
8584
const tarballName = stdoutLines[stdoutLines.length - 1].trim();
@@ -99,16 +98,18 @@ class AdapterSetup {
9998
const packageJsonPath = path.join(this.testDir, 'package.json');
10099
const packageJson = await (0, fs_extra_1.readJSON)(packageJsonPath);
101100
packageJson.dependencies[this.adapterFullName] = `file:./${tarballName}`;
102-
for (const [dep, version] of (0, objects_1.entries)((0, adapterTools_1.getAdapterDependencies)(this.adapterDir))) {
101+
for (const [dep, version] of Object.entries((0, adapterTools_1.getAdapterDependencies)(this.adapterDir))) {
103102
// Don't overwrite the js-controller GitHub dependency with a probably lower one
104-
if (dep === 'js-controller')
103+
if (dep === 'js-controller') {
105104
continue;
105+
}
106106
packageJson.dependencies[`${this.appName}.${dep}`] = version;
107107
}
108108
await (0, fs_extra_1.writeJSON)(packageJsonPath, packageJson, { spaces: 2 });
109109
debug('Deleting old remains of this adapter');
110-
if (await (0, fs_extra_1.pathExists)(this.testAdapterDir))
110+
if (await (0, fs_extra_1.pathExists)(this.testAdapterDir)) {
111111
await (0, fs_extra_1.remove)(this.testAdapterDir);
112+
}
112113
debug('Installing adapter');
113114
// Defer to npm to install the controller (if it wasn't already)
114115
await (0, executeCommand_1.executeCommand)('npm', ['i', '--omit=dev'], {
@@ -126,15 +127,16 @@ class AdapterSetup {
126127
cwd: this.testControllerDir,
127128
stdout: 'ignore',
128129
});
129-
if (addResult.exitCode !== 0)
130+
if (addResult.exitCode !== 0) {
130131
throw new Error(`Adding the adapter instance failed!`);
132+
}
131133
debug(' => done!');
132134
}
133135
async deleteOldInstances(dbConnection) {
134136
debug('Removing old adapter instances...');
135137
const allKeys = new Set([...(await dbConnection.getObjectIDs()), ...(await dbConnection.getStateIDs())]);
136138
const instanceRegex = new RegExp(`^system\\.adapter\\.${this.adapterName}\\.\\d+`);
137-
const instanceObjsRegex = new RegExp(`^${this.adapterName}\\.\\d+\.`);
139+
const instanceObjsRegex = new RegExp(`^${this.adapterName}\\.\\d+\\.`);
138140
const belongsToAdapter = (id) => {
139141
return (instanceRegex.test(id) ||
140142
instanceObjsRegex.test(id) ||

build/tests/integration/lib/controllerSetup.d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export declare class ControllerSetup {
1111
prepareTestDir(controllerVersion?: string): Promise<void>;
1212
/**
1313
* Tests if JS-Controller is already installed
14-
* @param appName The branded name of "iobroker"
15-
* @param testDir The directory the integration tests are executed in
1614
*/
1715
isJsControllerInstalled(): Promise<boolean>;
1816
/**
@@ -25,25 +23,18 @@ export declare class ControllerSetup {
2523
setupJsController(): Promise<void>;
2624
/**
2725
* Changes the objects and states db to use alternative ports
28-
* @param appName The branded name of "iobroker"
29-
* @param testDir The directory the integration tests are executed in
3026
*/
3127
setupSystemConfig(dbConnection: DBConnection): void;
3228
/**
3329
* Clears the log dir for integration tests (and creates it if it doesn't exist)
34-
* @param appName The branded name of "iobroker"
35-
* @param testDir The directory the integration tests are executed in
3630
*/
3731
clearLogDir(): Promise<void>;
3832
/**
3933
* Clears the sqlite DB dir for integration tests (and creates it if it doesn't exist)
40-
* @param appName The branded name of "iobroker"
41-
* @param testDir The directory the integration tests are executed in
4234
*/
4335
clearDBDir(): Promise<void>;
4436
/**
4537
* Disables all admin instances in the objects DB
46-
* @param objects The contents of objects.json
4738
*/
4839
disableAdminInstances(dbConnection: DBConnection): Promise<void>;
4940
}

0 commit comments

Comments
 (0)