Skip to content

Commit 0d144c8

Browse files
abetomoDeviaVir
authored andcommitted
Replace var with const (#341)
* Refactoring _listEventSourceMappings Modify that _listEventSourceMappings returns Promise * Remove unnecessary catch * Replace `var` with `const`
1 parent 5de32fb commit 0d144c8

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/main.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const Lambda = function () {
2323
}
2424

2525
Lambda.prototype._createSampleFile = function (file, boilerplateName) {
26-
var exampleFile = path.join(process.cwd(), file)
27-
var boilerplateFile = path.join(
26+
const exampleFile = path.join(process.cwd(), file)
27+
const boilerplateFile = path.join(
2828
__dirname,
2929
(boilerplateName || file) + '.example'
3030
)
@@ -150,7 +150,7 @@ so you can easily test run multiple events.
150150
}
151151

152152
Lambda.prototype._params = function (program, buffer) {
153-
var params = {
153+
const params = {
154154
FunctionName: program.functionName +
155155
(program.environment ? '-' + program.environment : '') +
156156
(program.lambdaVersion ? '-' + program.lambdaVersion : ''),
@@ -189,8 +189,8 @@ Lambda.prototype._params = function (program, buffer) {
189189
}
190190
}
191191
if (program.configFile) {
192-
var configValues = fs.readFileSync(program.configFile)
193-
var config = dotenv.parse(configValues)
192+
const configValues = fs.readFileSync(program.configFile)
193+
const config = dotenv.parse(configValues)
194194
// If `configFile` is an empty file, `config` value will be `{}`
195195
params.Environment = {
196196
Variables: config
@@ -441,8 +441,8 @@ Lambda.prototype._cleanDirectory = (codeDirectory) => {
441441
}
442442

443443
Lambda.prototype._setRunTimeEnvironmentVars = function (program) {
444-
var configValues = fs.readFileSync(program.configFile)
445-
var config = dotenv.parse(configValues)
444+
const configValues = fs.readFileSync(program.configFile)
445+
const config = dotenv.parse(configValues)
446446

447447
for (let k in config) {
448448
if (!config.hasOwnProperty(k)) {

test/main.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,36 +152,36 @@ describe('lib/main', function () {
152152
const functionNamePattern =
153153
/(arn:aws:lambda:)?([a-z]{2}-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?/
154154
it('appends environment to original functionName', function () {
155-
var params = lambda._params(program)
155+
const params = lambda._params(program)
156156
assert.equal(params.FunctionName, '___node-lambda-development')
157157
assert.match(params.FunctionName, functionNamePattern)
158158
})
159159

160160
it('appends environment to original functionName (production)', function () {
161161
program.environment = 'production'
162-
var params = lambda._params(program)
162+
const params = lambda._params(program)
163163
assert.equal(params.FunctionName, '___node-lambda-production')
164164
assert.match(params.FunctionName, functionNamePattern)
165165
})
166166

167167
it('appends version to original functionName', function () {
168168
program.lambdaVersion = '2015-02-01'
169-
var params = lambda._params(program)
169+
const params = lambda._params(program)
170170
assert.equal(params.FunctionName, '___node-lambda-development-2015-02-01')
171171
assert.match(params.FunctionName, functionNamePattern)
172172
})
173173

174174
it('appends version to original functionName (value not allowed by AWS)', function () {
175175
program.lambdaVersion = '2015.02.01'
176-
var params = lambda._params(program)
176+
const params = lambda._params(program)
177177
assert.equal(params.FunctionName, '___node-lambda-development-2015_02_01')
178178
assert.match(params.FunctionName, functionNamePattern)
179179
})
180180

181181
it('appends VpcConfig to params when vpc params set', function () {
182182
program.vpcSubnets = 'subnet-00000000,subnet-00000001,subnet-00000002'
183183
program.vpcSecurityGroups = 'sg-00000000,sg-00000001,sg-00000002'
184-
var params = lambda._params(program)
184+
const params = lambda._params(program)
185185
assert.equal(params.VpcConfig.SubnetIds[0], program.vpcSubnets.split(',')[0])
186186
assert.equal(params.VpcConfig.SubnetIds[1], program.vpcSubnets.split(',')[1])
187187
assert.equal(params.VpcConfig.SubnetIds[2], program.vpcSubnets.split(',')[2])
@@ -191,7 +191,7 @@ describe('lib/main', function () {
191191
})
192192

193193
it('does not append VpcConfig when params are not set', function () {
194-
var params = lambda._params(program)
194+
const params = lambda._params(program)
195195
assert.equal(Object.keys(params.VpcConfig.SubnetIds).length, 0)
196196
assert.equal(Object.keys(params.VpcConfig.SecurityGroupIds).length, 0)
197197
})
@@ -206,7 +206,7 @@ describe('lib/main', function () {
206206

207207
it('does not append DeadLetterConfig when params are not set', function () {
208208
delete program.deadLetterConfigTargetArn
209-
var params = lambda._params(program)
209+
const params = lambda._params(program)
210210
assert.isNull(params.DeadLetterConfig.TargetArn)
211211
})
212212

@@ -236,19 +236,19 @@ describe('lib/main', function () {
236236

237237
it('adds variables when configFile param is set', function () {
238238
program.configFile = 'tmp.env'
239-
var params = lambda._params(program)
239+
const params = lambda._params(program)
240240
assert.equal(params.Environment.Variables['FOO'], 'bar')
241241
assert.equal(params.Environment.Variables['BAZ'], 'bing')
242242
})
243243

244244
it('when configFile param is set but it is an empty file', function () {
245245
program.configFile = 'empty.env'
246-
var params = lambda._params(program)
246+
const params = lambda._params(program)
247247
assert.equal(Object.keys(params.Environment.Variables).length, 0)
248248
})
249249

250250
it('does not add when configFile param is not set', function () {
251-
var params = lambda._params(program)
251+
const params = lambda._params(program)
252252
assert.isNull(params.Environment.Variables)
253253
})
254254
})

0 commit comments

Comments
 (0)