Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app.commandLine.hasSwitch() / app.commandLine.getSwitchValue() #16282

Merged
merged 5 commits into from Jan 7, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

add more tests

  • Loading branch information...
miniak committed Jan 5, 2019
commit cd5f1c4b249fe0f1f7a415b43dd78c55bad5151e
@@ -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')
@@ -1103,6 +1104,18 @@ describe('app module', () => {
})
})

describe('commandLine.hasSwitch (existing argv)', () => {
it('returns true when present', async () => {
const { hasSwitch } = await runCommandLineTestApp('--foobar')
expect(hasSwitch).to.be.true()
})

it('returns false when not present', async () => {
const { hasSwitch } = await runCommandLineTestApp()
expect(hasSwitch).to.be.false()
})
})

describe('commandLine.getSwitchValue', () => {
it('returns the value when present', () => {
app.commandLine.appendSwitch('foobar', 'test')
@@ -1118,4 +1131,34 @@ describe('app module', () => {
expect(app.commandLine.getSwitchValue('foobar2')).to.equal('')
})
})

describe('commandLine.getSwitchValue (existing argv)', () => {
it('returns the value when present', async () => {
const { getSwitchValue } = await runCommandLineTestApp('--foobar=test')
expect(getSwitchValue).to.equal('test')
})

it('returns an empty string when present without value', async () => {
const { getSwitchValue } = await runCommandLineTestApp('--foobar')
expect(getSwitchValue).to.equal('')
})

it('returns an empty string when not present', async () => {
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)
}
})
@@ -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()
})
})
@@ -0,0 +1,4 @@
{
"name": "command-line",
"main": "main.js"
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.