@iobroker/testing 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/build/index.d.ts +1 -1
- package/build/lib/adapterTools.d.ts +7 -1
- package/build/lib/adapterTools.js +36 -21
- package/build/lib/executeCommand.d.ts +3 -2
- package/build/lib/executeCommand.js +30 -29
- package/build/lib/str2regex.js +4 -4
- package/build/tests/index.d.ts +9 -9
- package/build/tests/integration/index.d.ts +1 -1
- package/build/tests/integration/index.js +44 -39
- package/build/tests/integration/lib/adapterSetup.d.ts +1 -1
- package/build/tests/integration/lib/adapterSetup.js +50 -50
- package/build/tests/integration/lib/controllerSetup.d.ts +1 -10
- package/build/tests/integration/lib/controllerSetup.js +59 -56
- package/build/tests/integration/lib/dbConnection.d.ts +12 -12
- package/build/tests/integration/lib/dbConnection.js +71 -69
- package/build/tests/integration/lib/harness.d.ts +9 -7
- package/build/tests/integration/lib/harness.js +68 -49
- package/build/tests/integration/lib/logger.js +1 -1
- package/build/tests/integration/lib/tools.d.ts +6 -1
- package/build/tests/integration/lib/tools.js +27 -12
- package/build/tests/packageFiles/index.js +92 -90
- package/build/tests/unit/harness/createMocks.d.ts +3 -2
- package/build/tests/unit/harness/createMocks.js +0 -1
- package/build/tests/unit/index.js +5 -4
- package/build/tests/unit/mocks/mockAdapter.d.ts +3 -3
- package/build/tests/unit/mocks/mockAdapter.js +196 -162
- package/build/tests/unit/mocks/mockAdapterCore.d.ts +4 -9
- package/build/tests/unit/mocks/mockAdapterCore.js +23 -14
- package/build/tests/unit/mocks/mockDatabase.d.ts +13 -12
- package/build/tests/unit/mocks/mockDatabase.js +39 -43
- package/build/tests/unit/mocks/mockLogger.d.ts +1 -1
- package/build/tests/unit/mocks/mockLogger.js +1 -1
- package/build/tests/unit/mocks/tools.d.ts +2 -2
- package/build/tests/unit/mocks/tools.js +14 -11
- package/package.json +15 -22
|
@@ -15,19 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.AdapterSetup = void 0;
|
|
30
40
|
// Add debug logging for tests
|
|
41
|
+
// @ts-expect-error no types
|
|
31
42
|
const objects_1 = require("alcalzone-shared/objects");
|
|
32
43
|
const debug_1 = __importDefault(require("debug"));
|
|
33
44
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -35,12 +46,12 @@ const path = __importStar(require("path"));
|
|
|
35
46
|
const adapterTools_1 = require("../../../lib/adapterTools");
|
|
36
47
|
const executeCommand_1 = require("../../../lib/executeCommand");
|
|
37
48
|
const tools_1 = require("./tools");
|
|
38
|
-
const debug = (0, debug_1.default)(
|
|
49
|
+
const debug = (0, debug_1.default)('testing:integration:AdapterSetup');
|
|
39
50
|
class AdapterSetup {
|
|
40
51
|
constructor(adapterDir, testDir) {
|
|
41
52
|
this.adapterDir = adapterDir;
|
|
42
53
|
this.testDir = testDir;
|
|
43
|
-
debug(
|
|
54
|
+
debug('Creating AdapterSetup...');
|
|
44
55
|
this.adapterName = (0, adapterTools_1.getAdapterName)(this.adapterDir);
|
|
45
56
|
this.adapterFullName = (0, adapterTools_1.getAdapterFullName)(this.adapterDir);
|
|
46
57
|
this.appName = (0, adapterTools_1.getAppName)(this.adapterDir);
|
|
@@ -61,14 +72,15 @@ class AdapterSetup {
|
|
|
61
72
|
}
|
|
62
73
|
/** Copies all adapter files (except a few) to the test directory */
|
|
63
74
|
async installAdapterInTestDir() {
|
|
64
|
-
debug(
|
|
75
|
+
debug('Copying adapter files to test directory...');
|
|
65
76
|
// We install the adapter almost like it would be installed in the real world
|
|
66
77
|
// Therefore pack it into a tarball and put it in the test dir for installation
|
|
67
|
-
const packResult = await (0, executeCommand_1.executeCommand)(
|
|
68
|
-
stdout:
|
|
78
|
+
const packResult = await (0, executeCommand_1.executeCommand)('npm', ['pack', '--loglevel', 'silent'], {
|
|
79
|
+
stdout: 'pipe',
|
|
69
80
|
});
|
|
70
|
-
if (packResult.exitCode !== 0 || typeof packResult.stdout !==
|
|
81
|
+
if (packResult.exitCode !== 0 || typeof packResult.stdout !== 'string') {
|
|
71
82
|
throw new Error(`Packing the adapter tarball failed!`);
|
|
83
|
+
}
|
|
72
84
|
// The last non-empty line of `npm pack`s STDOUT contains the tarball path
|
|
73
85
|
const stdoutLines = packResult.stdout.trim().split(/[\r\n]+/);
|
|
74
86
|
const tarballName = stdoutLines[stdoutLines.length - 1].trim();
|
|
@@ -79,78 +91,66 @@ class AdapterSetup {
|
|
|
79
91
|
// so that the installation in the following step
|
|
80
92
|
// won't grab the cached files.
|
|
81
93
|
// See https://github.com/ioBroker/testing/issues/612
|
|
82
|
-
debug(
|
|
83
|
-
await (0, executeCommand_1.executeCommand)(
|
|
84
|
-
"uninstall",
|
|
85
|
-
this.adapterFullName,
|
|
86
|
-
"--package-lock-only",
|
|
87
|
-
"--omit=dev",
|
|
88
|
-
], {
|
|
94
|
+
debug('Removing the adapter from package-lock.json');
|
|
95
|
+
await (0, executeCommand_1.executeCommand)('npm', ['uninstall', this.adapterFullName, '--package-lock-only', '--omit=dev'], {
|
|
89
96
|
cwd: this.testDir,
|
|
90
97
|
});
|
|
91
98
|
// Complete the package.json, so npm can do it's magic
|
|
92
|
-
debug(
|
|
93
|
-
const packageJsonPath = path.join(this.testDir,
|
|
99
|
+
debug('Saving the adapter in package.json');
|
|
100
|
+
const packageJsonPath = path.join(this.testDir, 'package.json');
|
|
94
101
|
const packageJson = await (0, fs_extra_1.readJSON)(packageJsonPath);
|
|
95
|
-
packageJson.dependencies[this.adapterFullName] =
|
|
96
|
-
`file:./${tarballName}`;
|
|
102
|
+
packageJson.dependencies[this.adapterFullName] = `file:./${tarballName}`;
|
|
97
103
|
for (const [dep, version] of (0, objects_1.entries)((0, adapterTools_1.getAdapterDependencies)(this.adapterDir))) {
|
|
98
|
-
// Don't overwrite the js-controller
|
|
99
|
-
if (dep ===
|
|
104
|
+
// Don't overwrite the js-controller GitHub dependency with a probably lower one
|
|
105
|
+
if (dep === 'js-controller') {
|
|
100
106
|
continue;
|
|
107
|
+
}
|
|
101
108
|
packageJson.dependencies[`${this.appName}.${dep}`] = version;
|
|
102
109
|
}
|
|
103
110
|
await (0, fs_extra_1.writeJSON)(packageJsonPath, packageJson, { spaces: 2 });
|
|
104
|
-
debug(
|
|
105
|
-
if (await (0, fs_extra_1.pathExists)(this.testAdapterDir))
|
|
111
|
+
debug('Deleting old remains of this adapter');
|
|
112
|
+
if (await (0, fs_extra_1.pathExists)(this.testAdapterDir)) {
|
|
106
113
|
await (0, fs_extra_1.remove)(this.testAdapterDir);
|
|
107
|
-
|
|
114
|
+
}
|
|
115
|
+
debug('Installing adapter');
|
|
108
116
|
// Defer to npm to install the controller (if it wasn't already)
|
|
109
|
-
await (0, executeCommand_1.executeCommand)(
|
|
117
|
+
await (0, executeCommand_1.executeCommand)('npm', ['i', '--omit=dev'], {
|
|
110
118
|
cwd: this.testDir,
|
|
111
119
|
});
|
|
112
|
-
debug(
|
|
120
|
+
debug(' => done!');
|
|
113
121
|
}
|
|
114
122
|
/**
|
|
115
123
|
* Adds an instance for an already installed adapter in the test directory
|
|
116
124
|
*/
|
|
117
125
|
async addAdapterInstance() {
|
|
118
|
-
debug(
|
|
126
|
+
debug('Adding adapter instance...');
|
|
119
127
|
// execute iobroker add <adapter> -- This also installs missing dependencies
|
|
120
|
-
const addResult = await (0, executeCommand_1.executeCommand)(
|
|
121
|
-
`${this.appName}.js`,
|
|
122
|
-
"add",
|
|
123
|
-
this.adapterName,
|
|
124
|
-
"--enabled",
|
|
125
|
-
"false",
|
|
126
|
-
], {
|
|
128
|
+
const addResult = await (0, executeCommand_1.executeCommand)('node', [`${this.appName}.js`, 'add', this.adapterName, '--enabled', 'false'], {
|
|
127
129
|
cwd: this.testControllerDir,
|
|
128
|
-
stdout:
|
|
130
|
+
stdout: 'ignore',
|
|
129
131
|
});
|
|
130
|
-
if (addResult.exitCode !== 0)
|
|
132
|
+
if (addResult.exitCode !== 0) {
|
|
131
133
|
throw new Error(`Adding the adapter instance failed!`);
|
|
132
|
-
|
|
134
|
+
}
|
|
135
|
+
debug(' => done!');
|
|
133
136
|
}
|
|
134
137
|
async deleteOldInstances(dbConnection) {
|
|
135
|
-
debug(
|
|
136
|
-
const allKeys = new Set([
|
|
137
|
-
...(await dbConnection.getObjectIDs()),
|
|
138
|
-
...(await dbConnection.getStateIDs()),
|
|
139
|
-
]);
|
|
138
|
+
debug('Removing old adapter instances...');
|
|
139
|
+
const allKeys = new Set([...(await dbConnection.getObjectIDs()), ...(await dbConnection.getStateIDs())]);
|
|
140
140
|
const instanceRegex = new RegExp(`^system\\.adapter\\.${this.adapterName}\\.\\d+`);
|
|
141
|
-
const instanceObjsRegex = new RegExp(`^${this.adapterName}\\.\\d
|
|
141
|
+
const instanceObjsRegex = new RegExp(`^${this.adapterName}\\.\\d+\\.`);
|
|
142
142
|
const belongsToAdapter = (id) => {
|
|
143
143
|
return (instanceRegex.test(id) ||
|
|
144
144
|
instanceObjsRegex.test(id) ||
|
|
145
145
|
id === this.adapterName ||
|
|
146
146
|
id === `${this.adapterName}.admin`);
|
|
147
147
|
};
|
|
148
|
-
const idsToDelete = [...allKeys].filter(
|
|
148
|
+
const idsToDelete = [...allKeys].filter(id => belongsToAdapter(id));
|
|
149
149
|
for (const id of idsToDelete) {
|
|
150
150
|
await dbConnection.delObject(id).catch(() => { });
|
|
151
151
|
await dbConnection.delState(id).catch(() => { });
|
|
152
152
|
}
|
|
153
|
-
debug(
|
|
153
|
+
debug(' => done!');
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
exports.AdapterSetup = AdapterSetup;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DBConnection } from
|
|
1
|
+
import type { DBConnection } from './dbConnection';
|
|
2
2
|
export declare class ControllerSetup {
|
|
3
3
|
private adapterDir;
|
|
4
4
|
private testDir;
|
|
@@ -11,8 +11,6 @@ export declare class ControllerSetup {
|
|
|
11
11
|
prepareTestDir(controllerVersion?: string): Promise<void>;
|
|
12
12
|
/**
|
|
13
13
|
* 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
|
|
16
14
|
*/
|
|
17
15
|
isJsControllerInstalled(): Promise<boolean>;
|
|
18
16
|
/**
|
|
@@ -25,25 +23,18 @@ export declare class ControllerSetup {
|
|
|
25
23
|
setupJsController(): Promise<void>;
|
|
26
24
|
/**
|
|
27
25
|
* 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
|
|
30
26
|
*/
|
|
31
27
|
setupSystemConfig(dbConnection: DBConnection): void;
|
|
32
28
|
/**
|
|
33
29
|
* 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
|
|
36
30
|
*/
|
|
37
31
|
clearLogDir(): Promise<void>;
|
|
38
32
|
/**
|
|
39
33
|
* 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
|
|
42
34
|
*/
|
|
43
35
|
clearDBDir(): Promise<void>;
|
|
44
36
|
/**
|
|
45
37
|
* Disables all admin instances in the objects DB
|
|
46
|
-
* @param objects The contents of objects.json
|
|
47
38
|
*/
|
|
48
39
|
disableAdminInstances(dbConnection: DBConnection): Promise<void>;
|
|
49
40
|
}
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -35,12 +45,12 @@ const path = __importStar(require("path"));
|
|
|
35
45
|
const adapterTools_1 = require("../../../lib/adapterTools");
|
|
36
46
|
const executeCommand_1 = require("../../../lib/executeCommand");
|
|
37
47
|
const tools_1 = require("./tools");
|
|
38
|
-
const debug = (0, debug_1.default)(
|
|
48
|
+
const debug = (0, debug_1.default)('testing:integration:ControllerSetup');
|
|
39
49
|
class ControllerSetup {
|
|
40
50
|
constructor(adapterDir, testDir) {
|
|
41
51
|
this.adapterDir = adapterDir;
|
|
42
52
|
this.testDir = testDir;
|
|
43
|
-
debug(
|
|
53
|
+
debug('Creating ControllerSetup...');
|
|
44
54
|
this.adapterName = (0, adapterTools_1.getAdapterName)(this.adapterDir);
|
|
45
55
|
this.appName = (0, adapterTools_1.getAppName)(this.adapterDir);
|
|
46
56
|
this.testAdapterDir = (0, tools_1.getTestAdapterDir)(this.adapterDir, this.testDir);
|
|
@@ -53,60 +63,59 @@ class ControllerSetup {
|
|
|
53
63
|
debug(` appName: ${this.appName}`);
|
|
54
64
|
debug(` adapterName: ${this.adapterName}`);
|
|
55
65
|
}
|
|
56
|
-
async prepareTestDir(controllerVersion =
|
|
66
|
+
async prepareTestDir(controllerVersion = 'dev') {
|
|
57
67
|
debug(`Preparing the test directory. JS-Controller version: "${controllerVersion}"...`);
|
|
58
68
|
// Make sure the test dir exists
|
|
59
69
|
await (0, fs_extra_1.ensureDir)(this.testDir);
|
|
60
70
|
// Write the package.json
|
|
61
71
|
const packageJson = {
|
|
62
72
|
name: path.basename(this.testDir),
|
|
63
|
-
version:
|
|
64
|
-
main:
|
|
73
|
+
version: '1.0.0',
|
|
74
|
+
main: 'index.js',
|
|
65
75
|
scripts: {
|
|
66
76
|
test: 'echo "Error: no test specified" && exit 1',
|
|
67
77
|
},
|
|
68
78
|
keywords: [],
|
|
69
|
-
author:
|
|
70
|
-
license:
|
|
79
|
+
author: '',
|
|
80
|
+
license: 'ISC',
|
|
71
81
|
dependencies: {
|
|
72
82
|
[`${this.appName}.js-controller`]: controllerVersion,
|
|
73
83
|
},
|
|
74
|
-
description:
|
|
84
|
+
description: '',
|
|
75
85
|
};
|
|
76
|
-
await (0, fs_extra_1.writeJSON)(path.join(this.testDir,
|
|
86
|
+
await (0, fs_extra_1.writeJSON)(path.join(this.testDir, 'package.json'), packageJson, {
|
|
77
87
|
spaces: 2,
|
|
78
88
|
});
|
|
79
89
|
// Delete a possible package-lock.json as it can mess with future installations
|
|
80
|
-
const pckLockPath = path.join(this.testDir,
|
|
81
|
-
if (await (0, fs_extra_1.pathExists)(pckLockPath))
|
|
90
|
+
const pckLockPath = path.join(this.testDir, 'package-lock.json');
|
|
91
|
+
if (await (0, fs_extra_1.pathExists)(pckLockPath)) {
|
|
82
92
|
await (0, fs_extra_1.unlink)(pckLockPath);
|
|
93
|
+
}
|
|
83
94
|
// Set the engineStrict flag on new Node.js versions to be in line with newer ioBroker installations
|
|
84
|
-
const nodeMajorVersion = parseInt(process.versions.node.split(
|
|
95
|
+
const nodeMajorVersion = parseInt(process.versions.node.split('.')[0], 10);
|
|
85
96
|
if (nodeMajorVersion >= 10) {
|
|
86
|
-
await (0, fs_extra_1.writeFile)(path.join(this.testDir,
|
|
97
|
+
await (0, fs_extra_1.writeFile)(path.join(this.testDir, '.npmrc'), 'engine-strict=true', 'utf8');
|
|
87
98
|
}
|
|
88
99
|
// Remember if JS-Controller is installed already. If so, we need to call `setup first` afterwards
|
|
89
100
|
const wasJsControllerInstalled = await this.isJsControllerInstalled();
|
|
90
101
|
// Defer to npm to install the controller (if it wasn't already)
|
|
91
|
-
debug(
|
|
92
|
-
await (0, executeCommand_1.executeCommand)(
|
|
102
|
+
debug('(Re-)installing JS Controller...');
|
|
103
|
+
await (0, executeCommand_1.executeCommand)('npm', ['i', '--omit=dev'], {
|
|
93
104
|
cwd: this.testDir,
|
|
94
105
|
});
|
|
95
106
|
// Prepare/clean the databases and config
|
|
96
|
-
if (wasJsControllerInstalled)
|
|
107
|
+
if (wasJsControllerInstalled) {
|
|
97
108
|
await this.setupJsController();
|
|
98
|
-
|
|
109
|
+
}
|
|
110
|
+
debug(' => done!');
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* Tests if JS-Controller is already installed
|
|
102
|
-
* @param appName The branded name of "iobroker"
|
|
103
|
-
* @param testDir The directory the integration tests are executed in
|
|
104
114
|
*/
|
|
105
115
|
async isJsControllerInstalled() {
|
|
106
|
-
debug(
|
|
116
|
+
debug('Testing if JS-Controller is installed...');
|
|
107
117
|
// We expect js-controller to be installed if the dir in <testDir>/node_modules and the data directory exist
|
|
108
|
-
const isInstalled = (await (0, fs_extra_1.pathExists)(this.testControllerDir)) &&
|
|
109
|
-
(await (0, fs_extra_1.pathExists)(this.testDataDir));
|
|
118
|
+
const isInstalled = (await (0, fs_extra_1.pathExists)(this.testControllerDir)) && (await (0, fs_extra_1.pathExists)(this.testDataDir));
|
|
110
119
|
debug(` => ${isInstalled}`);
|
|
111
120
|
return isInstalled;
|
|
112
121
|
}
|
|
@@ -114,8 +123,8 @@ class ControllerSetup {
|
|
|
114
123
|
* Tests if an instance of JS-Controller is already running by attempting to connect to the Objects DB
|
|
115
124
|
*/
|
|
116
125
|
isJsControllerRunning() {
|
|
117
|
-
debug(
|
|
118
|
-
return new Promise(
|
|
126
|
+
debug('Testing if JS-Controller is running...');
|
|
127
|
+
return new Promise(resolve => {
|
|
119
128
|
const client = new net_1.Socket();
|
|
120
129
|
const timeout = setTimeout(() => {
|
|
121
130
|
// Assume the connection failed after 1 s
|
|
@@ -127,16 +136,16 @@ class ControllerSetup {
|
|
|
127
136
|
client
|
|
128
137
|
.connect({
|
|
129
138
|
port: 9000,
|
|
130
|
-
host:
|
|
139
|
+
host: '127.0.0.1',
|
|
131
140
|
})
|
|
132
|
-
.on(
|
|
141
|
+
.on('connect', () => {
|
|
133
142
|
// The connection succeeded
|
|
134
143
|
client.destroy();
|
|
135
144
|
debug(` => true`);
|
|
136
145
|
clearTimeout(timeout);
|
|
137
146
|
resolve(true);
|
|
138
147
|
})
|
|
139
|
-
.on(
|
|
148
|
+
.on('error', () => {
|
|
140
149
|
client.destroy();
|
|
141
150
|
debug(` => false`);
|
|
142
151
|
clearTimeout(timeout);
|
|
@@ -168,24 +177,23 @@ class ControllerSetup {
|
|
|
168
177
|
* Sets up an existing JS-Controller instance for testing by executing "iobroker setup first"
|
|
169
178
|
*/
|
|
170
179
|
async setupJsController() {
|
|
171
|
-
debug(
|
|
180
|
+
debug('Initializing JS-Controller installation...');
|
|
172
181
|
// Stop the controller before calling setup first
|
|
173
|
-
await (0, executeCommand_1.executeCommand)(
|
|
182
|
+
await (0, executeCommand_1.executeCommand)('node', [`${this.appName}.js`, 'stop'], {
|
|
174
183
|
cwd: this.testControllerDir,
|
|
175
|
-
stdout:
|
|
184
|
+
stdout: 'ignore',
|
|
176
185
|
});
|
|
177
|
-
const setupResult = await (0, executeCommand_1.executeCommand)(
|
|
186
|
+
const setupResult = await (0, executeCommand_1.executeCommand)('node', [`${this.appName}.js`, 'setup', 'first', '--console'], {
|
|
178
187
|
cwd: this.testControllerDir,
|
|
179
|
-
stdout:
|
|
188
|
+
stdout: 'ignore',
|
|
180
189
|
});
|
|
181
|
-
if (setupResult.exitCode !== 0)
|
|
190
|
+
if (setupResult.exitCode !== 0) {
|
|
182
191
|
throw new Error(`${this.appName} setup first failed!`);
|
|
183
|
-
|
|
192
|
+
}
|
|
193
|
+
debug(' => done!');
|
|
184
194
|
}
|
|
185
195
|
/**
|
|
186
196
|
* Changes the objects and states db to use alternative ports
|
|
187
|
-
* @param appName The branded name of "iobroker"
|
|
188
|
-
* @param testDir The directory the integration tests are executed in
|
|
189
197
|
*/
|
|
190
198
|
setupSystemConfig(dbConnection) {
|
|
191
199
|
debug(`Moving databases to different ports...`);
|
|
@@ -193,35 +201,30 @@ class ControllerSetup {
|
|
|
193
201
|
systemConfig.objects.port = 19001;
|
|
194
202
|
systemConfig.states.port = 19000;
|
|
195
203
|
dbConnection.setSystemConfig(systemConfig);
|
|
196
|
-
debug(
|
|
204
|
+
debug(' => done!');
|
|
197
205
|
}
|
|
198
206
|
/**
|
|
199
207
|
* Clears the log dir for integration tests (and creates it if it doesn't exist)
|
|
200
|
-
* @param appName The branded name of "iobroker"
|
|
201
|
-
* @param testDir The directory the integration tests are executed in
|
|
202
208
|
*/
|
|
203
209
|
clearLogDir() {
|
|
204
|
-
debug(
|
|
210
|
+
debug('Cleaning log directory...');
|
|
205
211
|
return (0, fs_extra_1.emptyDir)((0, tools_1.getTestLogDir)(this.appName, this.testDir));
|
|
206
212
|
}
|
|
207
213
|
/**
|
|
208
214
|
* Clears the sqlite DB dir for integration tests (and creates it if it doesn't exist)
|
|
209
|
-
* @param appName The branded name of "iobroker"
|
|
210
|
-
* @param testDir The directory the integration tests are executed in
|
|
211
215
|
*/
|
|
212
216
|
clearDBDir() {
|
|
213
|
-
debug(
|
|
217
|
+
debug('Cleaning SQLite directory...');
|
|
214
218
|
return (0, fs_extra_1.emptyDir)((0, tools_1.getTestDBDir)(this.appName, this.testDir));
|
|
215
219
|
}
|
|
216
220
|
/**
|
|
217
221
|
* Disables all admin instances in the objects DB
|
|
218
|
-
* @param objects The contents of objects.json
|
|
219
222
|
*/
|
|
220
223
|
async disableAdminInstances(dbConnection) {
|
|
221
|
-
debug(
|
|
222
|
-
const instanceObjects = await dbConnection.getObjectViewAsync(
|
|
223
|
-
startkey:
|
|
224
|
-
endkey:
|
|
224
|
+
debug('Disabling admin instances...');
|
|
225
|
+
const instanceObjects = await dbConnection.getObjectViewAsync('system', 'instance', {
|
|
226
|
+
startkey: 'system.adapter.admin.',
|
|
227
|
+
endkey: 'system.adapter.admin.\u9999',
|
|
225
228
|
});
|
|
226
229
|
for (const { id, value: obj } of instanceObjects.rows) {
|
|
227
230
|
if (obj && obj.common) {
|
|
@@ -229,7 +232,7 @@ class ControllerSetup {
|
|
|
229
232
|
await dbConnection.setObject(id, obj);
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
|
-
debug(
|
|
235
|
+
debug(' => done!');
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
exports.ControllerSetup = ControllerSetup;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import EventEmitter from
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
2
|
export type ObjectsDB = Record<string, ioBroker.Object>;
|
|
3
3
|
export type StatesDB = Record<string, ioBroker.State>;
|
|
4
4
|
export interface DBConnection {
|
|
5
|
-
on(event:
|
|
6
|
-
on(event:
|
|
5
|
+
on(event: 'objectChange', handler: ioBroker.ObjectChangeHandler): this;
|
|
6
|
+
on(event: 'stateChange', handler: ioBroker.StateChangeHandler): this;
|
|
7
7
|
}
|
|
8
8
|
/** The DB connection capsules access to the states and objects DB */
|
|
9
9
|
export declare class DBConnection extends EventEmitter {
|
|
@@ -25,9 +25,9 @@ export declare class DBConnection extends EventEmitter {
|
|
|
25
25
|
private _statesClient;
|
|
26
26
|
/** The underlying states client instance that can be used to access the states DB */
|
|
27
27
|
get statesClient(): any;
|
|
28
|
-
get objectsType():
|
|
28
|
+
get objectsType(): 'file' | 'jsonl';
|
|
29
29
|
get objectsPath(): string;
|
|
30
|
-
get statesType():
|
|
30
|
+
get statesType(): 'file' | 'jsonl';
|
|
31
31
|
get statesPath(): string;
|
|
32
32
|
getSystemConfig(): any;
|
|
33
33
|
backup(): Promise<{
|
|
@@ -44,15 +44,15 @@ export declare class DBConnection extends EventEmitter {
|
|
|
44
44
|
private createObjectsDB;
|
|
45
45
|
/** Creates the states DB and sets up listeners for it */
|
|
46
46
|
private createStatesDB;
|
|
47
|
-
readonly getObject: ioBroker.Adapter[
|
|
48
|
-
readonly setObject: ioBroker.Adapter[
|
|
49
|
-
readonly delObject: ioBroker.Adapter[
|
|
50
|
-
readonly getState: ioBroker.Adapter[
|
|
51
|
-
readonly setState: ioBroker.Adapter[
|
|
52
|
-
readonly delState: ioBroker.Adapter[
|
|
47
|
+
readonly getObject: ioBroker.Adapter['getForeignObjectAsync'];
|
|
48
|
+
readonly setObject: ioBroker.Adapter['setForeignObjectAsync'];
|
|
49
|
+
readonly delObject: ioBroker.Adapter['delForeignObjectAsync'];
|
|
50
|
+
readonly getState: ioBroker.Adapter['getForeignStateAsync'];
|
|
51
|
+
readonly setState: ioBroker.Adapter['setForeignStateAsync'];
|
|
52
|
+
readonly delState: ioBroker.Adapter['delForeignStateAsync'];
|
|
53
53
|
subscribeMessage(id: string): void;
|
|
54
54
|
pushMessage(instanceId: string, msg: any, callback: (err: Error | null, id: any) => void): void;
|
|
55
|
-
readonly getObjectViewAsync: ioBroker.Adapter[
|
|
55
|
+
readonly getObjectViewAsync: ioBroker.Adapter['getObjectViewAsync'];
|
|
56
56
|
getStateIDs(pattern?: string): Promise<string[]>;
|
|
57
57
|
getObjectIDs(pattern?: string): Promise<string[]>;
|
|
58
58
|
}
|