diff --git a/package.json b/package.json index 443c29c..124e76e 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,10 @@ "dependencies": { "async": "^2.6.1", "serialport": "^6.2.2", - "tape": "^4.9.1" + "tape": "^4.9.1", + "testbed-query-fixtures": "^1.0.0" + }, + "devDependencies": { + "homedir": "^0.6.0" } } diff --git a/test/test.js b/test/test.js index f33222c..20ceecb 100644 --- a/test/test.js +++ b/test/test.js @@ -1,16 +1,35 @@ var async = require("async"); +var homedir = require("homedir")(); var spawn = require("child_process").spawn; var SerialPort = require("serialport"); var path = require("path"); var test = require("tape"); +var testbed = require("testbed-query-fixtures"); const exec = path.join(process.env.IDF_PATH, "components", "esptool_py", "esptool", "esptool.py"); -const portString = "/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_SERIAL_ID-if00-port0"; const buildPath = path.join(__dirname, "lora32", "build"); -const TB_DEV1 = process.env.TB_DEV1 || "0000"; -const TB_DEV2 = process.env.TB_DEV2 || "0001"; +try { + var testbedConfig = require(path.join(homedir, ".testbed.json")); +} catch(e) { + console.log(e); + console.error("testbed.json fixture file not found."); + + process.exit(1); +} + +var devices = testbed({ + f: [ "esp32", "lora" ], + fixtures: testbedConfig.fixtures +}); + +if(devices.length < 2) { + throw new Error("Not enough test devices available"); +} + +const TB_DEV1 = devices[0].DEVNAME; +const TB_DEV2 = devices[1].DEVNAME; var args = [ "--chip", @@ -108,20 +127,20 @@ async.series([ async.parallel([ function(done) { - flash(portString.replace("SERIAL_ID", TB_DEV1), done); + flash(TB_DEV1, done); }, function(done) { - flash(portString.replace("SERIAL_ID", TB_DEV2), done); + flash(TB_DEV2, done); }], next); }, function(next) { async.parallel({ dev1: function(done) { - serial(portString.replace("SERIAL_ID", TB_DEV1), done); + serial(TB_DEV1, done); }, dev2: function(done) { - serial(portString.replace("SERIAL_ID", TB_DEV2), done); + serial(TB_DEV2, done); } }, next); }