Skip to content

Commit aea1502

Browse files
author
Pavel Petroshenko
authored
Merge pull request #52 from electricimp/develop
v2.4.2
2 parents 5daaa64 + ec9c32e commit aea1502

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

Diff for: lib/util/TestHelper.js

+42-18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class TestHelper {
7474
this._devices = null;
7575
this._success = true;
7676

77+
this._testFailures = [];
78+
this._testMethod = null;
79+
this._testFile = null;
80+
this._tests = 0;
81+
this._assertions = 0;
82+
this._failures = 0;
83+
7784
TestDebugMixin.call(this);
7885
this._init(options);
7986

@@ -141,19 +148,30 @@ class TestHelper {
141148
return this._runTestOnDeviceGroup(testFile);
142149
}),
143150
Promise.resolve())).then(() => {
144-
if (this._stopCommand) {
145-
this._debug(UserInteractor.MESSAGES.TEST_STOP);
146-
}
147-
return Promise.resolve();
148-
}).then(() => {
149-
this._blank();
150-
151-
if (this._success) {
152-
this._info(c.green(UserInteractor.MESSAGES.TEST_SUCCEEDED));
153-
} else {
154-
this._info(c.red(UserInteractor.ERRORS.TEST_FAILED));
155-
}
156-
});
151+
if (this._stopCommand) {
152+
this._debug(UserInteractor.MESSAGES.TEST_STOP);
153+
}
154+
return Promise.resolve();
155+
}).then(() => {
156+
this._blank();
157+
this._info(UserInteractor.MESSAGES.TEST_SUMMARY_HEADER);
158+
this._blank();
159+
this._testFailures.forEach((item, index) => {
160+
this._info(Util.format(UserInteractor.MESSAGES.TEST_SUMMARY_FAILURE, index + 1, item.test));
161+
this._info(Util.format(UserInteractor.MESSAGES.TEST_SUMMARY_AT, item.file));
162+
this._info(Util.format(UserInteractor.MESSAGES.TEST_SUMMARY_ERROR, item.result));
163+
this._blank();
164+
});
165+
this._info(Util.format(UserInteractor.MESSAGES.TEST_SESSION_RESULT, this._tests, this._assertions, this._failures));
166+
this._info(UserInteractor.MESSAGES.TEST_SUMMARY_FOOTER);
167+
this._blank();
168+
169+
if (this._success) {
170+
this._info(c.green(UserInteractor.MESSAGES.TEST_SUCCEEDED));
171+
} else {
172+
this._info(c.red(UserInteractor.ERRORS.TEST_FAILED));
173+
}
174+
});
157175
}
158176

159177
_runTestOnDeviceGroup(testFile) {
@@ -201,7 +219,7 @@ class TestHelper {
201219
if (testIsAgentOnly) {
202220
this._info(UserInteractor.MESSAGES.TEST_AGENT_ONLY);
203221
}
204-
this._info(Util.format(UserInteractor.MESSAGES.TEST_USE_DEVICE,
222+
this._info(Util.format(UserInteractor.MESSAGES.TEST_USE_DEVICE,
205223
device.name ? device.name : '', device.id, deviceIndex, this._devices.length));
206224

207225
// check online state
@@ -219,7 +237,7 @@ class TestHelper {
219237
// run test session
220238
return this._runSession(device, testFile.type, this._deviceGroup)
221239

222-
// error
240+
// error
223241
.catch((error) => {
224242
this._onError(error);
225243
})
@@ -315,7 +333,7 @@ class TestHelper {
315333
}
316334

317335
for (const searchPattern of searchPatterns) {
318-
for (const file of glob.sync(searchPattern, {cwd: configCwd})) {
336+
for (const file of glob.sync(searchPattern, { cwd: configCwd })) {
319337
// TODO: would it better to add the testFileName to the searchPatterns?
320338
if (testFileName != null && testFileName.length > 0 && file.search(testFileName) < 0) {
321339
this._debug(Util.format(UserInteractor.MESSAGES.TEST_SKIP_TEST, file));
@@ -340,6 +358,9 @@ class TestHelper {
340358
_getSessionCode(testFile) {
341359
let agentCode, deviceCode;
342360

361+
// save current test file name
362+
this._testFile = testFile.name;
363+
343364
// [info]
344365
this._info(Util.format(UserInteractor.MESSAGES.TEST_USE_FILE, testFile.type, testFile.name));
345366

@@ -560,6 +581,7 @@ ${'partnerpath' in testFile ? '@include "' + backslashToSlash(testFile.partnerpa
560581

561582
this._session.on('message', (e) => {
562583
if ('test' === e.type) {
584+
this._testMethod = e.message;
563585
this._testLine(e.message);
564586
} else if ('externalCommandOutput' === e.type) {
565587
this._print(e.message);
@@ -594,6 +616,9 @@ ${'partnerpath' in testFile ? '@include "' + backslashToSlash(testFile.partnerpa
594616
this._session.on('done', () => {
595617
this._sessionStartWatchdog.stop();
596618
this._sessionTestMessagesWatchdog.stop();
619+
this._tests += this._session.tests;
620+
this._failures += this._session.failures;
621+
this._assertions += this._session.assertions;
597622
resolve();
598623
});
599624

@@ -613,10 +638,9 @@ ${'partnerpath' in testFile ? '@include "' + backslashToSlash(testFile.partnerpa
613638
this._debug(Util.format(UserInteractor.MESSAGES.TEST_ERROR_TYPE, error.constructor.name));
614639

615640
if (error instanceof TestSession.Errors.TestMethodError) {
616-
617641
this._testLine(c.red(Util.format(UserInteractor.MESSAGES.TEST_FAILURE, error.message)));
642+
this._testFailures.push({ file: this._testFile, test: this._testMethod, result: error.message });
618643
this._stopSession = this._testConfig.stopOnFail;
619-
620644
} else if (error instanceof TestSession.Errors.TestStateError) {
621645

622646
this._error(error);

Diff for: lib/util/UserInteractor.js

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ const MESSAGES = {
191191
TEST_WATCHDOG_STARTED : 'Watchdog "%s" started',
192192
TEST_WATCHDOG_STOPPED : 'Watchdog "%s" stopped',
193193
TEST_WATCHDOG_TIME_OUT : 'Watchdog "%s" timed out',
194+
TEST_SUMMARY_HEADER : '-------------TEST SUMMARY-------------',
195+
TEST_SUMMARY_FAILURE : '%d) %s',
196+
TEST_SUMMARY_AT: 'at %s',
197+
TEST_SUMMARY_ERROR : 'Error: %s',
198+
TEST_SUMMARY_FOOTER : '--------------------------------------',
194199
PROJECT_DEVICE_FILE : 'Device file',
195200
PROJECT_AGENT_FILE : 'Agent file',
196201
PROJECT_DEVICE_SOURCE_FILE : 'Device source file',

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imp-central-impt",
3-
"version": "2.4.1",
3+
"version": "2.4.2",
44
"description": "impt - command line tool for the Electric Imp impCentral API",
55
"main": "bin/impt",
66
"engines": {

0 commit comments

Comments
 (0)