@iobroker/legacy-testing 0.3.4 → 0.3.5

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/setup.js +12 -47
package/README.md CHANGED
@@ -11,7 +11,7 @@ Legacy test modules for ioBroker
11
11
 
12
12
  ## Changelog
13
13
  <!-- ### **WORK IN PROGRESS** -->
14
- ### 0.3.4 (2023-05-08)
14
+ ### 0.3.5 (2023-05-08)
15
15
  * (bluefox) Added possibility to install additional adapters at start
16
16
  * (bluefox) Added setOfflineState/getOfflineState
17
17
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.4",
2
+ "version": "0.3.5",
3
3
  "name": "@iobroker/legacy-testing",
4
4
  "main": "setup.js",
5
5
  "files": [
package/setup.js CHANGED
@@ -262,8 +262,13 @@ async function installAdapter(customAdapterName, cb) {
262
262
  cb = customAdapterName;
263
263
  customAdapterName = null;
264
264
  }
265
- customAdapterName = customAdapterName || pkg.name;
266
- console.log(`[${customAdapterName}] Install adapter...`);
265
+ console.log(`[${customAdapterName || pkg.name}] Install adapter...`);
266
+
267
+ // if own adapter
268
+ if (!customAdapterName) {
269
+ installCustomAdapter(pkg.name); // force install from the current directory
270
+ customAdapterName = pkg.name;
271
+ }
267
272
 
268
273
  if (customAdapterName.includes('@')) {
269
274
  installCustomAdapter(customAdapterName);
@@ -288,29 +293,7 @@ async function installAdapter(customAdapterName, cb) {
288
293
 
289
294
  const name = (customAdapterName.split('@')[0]).split('.').pop(); // extract from iobroker.adaptername@version => adaptername
290
295
 
291
- try {
292
- await checkIsAdapterInstalledAsync(null, name);
293
- } catch (err) {
294
- console.warn(`[${customAdapterName}] Adapter not installed: ${err}`);
295
- // try workaround
296
- installCustomAdapter(customAdapterName);
297
- // make first install
298
- if (debug) {
299
- cp.execSync(`node ${startFile} add ${customAdapterName} --enabled false`, {
300
- cwd: `${rootDir}tmp`,
301
- stdio: [0, 1, 2],
302
- });
303
- } else {
304
- // add controller
305
- const _pid = cp.fork(startFile, ['add', customAdapterName, '--enabled', 'false'], {
306
- cwd: `${rootDir}tmp`,
307
- stdio: [0, 1, 2, 'ipc'],
308
- });
309
-
310
- await waitForEndAsync(_pid);
311
- }
312
- await checkIsAdapterInstalledAsync(null, name);
313
- }
296
+ await checkIsAdapterInstalledAsync(null, name);
314
297
  console.log(`[${customAdapterName}] Adapter installed.`);
315
298
  cb && cb();
316
299
  }
@@ -320,25 +303,6 @@ function installAdapterAsync(customAdapterName) {
320
303
  installAdapter(customAdapterName, () => resolve()));
321
304
  }
322
305
 
323
- function waitForEnd(_pid, cb) {
324
- if (!_pid) {
325
- cb(-1, -1);
326
- } else {
327
- _pid.on('exit', (code, signal) => {
328
- if (_pid) {
329
- _pid = null;
330
- cb(code, signal);
331
- }
332
- });
333
- _pid.on('close', (code, signal) => {
334
- if (_pid) {
335
- _pid = null;
336
- cb(code, signal);
337
- }
338
- });
339
- }
340
- }
341
-
342
306
  function waitForEndAsync(_pid) {
343
307
  if (!_pid) {
344
308
  return {code: -1, signal: -1};
@@ -414,13 +378,14 @@ async function installJsController(preInstalledAdapters, cb) {
414
378
  stdio: [0, 1, 2, 'ipc']
415
379
  });
416
380
  }
417
- await waitForEnd(__pid);
381
+ await waitForEndAsync(__pid);
418
382
  await checkIsControllerInstalledAsync();
419
383
  } else {
420
384
  // check if port 9000 is free, else admin adapter will be added to running instance
421
385
  const {Socket} = require('net')
422
386
  const client = new Socket();
423
387
  client.on('error', () => {
388
+ // ignore
424
389
  });
425
390
  client.connect(9000, '127.0.0.1', () => {
426
391
  console.error('Cannot initiate the first run of test, because one instance of application is running on this PC. Stop it and repeat.');
@@ -452,7 +417,7 @@ async function installJsController(preInstalledAdapters, cb) {
452
417
  stdio: [0, 1, 2, 'ipc'],
453
418
  });
454
419
  }
455
- await waitForEnd(__pid);
420
+ await waitForEndAsync(__pid);
456
421
  }
457
422
 
458
423
  // let npm install admin and run setup
@@ -498,7 +463,7 @@ async function installJsController(preInstalledAdapters, cb) {
498
463
  function copyAdapterToController() {
499
464
  console.log('Copy adapter...');
500
465
  // Copy adapter to tmp/node_modules/appName.adapter
501
- copyFolderRecursiveSync(rootDir, `${rootDir}tmp/node_modules/`, ['.github', '.idea', 'test', 'tmp', '.git', 'src', 'src-widgets', `${appName}.js-controller`]);
466
+ copyFolderRecursiveSync(rootDir, `${rootDir}tmp/node_modules/`, ['node_modules', '.github', '.idea', 'test', 'tmp', '.git', 'src', 'src-widgets', `${appName}.js-controller`]);
502
467
  console.log('Adapter copied.');
503
468
  }
504
469