Skip to content

Commit

Permalink
fix: bugfix for log beginning copied to every test log
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed May 20, 2018
1 parent cc8e91a commit a7cf806
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions detox/src/artifacts/log/ios/SimulatorLogRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ const tempfile = require('tempfile');
const Recorder = require('../../core/factory/Recorder');
const SimulatorLogRecording = require('./SimulatorLogRecording');

// TODO: implement
class SimulatorLogRecorder extends Recorder {
constructor(config) {
super(config);

this.appleSimUtils = config.appleSimUtils;
this.udid = config.udid;
this.started = false;
}

createRecording() {
const { stdout, stderr } = this.appleSimUtils.getLogsPaths(this.udid);

return new SimulatorLogRecording({
const recording = new SimulatorLogRecording({
stdoutPath: stdout,
stderrPath: stderr,
temporaryLogPath: tempfile('.log'),
fromBeginning: !this.started,
});

this.started = true;
return recording;
}
}

Expand Down
16 changes: 14 additions & 2 deletions detox/src/artifacts/log/ios/SimulatorLogRecording.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class SimulatorLogRecording extends RecordingArtifact {
stdoutPath,
stderrPath,
temporaryLogPath,
fromBeginning,
}) {
super();

this._logPath = temporaryLogPath;
this._stdoutPath = stdoutPath;
this._stderrPath = stderrPath;
this._fromBeginning = fromBeginning;

this._logStream = null;
this._stdoutTail = null;
Expand Down Expand Up @@ -44,7 +46,7 @@ class SimulatorLogRecording extends RecordingArtifact {

_createTail(file, prefix) {
const tail = new Tail(file, {
fromBeginning: true,
fromBeginning: this._fromBeginning,
logger: {
info: (...args) => npmlog.verbose(`simulator-log-${prefix}`, ...args),
error: (...args) => npmlog.error(`simulator-log-${prefix}`, ...args),
Expand All @@ -53,10 +55,20 @@ class SimulatorLogRecording extends RecordingArtifact {
this._appendLine(prefix, line);
});

tail.watchEvent.call(tail, "change");
if (this._fromBeginning) {
this._triggerTailReadUsingHack(tail);
}

return tail;
}

/***
* @link https://github.com/lucagrulla/node-tail/issues/40
*/
_triggerTailReadUsingHack(tail) {
tail.watchEvent.call(tail, "change");
}

_appendLine(prefix, line) {
this._logStream.write(prefix);
this._logStream.write(': ');
Expand Down

0 comments on commit a7cf806

Please sign in to comment.