-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generic): Support setting the Electron app path in start()
The start command allows the caller to specify the directory for the Electron forge project, and then assumes that its main module is the Electron application. However, some projects may contain multiple Electron applications, or may want to specify an html file or a URL as the Electron application (see https://github.com/electron/electron/blob/cf694ef32b78f0904219c6c8ba554d3d5cbea037/default_app/main.js#L338). So, this adds an optional 'appPath' API option (and corresponding '-p'/'--app-path' CLI option) that is the path to the Electron application relative to the electron forge project (the 'dir' option). This also fixes the start command-line options parsing, which was passing all arguments through to the Electron application instead of parsing out the start command options.
- Loading branch information
1 parent
fddb40e
commit 47c5572
Showing
4 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import proxyquire from 'proxyquire'; | ||
import sinon from 'sinon'; | ||
import { Command } from 'commander'; | ||
import path from 'path'; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('electron-forge start', () => { | ||
let argv; | ||
let startStub; | ||
let runCommand; | ||
|
||
beforeEach(() => { | ||
({ argv } = process); | ||
|
||
startStub = sinon.stub(); | ||
runCommand = async (args = []) => { | ||
process.argv = ['node', 'electron-forge-start'].concat(args); | ||
return proxyquire.noCallThru().load('../../src/electron-forge-start', { | ||
commander: new Command(), | ||
'./api': { start: async opts => startStub(opts) }, | ||
}); | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
process.argv = argv; | ||
}); | ||
|
||
it('should pass through correct defaults', async () => { | ||
await runCommand(); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: process.cwd(), | ||
interactive: true, | ||
}); | ||
}); | ||
|
||
it('should handle an absolute project directory', async () => { | ||
await runCommand([path.join(process.cwd(), 'test', 'fixture', 'dummy_app')]); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: path.join(process.cwd(), 'test', 'fixture', 'dummy_app'), | ||
interactive: true, | ||
}); | ||
}); | ||
|
||
it('should handle a relative project directory', async () => { | ||
await runCommand([path.join('test', 'fixture', 'dummy_app')]); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: path.join(process.cwd(), 'test', 'fixture', 'dummy_app'), | ||
interactive: true, | ||
}); | ||
}); | ||
|
||
it('should handle an app path', async () => { | ||
await runCommand(['-p', path.join('foo', 'electron.js')]); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: process.cwd(), | ||
appPath: path.join('foo', 'electron.js'), | ||
interactive: true, | ||
}); | ||
}); | ||
|
||
it('should be able to enable logging', async () => { | ||
await runCommand(['-l']); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: process.cwd(), | ||
enableLogging: true, | ||
interactive: true, | ||
}); | ||
}); | ||
|
||
it('should handle app args', async () => { | ||
await runCommand(['-l', '---', '-a', 'foo', '-l']); | ||
expect(startStub.callCount).to.equal(1); | ||
expect(startStub.firstCall.args[0]).to.deep.equal({ | ||
dir: process.cwd(), | ||
enableLogging: true, | ||
interactive: true, | ||
args: ['-a', 'foo', '-l'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters