Skip to content

Commit 9c21121

Browse files
authored
Fix argument ordering issue when number of arguments exceeds 10. Added test for issue. (#588)
Co-authored-by: Jason Hiser <jdhiser@gmail.com>
1 parent 336d866 commit 9c21121

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/launcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ process.argv.slice(2).forEach(function (arg) {
1818
if (name === '--spectron-path') {
1919
executablePath = value
2020
} else if (name.indexOf('--spectron-arg') === 0) {
21-
appArgs.push(value)
21+
appArgs[Number(name.substring(14))] = value
2222
} else if (name.indexOf('--spectron-env') === 0) {
2323
process.env[name.substring(15)] = value
2424
} else if (name.indexOf('--spectron-') !== 0) {

test/many-args.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var helpers = require('./global-setup')
2+
var path = require('path')
3+
var temp = require('temp').track()
4+
5+
var describe = global.describe
6+
var it = global.it
7+
var beforeEach = global.beforeEach
8+
var afterEach = global.afterEach
9+
var expect = require('chai').expect
10+
11+
describe('application loading', function () {
12+
helpers.setupTimeout(this)
13+
14+
var app = null
15+
var tempPath = null
16+
17+
beforeEach(function () {
18+
tempPath = temp.mkdirSync('spectron-temp-dir-')
19+
20+
return helpers.startApplication({
21+
cwd: path.join(__dirname, 'fixtures'),
22+
args: [
23+
path.join(__dirname, 'fixtures', 'app'),
24+
'--bar1=baz1',
25+
'--bar2=baz2',
26+
'--bar3=baz3',
27+
'--bar4=baz4',
28+
'--bar5=baz5',
29+
'--bar6=baz6',
30+
'--bar7=baz7',
31+
'--bar8=baz8',
32+
'--bar9=baz9',
33+
'--bar10=baz10',
34+
'--bar11=baz11',
35+
'--bar12=baz12',
36+
'--bar13=baz13'
37+
],
38+
env: {
39+
FOO: 'BAR',
40+
HELLO: 'WORLD',
41+
SPECTRON_TEMP_DIR: tempPath
42+
}
43+
}).then(function (startedApp) { app = startedApp })
44+
})
45+
46+
afterEach(function () {
47+
return helpers.stopApplication(app)
48+
})
49+
50+
it('passes through args to the launched app', function () {
51+
return app.mainProcess.argv().then(function (argv) {
52+
expect(argv[2]).to.equal('--bar1=baz1')
53+
expect(argv[9]).to.equal('--bar8=baz8')
54+
expect(argv[12]).to.equal('--bar11=baz11')
55+
})
56+
})
57+
})

0 commit comments

Comments
 (0)