Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jan 5, 2019
1 parent 6c74e6b commit 7983527
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
39 changes: 34 additions & 5 deletions spec/api-app-spec.js
Expand Up @@ -6,6 +6,7 @@ const https = require('https')
const net = require('net')
const fs = require('fs')
const path = require('path')
const cp = require('child_process')
const { ipcRenderer, remote } = require('electron')
const { emittedOnce } = require('./events-helpers')
const { closeWindow } = require('./window-helpers')
Expand Down Expand Up @@ -1093,29 +1094,57 @@ describe('app module', () => {
})

describe('commandLine.hasSwitch', () => {
it('returns true when present', () => {
it('returns true when present', async () => {
app.commandLine.appendSwitch('foobar1')
expect(app.commandLine.hasSwitch('foobar1')).to.be.true()

const { hasSwitch } = await runCommandLineTestApp('--foobar')
expect(hasSwitch).to.be.true()
})

it('returns false when not present', () => {
it('returns false when not present', async () => {
expect(app.commandLine.hasSwitch('foobar2')).to.be.false()

const { hasSwitch } = await runCommandLineTestApp()
expect(hasSwitch).to.be.false()
})
})

describe('commandLine.getSwitchValue', () => {
it('returns the value when present', () => {
it('returns the value when present', async () => {
app.commandLine.appendSwitch('foobar', 'test')
expect(app.commandLine.getSwitchValue('foobar')).to.equal('test')

const { getSwitchValue } = await runCommandLineTestApp('--foobar=test')
expect(getSwitchValue).to.equal('test')
})

it('returns an empty string when present without value', () => {
it('returns an empty string when present without value', async () => {
app.commandLine.appendSwitch('foobar1')
expect(app.commandLine.getSwitchValue('foobar1')).to.equal('')

const { getSwitchValue } = await runCommandLineTestApp('--foobar')
expect(getSwitchValue).to.equal('')
})

it('returns an empty string when not present', () => {
it('returns an empty string when not present', async () => {
expect(app.commandLine.getSwitchValue('foobar2')).to.equal('')

const { getSwitchValue } = await runCommandLineTestApp()
expect(getSwitchValue).to.equal('')
})
})

async function runCommandLineTestApp (...args) {
const appPath = path.join(__dirname, 'fixtures', 'api', 'command-line')
const electronPath = remote.getGlobal('process').execPath
const appProcess = cp.spawn(electronPath, [appPath, ...args])

let output = ''
appProcess.stdout.on('data', (data) => { output += data })

await emittedOnce(appProcess.stdout, 'end')

return JSON.parse(output)
}
})
15 changes: 15 additions & 0 deletions spec/fixtures/api/command-line/main.js
@@ -0,0 +1,15 @@
const { app } = require('electron')

app.on('ready', () => {
const payload = {
hasSwitch: app.commandLine.hasSwitch('foobar'),
getSwitchValue: app.commandLine.getSwitchValue('foobar')
}

process.stdout.write(JSON.stringify(payload))
process.stdout.end()

setImmediate(() => {
app.quit()
})
})
4 changes: 4 additions & 0 deletions spec/fixtures/api/command-line/package.json
@@ -0,0 +1,4 @@
{
"name": "command-line",
"main": "main.js"
}

0 comments on commit 7983527

Please sign in to comment.