Skip to content

Commit

Permalink
fix: Fix recent entry retrieval (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 2, 2024
1 parent 24527bf commit 67d4b06
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
25 changes: 10 additions & 15 deletions lib/logcat.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,17 @@ class Logcat extends EventEmitter {
resolve();
}
});
this.proc.on('lines-stderr', (lines) => {
for (const line of lines) {
if (!started && EXECVP_ERR_PATTERN.test(line)) {
log.error('Logcat process failed to start');
return reject(new Error(`Logcat process failed to start. stderr: ${line}`));
}
this.outputHandler(line, 'STDERR: ');
this.proc.on('line-stderr', (line) => {
if (!started && EXECVP_ERR_PATTERN.test(line)) {
log.error('Logcat process failed to start');
return reject(new Error(`Logcat process failed to start. stderr: ${line}`));
}
this.outputHandler(line, 'STDERR: ');
resolve();
});
this.proc.on('lines-stdout', (lines) => {
this.proc.on('line-stdout', (line) => {
this.outputHandler(line);
resolve();
for (const line of lines) {
this.outputHandler(line);
}
});
await this.proc.start(0);
// resolve after a timeout, even if no output was recorded
Expand All @@ -189,9 +185,8 @@ class Logcat extends EventEmitter {
*/
outputHandler (logLine, prefix = '') {
const timestamp = Date.now();
/** @type {number} */
let recentIndex = -1;
for (const key of this.logs.rkeys()) {
for (const key of this.logs.keys()) {
recentIndex = key;
break;
}
Expand Down Expand Up @@ -228,7 +223,7 @@ class Logcat extends EventEmitter {
const result = [];
/** @type {number?} */
let recentLogIndex = null;
for (const [index, [message, timestamp]] of this.logs.entries()) {
for (const [index, [message, timestamp]] of /** @type {Generator} */ (this.logs.rentries())) {
if (this.logIndexSinceLastRequest && index > this.logIndexSinceLastRequest
|| !this.logIndexSinceLastRequest) {
recentLogIndex = index;
Expand All @@ -247,7 +242,7 @@ class Logcat extends EventEmitter {
getAllLogs () {
/** @type {LogEntry[]} */
const result = [];
for (const [message, timestamp] of this.logs.values()) {
for (const [message, timestamp] of /** @type {Generator} */ (this.logs.rvalues())) {
result.push(toLogEntry(message, timestamp));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lru-cache": "^10.0.0",
"semver": "^7.0.0",
"source-map-support": "^0.x",
"teen_process": "^2.1.10"
"teen_process": "^2.2.0"
},
"devDependencies": {
"@appium/eslint-config-appium-ts": "^0.x",
Expand Down
6 changes: 3 additions & 3 deletions test/unit/logcat-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('logcat', withMocks({teen_process}, function (mocks) {
.onFirstCall()
.returns(conn);
setTimeout(function () {
conn.emit('lines-stdout', ['- beginning of system\r']);
conn.emit('line-stdout', '- beginning of system\r');
}, 0);
await logcat.startCapture({
format: 'brief',
Expand All @@ -46,7 +46,7 @@ describe('logcat', withMocks({teen_process}, function (mocks) {
.onFirstCall()
.returns(conn);
setTimeout(function () {
conn.emit('lines-stderr', ['execvp()']);
conn.emit('line-stderr', 'execvp()');
}, 0);
await logcat.startCapture().should.eventually.be.rejectedWith('Logcat');
});
Expand All @@ -58,7 +58,7 @@ describe('logcat', withMocks({teen_process}, function (mocks) {
.onFirstCall()
.returns(conn);
setTimeout(function () {
conn.emit('lines-stderr', ['something']);
conn.emit('line-stderr', 'something');
}, 0);
await logcat.startCapture().should.eventually.not.be.rejectedWith('Logcat');
});
Expand Down

0 comments on commit 67d4b06

Please sign in to comment.