@iobroker/legacy-testing 0.3.4 → 0.3.6

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 +19 -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.6 (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.6",
3
3
  "name": "@iobroker/legacy-testing",
4
4
  "main": "setup.js",
5
5
  "files": [
package/setup.js CHANGED
@@ -262,6 +262,7 @@ async function installAdapter(customAdapterName, cb) {
262
262
  cb = customAdapterName;
263
263
  customAdapterName = null;
264
264
  }
265
+
265
266
  customAdapterName = customAdapterName || pkg.name;
266
267
  console.log(`[${customAdapterName}] Install adapter...`);
267
268
 
@@ -288,29 +289,7 @@ async function installAdapter(customAdapterName, cb) {
288
289
 
289
290
  const name = (customAdapterName.split('@')[0]).split('.').pop(); // extract from iobroker.adaptername@version => adaptername
290
291
 
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
- }
292
+ await checkIsAdapterInstalledAsync(null, name);
314
293
  console.log(`[${customAdapterName}] Adapter installed.`);
315
294
  cb && cb();
316
295
  }
@@ -320,25 +299,6 @@ function installAdapterAsync(customAdapterName) {
320
299
  installAdapter(customAdapterName, () => resolve()));
321
300
  }
322
301
 
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
302
  function waitForEndAsync(_pid) {
343
303
  if (!_pid) {
344
304
  return {code: -1, signal: -1};
@@ -414,13 +374,14 @@ async function installJsController(preInstalledAdapters, cb) {
414
374
  stdio: [0, 1, 2, 'ipc']
415
375
  });
416
376
  }
417
- await waitForEnd(__pid);
377
+ await waitForEndAsync(__pid);
418
378
  await checkIsControllerInstalledAsync();
419
379
  } else {
420
380
  // check if port 9000 is free, else admin adapter will be added to running instance
421
381
  const {Socket} = require('net')
422
382
  const client = new Socket();
423
383
  client.on('error', () => {
384
+ // ignore
424
385
  });
425
386
  client.connect(9000, '127.0.0.1', () => {
426
387
  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 +413,7 @@ async function installJsController(preInstalledAdapters, cb) {
452
413
  stdio: [0, 1, 2, 'ipc'],
453
414
  });
454
415
  }
455
- await waitForEnd(__pid);
416
+ await waitForEndAsync(__pid);
456
417
  }
457
418
 
458
419
  // let npm install admin and run setup
@@ -496,9 +457,20 @@ async function installJsController(preInstalledAdapters, cb) {
496
457
  }
497
458
 
498
459
  function copyAdapterToController() {
499
- console.log('Copy adapter...');
500
- // 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`]);
460
+ console.log('Pack adapter...');
461
+
462
+ fs.existsSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`) && fs.unlinkSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`);
463
+ fs.existsSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`) && fs.unlinkSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
464
+
465
+ cp.execSync(`npm pack`, {
466
+ cwd: rootDir,
467
+ stdio: [0, 1, 2],
468
+ });
469
+ copyFileSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`, `${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
470
+ cp.execSync(`npm install ${pkg.name}-${pkg.version}.tgz --prefix ./ --production`, {
471
+ cwd: `${rootDir}tmp`,
472
+ stdio: [0, 1, 2],
473
+ });
502
474
  console.log('Adapter copied.');
503
475
  }
504
476