import { Application } from 'spectron'
import electronPath from 'electron'
import path from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000

const delay = time => new Promise(resolve => setTimeout(resolve, time))

describe('main window', function spec() {
  beforeAll(async () => {
    this.app = new Application({
      path: electronPath,
      args: [path.join(__dirname, '..', '..', 'app')]
    })

    return this.app.start()
  })

  afterAll(() => this.app && this.app.isRunning() && this.app.stop())

  it('should open window', async () => {
    const { client, browserWindow } = this.app

    await client.waitUntilWindowLoaded()
    await delay(500)
    const title = await browserWindow.getTitle()
    expect(title).toBe('Zap')
  })

  it('should haven\'t any logs in console of main window', async () => {
    const { client } = this.app
    const logs = await client.getRenderProcessLogs()
    // Print renderer process logs
    logs.forEach((log) => {
      console.log(log.message)
      console.log(log.source)
      console.log(log.level)
    })
    expect(logs).toHaveLength(0)
  })
})

import { Application } from 'spectron'
import electronPath from 'electron'
import path from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000

const delay = time => new Promise(resolve => setTimeout(resolve, time))

describe('main window', function spec() {
  beforeAll(async () => {
    this.app = new Application({
      path: electronPath,
      args: [path.join(__dirname, '..', '..', 'app')]
    })

    return this.app.start()
  })

  afterAll(() => this.app && this.app.isRunning() && this.app.stop())

  it('should open window', async () => {
    const { client, browserWindow } = this.app

    await client.waitUntilWindowLoaded()
    await delay(500)
    const title = await browserWindow.getTitle()
    expect(title).toBe('Zap')
  })

  it('should haven\'t any logs in console of main window', async () => {
    const { client } = this.app
    const logs = await client.getRenderProcessLogs()
    expect(logs).toHaveLength(0)
  })
})

Drop pessimistic printing of logs that shouldn't be there
enhance(test): Drop pessimistic printing of logs that shouldn't be there

This test code is unnecessary in the common case and can be revived if the test
fails.
