Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Automation: Use spectron to get console logs #1239

Merged
merged 2 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions browser/src/Services/Automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class Automation implements OniApi.Automation.Api {

const testPath2 = testPath

const loggingRedirector = new LoggingRedirector()
Log.enableVerboseLogging()
try {
Log.info("[AUTOMATION] Starting test: " + testPath)
Expand All @@ -103,13 +102,6 @@ export class Automation implements OniApi.Automation.Api {
this._reportResult(false, ex)
} finally {
this._reportWindowSize()
const logs = loggingRedirector.getAllLogs()

const logsElement = this._createElement("automated-test-logs", this._getOrCreateTestContainer("automated-test-container"))

logsElement.textContent = JSON.stringify(logs)

loggingRedirector.dispose()
}
}

Expand Down Expand Up @@ -158,45 +150,3 @@ export class Automation implements OniApi.Automation.Api {
}

export const automation = new Automation()

class LoggingRedirector {

private _logs: string[] = []

private _oldInfo: any
private _oldWarn: any
private _oldError: any

constructor() {
this._oldInfo = console.log
this._oldWarn = console.warn
this._oldError = console.error

console.log = this._redirect("INFO", this._oldInfo)
console.warn = this._redirect("WARN", this._oldWarn)
console.error = this._redirect("ERROR", this._oldError)
}

public getAllLogs(): string[] {
return this._logs
}

public dispose(): void {
this._logs = null

console.log = this._oldInfo
console.warn = this._oldWarn
console.error = this._oldError

this._oldInfo = null
this._oldWarn = null
this._oldError = null
}

private _redirect(type: string, oldFunction: any): any {
return (...args: any[]) => {
this._logs.push("[" + type + "][" + new Date().getTime() + "]: " + JSON.stringify(args))
oldFunction(args)
}
}
}
13 changes: 8 additions & 5 deletions test/common/runInProcTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ export const runInProcTest = (rootPath: string, testName: string, timeout: numbe

console.log("Retrieving logs...")

await oni.client.waitForExist(".automated-test-logs")
const clientLogs = await oni.client.getText(".automated-test-logs")
console.log("---LOGS (During run): ")

const logs = JSON.parse(clientLogs).forEach((log) => console.log(log))
const writeLogs = (logs: any[]): void => {
logs.forEach((log) => {
console.log(`[${log.level}] ${log.message}`)
})
}

const rendererLogs: any[] = await oni.client.getRenderProcessLogs()
console.log("---LOGS (Renderer): ")
writeLogs(rendererLogs)
console.log("---")

const result = JSON.parse(resultText)
Expand Down