From 4e24a5512575f9ab72e7f5f18d084053b04ae3e3 Mon Sep 17 00:00:00 2001 From: step2yeung Date: Mon, 25 Oct 2021 10:14:42 -0700 Subject: [PATCH 1/3] return 0 for browserId not found --- lib/commands/exam.js | 22 ++++++++++------------ lib/utils/test-page-helper.js | 3 ++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/commands/exam.js b/lib/commands/exam.js index c7d641cb..859edbe7 100644 --- a/lib/commands/exam.js +++ b/lib/commands/exam.js @@ -287,19 +287,17 @@ module.exports = TestCommand.extend({ const launcherId = this.launcher.id; if (!failed && commands.get('loadBalance')) { - try { - const browserId = getBrowserId(this.launcher); - log.info(`Browser ${browserId} exiting. [ # of modules in current module queue ${testemEvents.stateManager.getTestModuleQueue().length} ]`); - } catch (err) { - const moduleQueueMessage = testemEvents.stateManager.getTestModuleQueue() === null ? - 'testModuleQueue is not set.' : - `[ # of modules in current module queue ${testemEvents.stateManager.getTestModuleQueue().length} ]`; - - if (typeof err === 'object' && err !== null) { - err.message = `${err.message} \n ${moduleQueueMessage}`; - ui.writeLine(err.message); + const browserId = getBrowserId(this.launcher); + log.info(`Browser ${browserId} exiting. [ # of modules in current module queue ${testemEvents.stateManager.getTestModuleQueue().length} ]`); + + // if getBrowserId cannot get the browserId + // but the test queue is not empty, report the number of test modules left in the queue + // otherwise, fail because testModuleQueue was not set + if (browserId === 0) { + if (testemEvents.stateManager.getTestModuleQueue() !== null) { + ui.writeLine(`[ # of modules in current module queue ${testemEvents.stateManager.getTestModuleQueue().length} ]`); } else { - throw new Error(moduleQueueMessage); + throw new Error('testModuleQueue is not set.'); } } } diff --git a/lib/utils/test-page-helper.js b/lib/utils/test-page-helper.js index c3b562b9..2306d293 100644 --- a/lib/utils/test-page-helper.js +++ b/lib/utils/test-page-helper.js @@ -138,8 +138,9 @@ function getBrowserId(launcher) { } } catch(err) { const errMsg = `${err.message} \n${err.stack} \nLauncher Settings: ${JSON.stringify(launcher.settings, null, 2)}`; - throw new Error(errMsg); + console.warn(errMsg); } + return 0; } /** From 4eec476db7e19e840cd014ca8ad2ea09c0c66460 Mon Sep 17 00:00:00 2001 From: step2yeung Date: Mon, 25 Oct 2021 17:29:56 -0700 Subject: [PATCH 2/3] fix typo --- lib/commands/exam.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/exam.js b/lib/commands/exam.js index 93c2c061..37231dde 100644 --- a/lib/commands/exam.js +++ b/lib/commands/exam.js @@ -297,7 +297,7 @@ module.exports = TestCommand.extend({ `Browser ${browserId} exiting. [ # of modules in current module queue ${ testemEvents.stateManager.getTestModuleQueue().length } ]` - + ); // if getBrowserId cannot get the browserId // but the test queue is not empty, report the number of test modules left in the queue // otherwise, fail because testModuleQueue was not set From 7b1df6fc4efde269ed056fcae7b0c681f8a6fec2 Mon Sep 17 00:00:00 2001 From: step2yeung Date: Mon, 25 Oct 2021 17:38:09 -0700 Subject: [PATCH 3/3] fix lint errors --- lib/commands/exam.js | 9 +++++---- lib/utils/test-page-helper.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/commands/exam.js b/lib/commands/exam.js index 37231dde..2ccf5465 100644 --- a/lib/commands/exam.js +++ b/lib/commands/exam.js @@ -294,9 +294,9 @@ module.exports = TestCommand.extend({ if (!failed && commands.get('loadBalance')) { const browserId = getBrowserId(this.launcher); log.info( - `Browser ${browserId} exiting. [ # of modules in current module queue ${ - testemEvents.stateManager.getTestModuleQueue().length - } ]` + `Browser ${browserId} exiting. [ # of modules in current module queue ${ + testemEvents.stateManager.getTestModuleQueue().length + } ]` ); // if getBrowserId cannot get the browserId // but the test queue is not empty, report the number of test modules left in the queue @@ -306,7 +306,8 @@ module.exports = TestCommand.extend({ ui.writeLine( `[ # of modules in current module queue ${ testemEvents.stateManager.getTestModuleQueue().length - } ]`); + } ]` + ); } else { throw new Error('testModuleQueue is not set.'); } diff --git a/lib/utils/test-page-helper.js b/lib/utils/test-page-helper.js index d75479a3..f77c815e 100644 --- a/lib/utils/test-page-helper.js +++ b/lib/utils/test-page-helper.js @@ -133,7 +133,7 @@ function getBrowserId(launcher) { if (Array.isArray(browserIdMatch) !== null && browserIdMatch !== null) { return browserIdMatch[1]; } - } catch(err) { + } catch (err) { const errMsg = `${err.message} \n${ err.stack } \nLauncher Settings: ${JSON.stringify(launcher.settings, null, 2)}`;