electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

how can I use electron-compile together with spectron? #178

Closed aeneasr closed 7 years ago

aeneasr commented 7 years ago

My application uses es6 like import statements and I want to write integration tests. My set up currently looks like this:

const Application = require('spectron').Application
const electron = require('electron')
const path = require('path')

describe('tests/integration/app', () => {
  let app

  beforeEach(() => {
    app = new Application({
      path: electron,
      args: [path.join(__dirname, '../../../src/main/index.js')]
    })
    return app.start()
  })

  afterEach(() => {
    if (app && app.isRunning()) {
      return app.stop()
    }
  })

  it('opens a window', () => {
    return app.client.waitUntilWindowLoaded()
  })
})

I've also tried const electron = require('electron-compile') but that yields Application path must be a string.

I couldn't find any docs on this and help is greatly appreciated!

ps: I'm using electron-prebuilt-compile in the app itself

aeneasr commented 7 years ago

Ok, I got one step further by doing const electron = path.resolve(__dirname, '../../../node_modules/.bin/electron') (which works due to electron-prebuilt-compile) but now yields:

bildschirmfoto 2017-02-14 um 09 50 02
aeneasr commented 7 years ago

got it:

const Application = require('spectron').Application
const path = require('path')
const electron = path.resolve(__dirname, '../../../node_modules/.bin/electron')
const exec = require('child_process').exec

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000

describe('tests/integration/app', () => {
  let app

  beforeEach(() => new Promise((resolve, reject) => {
    exec(`${path.resolve(__dirname, '../../../node_modules/.bin/electron-compile')} ${path.join(__dirname, '../../../')}`, () => {

      app = new Application({
        path: electron,
        args: [path.join(__dirname, '../../../src/main/index.js')]
      })
      app.start().then(resolve)
    })
  }))

  afterEach(() => {
    if (app && app.isRunning()) {
      return app.stop()
    }
  })

  it('opens a window', () => {
    return app.client.waitUntilWindowLoaded()
  })
})