From 189393452456b2f0a76427d80672ca96a8d4963b Mon Sep 17 00:00:00 2001 From: Wraithan McCarroll Date: Tue, 29 Oct 2019 18:13:32 -0700 Subject: [PATCH] reverting a style change I made and better comments in tests --- src/cmd/serial.js | 10 +++++----- src/cmd/serial.test.js | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cmd/serial.js b/src/cmd/serial.js index 7f3ce515d..06211c656 100644 --- a/src/cmd/serial.js +++ b/src/cmd/serial.js @@ -23,6 +23,7 @@ const ensureError = require('../lib/utilities').ensureError; const cmd = path.basename(process.argv[1]); const arrow = chalk.green('>'); const alert = chalk.yellow('!'); +const timeoutError = 'Serial timed out'; function protip(){ const args = Array.prototype.slice.call(arguments); @@ -30,7 +31,6 @@ function protip(){ console.log.apply(null, args); } -const TIMEOUT_ERROR_MESSAGE = 'Serial timed out'; // An LTE device may take up to 18 seconds to power up the modem const MODULE_INFO_COMMAND_TIMEOUT = 20000; @@ -617,7 +617,7 @@ module.exports = class SerialCommand { return !!matches; }) .catch((err) => { - if (err !== TIMEOUT_ERROR_MESSAGE){ + if (err !== timeoutError){ throw err; } return false; @@ -898,7 +898,7 @@ module.exports = class SerialCommand { } function startTimeout(to){ - self._serialTimeout = setTimeout(() => reject(TIMEOUT_ERROR_MESSAGE), to); + self._serialTimeout = setTimeout(() => reject(timeoutError), to); } function resetTimeout(){ @@ -1228,7 +1228,7 @@ module.exports = class SerialCommand { reject('Serial port closed early'); } - function startTimeout(to, message = TIMEOUT_ERROR_MESSAGE){ + function startTimeout(to, message = timeoutError){ self._serialTimeout = setTimeout(() => { reject(message); }, to); @@ -1319,7 +1319,7 @@ module.exports = class SerialCommand { serialPort.pipe(parser); const failTimer = setTimeout(() => { - reject(TIMEOUT_ERROR_MESSAGE); + reject(timeoutError); }, failDelay); parser.on('data', (data) => { diff --git a/src/cmd/serial.test.js b/src/cmd/serial.test.js index 3a428c191..898dce4fa 100644 --- a/src/cmd/serial.test.js +++ b/src/cmd/serial.test.js @@ -69,6 +69,8 @@ describe('Serial Command', () => { const mockSerial = new MockSerial(); serial.serialPort = mockSerial; const wifiPromise = serial._serialWifiConfig(device); + // This allows _serialWifiConfig's internal promises to run and try to + // connect to the serial device before moving time forward. process.nextTick(() => { clock.tick(5010); });