@iobroker/testing 2.4.4 → 2.5.3

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.
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
23
  };
@@ -41,18 +32,18 @@ const path = __importStar(require("path"));
41
32
  const adapterTools_1 = require("../../../lib/adapterTools");
42
33
  const executeCommand_1 = require("../../../lib/executeCommand");
43
34
  const tools_1 = require("./tools");
44
- const debug = debug_1.default("testing:integration:ControllerSetup");
35
+ const debug = (0, debug_1.default)("testing:integration:ControllerSetup");
45
36
  class ControllerSetup {
46
37
  constructor(adapterDir, testDir, dbConnection) {
47
38
  this.adapterDir = adapterDir;
48
39
  this.testDir = testDir;
49
40
  this.dbConnection = dbConnection;
50
41
  debug("Creating ControllerSetup...");
51
- this.adapterName = adapterTools_1.getAdapterName(this.adapterDir);
52
- this.appName = adapterTools_1.getAppName(this.adapterDir);
53
- this.testAdapterDir = tools_1.getTestAdapterDir(this.adapterDir, this.testDir);
54
- this.testControllerDir = tools_1.getTestControllerDir(this.appName, this.testDir);
55
- this.testDataDir = tools_1.getTestDataDir(this.appName, this.testDir);
42
+ this.adapterName = (0, adapterTools_1.getAdapterName)(this.adapterDir);
43
+ this.appName = (0, adapterTools_1.getAppName)(this.adapterDir);
44
+ this.testAdapterDir = (0, tools_1.getTestAdapterDir)(this.adapterDir, this.testDir);
45
+ this.testControllerDir = (0, tools_1.getTestControllerDir)(this.appName, this.testDir);
46
+ this.testDataDir = (0, tools_1.getTestDataDir)(this.appName, this.testDir);
56
47
  debug(` directories:`);
57
48
  debug(` controller: ${this.testControllerDir}`);
58
49
  debug(` adapter: ${this.testAdapterDir}`);
@@ -60,56 +51,52 @@ class ControllerSetup {
60
51
  debug(` appName: ${this.appName}`);
61
52
  debug(` adapterName: ${this.adapterName}`);
62
53
  }
63
- prepareTestDir() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- debug("Preparing the test directory...");
66
- // Make sure the test dir exists
67
- yield fs_extra_1.ensureDir(this.testDir);
68
- // Write the package.json
69
- const packageJson = {
70
- name: path.basename(this.testDir),
71
- version: "1.0.0",
72
- main: "index.js",
73
- scripts: {
74
- test: 'echo "Error: no test specified" && exit 1',
75
- },
76
- keywords: [],
77
- author: "",
78
- license: "ISC",
79
- dependencies: {
80
- [`${this.appName}.js-controller`]: `https://github.com/${this.appName}/${this.appName}.js-controller/tarball/master`,
81
- },
82
- description: "",
83
- };
84
- yield fs_extra_1.writeJSON(path.join(this.testDir, "package.json"), packageJson, {
85
- spaces: 2,
86
- });
87
- // Delete a possible package-lock.json as it can mess with future installations
88
- const pckLockPath = path.join(this.testDir, "package-lock.json");
89
- if (yield fs_extra_1.pathExists(pckLockPath))
90
- yield fs_extra_1.unlink(pckLockPath);
91
- // Set the engineStrict flag on new Node.js versions to be in line with newer ioBroker installations
92
- const nodeMajorVersion = parseInt(process.versions.node.split(".")[0], 10);
93
- if (nodeMajorVersion >= 10) {
94
- yield fs_extra_1.writeFile(path.join(this.testDir, ".npmrc"), "engine-strict=true", "utf8");
95
- }
96
- debug(" => done!");
54
+ async prepareTestDir() {
55
+ debug("Preparing the test directory...");
56
+ // Make sure the test dir exists
57
+ await (0, fs_extra_1.ensureDir)(this.testDir);
58
+ // Write the package.json
59
+ const packageJson = {
60
+ name: path.basename(this.testDir),
61
+ version: "1.0.0",
62
+ main: "index.js",
63
+ scripts: {
64
+ test: 'echo "Error: no test specified" && exit 1',
65
+ },
66
+ keywords: [],
67
+ author: "",
68
+ license: "ISC",
69
+ dependencies: {
70
+ [`${this.appName}.js-controller`]: "dev",
71
+ },
72
+ description: "",
73
+ };
74
+ await (0, fs_extra_1.writeJSON)(path.join(this.testDir, "package.json"), packageJson, {
75
+ spaces: 2,
97
76
  });
77
+ // Delete a possible package-lock.json as it can mess with future installations
78
+ const pckLockPath = path.join(this.testDir, "package-lock.json");
79
+ if (await (0, fs_extra_1.pathExists)(pckLockPath))
80
+ await (0, fs_extra_1.unlink)(pckLockPath);
81
+ // Set the engineStrict flag on new Node.js versions to be in line with newer ioBroker installations
82
+ const nodeMajorVersion = parseInt(process.versions.node.split(".")[0], 10);
83
+ if (nodeMajorVersion >= 10) {
84
+ await (0, fs_extra_1.writeFile)(path.join(this.testDir, ".npmrc"), "engine-strict=true", "utf8");
85
+ }
86
+ debug(" => done!");
98
87
  }
99
88
  /**
100
89
  * Tests if JS-Controller is already installed
101
90
  * @param appName The branded name of "iobroker"
102
91
  * @param testDir The directory the integration tests are executed in
103
92
  */
104
- isJsControllerInstalled() {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- debug("Testing if JS-Controller is installed...");
107
- // We expect js-controller to be installed if the dir in <testDir>/node_modules and the data directory exist
108
- const isInstalled = (yield fs_extra_1.pathExists(this.testControllerDir)) &&
109
- (yield fs_extra_1.pathExists(this.testDataDir));
110
- debug(` => ${isInstalled}`);
111
- return isInstalled;
112
- });
93
+ async isJsControllerInstalled() {
94
+ debug("Testing if JS-Controller is installed...");
95
+ // We expect js-controller to be installed if the dir in <testDir>/node_modules and the data directory exist
96
+ const isInstalled = (await (0, fs_extra_1.pathExists)(this.testControllerDir)) &&
97
+ (await (0, fs_extra_1.pathExists)(this.testDataDir));
98
+ debug(` => ${isInstalled}`);
99
+ return isInstalled;
113
100
  }
114
101
  /**
115
102
  * Tests if an instance of JS-Controller is already running by attempting to connect to the Objects DB
@@ -168,38 +155,36 @@ class ControllerSetup {
168
155
  * @param appName The branded name of "iobroker"
169
156
  * @param testDir The directory the integration tests are executed in
170
157
  */
171
- setupJsController() {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- debug("Initializing JS-Controller installation...");
174
- // Stop the controller before calling setup first
175
- yield executeCommand_1.executeCommand("node", [`${this.appName}.js`, "stop"], {
176
- cwd: this.testControllerDir,
177
- stdout: "ignore",
178
- });
179
- const setupResult = yield executeCommand_1.executeCommand("node", [`${this.appName}.js`, "setup", "first", "--console"], {
180
- cwd: this.testControllerDir,
181
- stdout: "ignore",
182
- });
183
- if (setupResult.exitCode !== 0)
184
- throw new Error(`${this.appName} setup first failed!`);
185
- debug(" => done!");
158
+ async setupJsController() {
159
+ debug("Initializing JS-Controller installation...");
160
+ // Stop the controller before calling setup first
161
+ await (0, executeCommand_1.executeCommand)("node", [`${this.appName}.js`, "stop"], {
162
+ cwd: this.testControllerDir,
163
+ stdout: "ignore",
164
+ });
165
+ const setupResult = await (0, executeCommand_1.executeCommand)("node", [`${this.appName}.js`, "setup", "first", "--console"], {
166
+ cwd: this.testControllerDir,
167
+ stdout: "ignore",
186
168
  });
169
+ if (setupResult.exitCode !== 0)
170
+ throw new Error(`${this.appName} setup first failed!`);
171
+ debug(" => done!");
187
172
  }
188
173
  /**
189
174
  * Changes the objects and states db to use alternative ports
190
175
  * @param appName The branded name of "iobroker"
191
176
  * @param testDir The directory the integration tests are executed in
192
177
  */
193
- setupSystemConfig() {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- debug("Moving databases to different ports...");
196
- const systemFilename = path.join(this.testDataDir, `${this.appName}.json`);
197
- const systemConfig = require(systemFilename);
198
- systemConfig.objects.port = 19001;
199
- systemConfig.states.port = 19000;
200
- yield fs_extra_1.writeFile(systemFilename, JSON.stringify(systemConfig, null, 2));
201
- debug(" => done!");
202
- });
178
+ async setupSystemConfig() {
179
+ debug(`Moving databases to different ports and setting type "file"...`);
180
+ const systemFilename = path.join(this.testDataDir, `${this.appName}.json`);
181
+ const systemConfig = require(systemFilename);
182
+ systemConfig.objects.port = 19001;
183
+ systemConfig.objects.type = "file";
184
+ systemConfig.states.port = 19000;
185
+ systemConfig.states.type = "file";
186
+ await (0, fs_extra_1.writeFile)(systemFilename, JSON.stringify(systemConfig, null, 2));
187
+ debug(" => done!");
203
188
  }
204
189
  /**
205
190
  * Clears the log dir for integration tests (and creates it if it doesn't exist)
@@ -208,7 +193,7 @@ class ControllerSetup {
208
193
  */
209
194
  clearLogDir() {
210
195
  debug("Cleaning log directory...");
211
- return fs_extra_1.emptyDir(tools_1.getTestLogDir(this.appName, this.testDir));
196
+ return (0, fs_extra_1.emptyDir)((0, tools_1.getTestLogDir)(this.appName, this.testDir));
212
197
  }
213
198
  /**
214
199
  * Clears the sqlite DB dir for integration tests (and creates it if it doesn't exist)
@@ -217,28 +202,26 @@ class ControllerSetup {
217
202
  */
218
203
  clearDBDir() {
219
204
  debug("Cleaning SQLite directory...");
220
- return fs_extra_1.emptyDir(tools_1.getTestDBDir(this.appName, this.testDir));
205
+ return (0, fs_extra_1.emptyDir)((0, tools_1.getTestDBDir)(this.appName, this.testDir));
221
206
  }
222
207
  /**
223
208
  * Disables all admin instances in the objects DB
224
209
  * @param objects The contents of objects.json
225
210
  */
226
- disableAdminInstances() {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- debug("Disabling admin instances...");
229
- const objects = yield this.dbConnection.readObjectsDB();
230
- if (objects) {
231
- for (const id of Object.keys(objects)) {
232
- if (/^system\.adapter\.admin\.\d.+$/.test(id)) {
233
- const obj = objects[id];
234
- if (obj && obj.common)
235
- obj.common.enabled = false;
236
- }
211
+ async disableAdminInstances() {
212
+ debug("Disabling admin instances...");
213
+ const objects = await this.dbConnection.readObjectsDB();
214
+ if (objects) {
215
+ for (const id of Object.keys(objects)) {
216
+ if (/^system\.adapter\.admin\.\d.+$/.test(id)) {
217
+ const obj = objects[id];
218
+ if (obj && obj.common)
219
+ obj.common.enabled = false;
237
220
  }
238
- yield this.dbConnection.writeObjectsDB(objects);
239
221
  }
240
- debug(" => done!");
241
- });
222
+ await this.dbConnection.writeObjectsDB(objects);
223
+ }
224
+ debug(" => done!");
242
225
  }
243
226
  }
244
227
  exports.ControllerSetup = ControllerSetup;
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
21
  Object.defineProperty(exports, "__esModule", { value: true });
31
22
  exports.DBConnection = void 0;
32
23
  const fs_extra_1 = require("fs-extra");
@@ -41,46 +32,38 @@ class DBConnection {
41
32
  constructor(appName, testDir) {
42
33
  this.appName = appName;
43
34
  this.testDir = testDir;
44
- this.testDataDir = tools_1.getTestDataDir(appName, testDir);
35
+ this.testDataDir = (0, tools_1.getTestDataDir)(appName, testDir);
45
36
  this.objectsPath = path.join(this.testDataDir, "objects.json");
46
37
  this.statesPath = path.join(this.testDataDir, "states.json");
47
38
  }
48
39
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
49
- readObjectsDB() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- // debug(`reading objects db...`);
52
- // debug(` dataDir: ${dataDir}`);
53
- // debug(` objectsPath: ${objectsPath}`);
54
- if (yield fs_extra_1.pathExists(this.objectsPath)) {
55
- // debug(` exists: true`);
56
- return fs_extra_1.readJSON(this.objectsPath, { encoding: "utf8" });
57
- }
58
- });
40
+ async readObjectsDB() {
41
+ // debug(`reading objects db...`);
42
+ // debug(` dataDir: ${dataDir}`);
43
+ // debug(` objectsPath: ${objectsPath}`);
44
+ if (await (0, fs_extra_1.pathExists)(this.objectsPath)) {
45
+ // debug(` exists: true`);
46
+ return (0, fs_extra_1.readJSON)(this.objectsPath, { encoding: "utf8" });
47
+ }
59
48
  }
60
- writeObjectsDB(objects) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- if (!objects)
63
- return;
64
- return fs_extra_1.writeJSON(this.objectsPath, objects);
65
- });
49
+ async writeObjectsDB(objects) {
50
+ if (!objects)
51
+ return;
52
+ return (0, fs_extra_1.writeJSON)(this.objectsPath, objects);
66
53
  }
67
- writeStatesDB(states) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- if (!states)
70
- return;
71
- return fs_extra_1.writeJSON(this.statesPath, states);
72
- });
54
+ async writeStatesDB(states) {
55
+ if (!states)
56
+ return;
57
+ return (0, fs_extra_1.writeJSON)(this.statesPath, states);
73
58
  }
74
- readStatesDB() {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- // debug(`reading states db...`);
77
- // debug(` dataDir: ${dataDir}`);
78
- // debug(` statesPath: ${statesPath}`);
79
- if (yield fs_extra_1.pathExists(this.statesPath)) {
80
- // debug(` exists: true`);
81
- return fs_extra_1.readJSON(this.statesPath, { encoding: "utf8" });
82
- }
83
- });
59
+ async readStatesDB() {
60
+ // debug(`reading states db...`);
61
+ // debug(` dataDir: ${dataDir}`);
62
+ // debug(` statesPath: ${statesPath}`);
63
+ if (await (0, fs_extra_1.pathExists)(this.statesPath)) {
64
+ // debug(` exists: true`);
65
+ return (0, fs_extra_1.readJSON)(this.statesPath, { encoding: "utf8" });
66
+ }
84
67
  }
85
68
  /**
86
69
  * Creates a backup of the objects and states DB, so it can be restored after each test
@@ -88,23 +71,19 @@ class DBConnection {
88
71
  * @param testDir The directory the integration tests are executed in
89
72
  */
90
73
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
91
- readDB() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const objects = yield this.readObjectsDB();
94
- const states = yield this.readStatesDB();
95
- return { objects, states };
96
- });
74
+ async readDB() {
75
+ const objects = await this.readObjectsDB();
76
+ const states = await this.readStatesDB();
77
+ return { objects, states };
97
78
  }
98
79
  /**
99
80
  * Restores a previous backup of the objects and states DB
100
81
  * @param appName The branded name of "iobroker"
101
82
  * @param testDir The directory the integration tests are executed in
102
83
  */
103
- writeDB(objects, states) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- yield this.writeObjectsDB(objects);
106
- yield this.writeStatesDB(states);
107
- });
84
+ async writeDB(objects, states) {
85
+ await this.writeObjectsDB(objects);
86
+ await this.writeStatesDB(states);
108
87
  }
109
88
  }
110
89
  exports.DBConnection = DBConnection;