node-lambda 1.2.1 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-lambda",
3
- "version": "1.2.1",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.",
5
5
  "main": "lib/main.js",
6
6
  "directories": {
@@ -32,23 +32,26 @@
32
32
  "author": "motdotla",
33
33
  "license": "BSD-2-Clause",
34
34
  "engines": {
35
- "node": ">= 10.0.0"
35
+ "node": ">= 18.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "archiver": "^6.0.0",
39
- "aws-sdk": "^2.1377.0",
38
+ "@aws-sdk/client-cloudwatch-events": "^3.797.0",
39
+ "@aws-sdk/client-cloudwatch-logs": "^3.782.0",
40
+ "@aws-sdk/client-lambda": "^3.670.0",
41
+ "@aws-sdk/client-s3": "^3.782.0",
42
+ "@dotenvx/dotenvx": "^1.14.0",
43
+ "archiver": "^7.0.0",
40
44
  "aws-xray-sdk-core": "^3.5.0",
41
- "commander": "^11.0.0",
45
+ "commander": "^12.0.0",
42
46
  "continuation-local-storage": "^3.2.1",
43
- "dotenv": "^16.0.3",
44
47
  "fs-extra": "^11.1.1",
45
48
  "klaw": "^4.1.0",
46
- "minimatch": "^9.0.0",
49
+ "minimatch": "^10.0.1",
47
50
  "proxy-agent": "^6.2.0"
48
51
  },
49
52
  "devDependencies": {
50
- "aws-sdk-mock": "^5.8.0",
51
- "chai": "^4.3.7",
53
+ "aws-sdk-client-mock": "^4.1.0",
54
+ "chai": "^5.0.0",
52
55
  "mocha": "^10.1.0",
53
56
  "node-zip": "^1.1.1",
54
57
  "standard": "^17.0.0"
package/tea.yaml ADDED
@@ -0,0 +1,6 @@
1
+ # https://tea.xyz/what-is-this-file
2
+ ---
3
+ version: 1.0.0
4
+ codeOwners:
5
+ - '0x248c5A7855A8861e3277341A1285c5D7dE64ba73'
6
+ quorum: 1
@@ -1,11 +1,20 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
4
7
  const path = require('path')
5
- const aws = require('aws-sdk-mock')
6
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
7
8
  const CloudWatchLogs = require(path.join('..', 'lib', 'cloudwatch_logs'))
8
9
 
10
+ const {
11
+ CloudWatchLogsClient,
12
+ CreateLogGroupCommand,
13
+ PutRetentionPolicyCommand
14
+ } = require('@aws-sdk/client-cloudwatch-logs')
15
+ const { mockClient } = require('aws-sdk-client-mock')
16
+ const mockCloudWatchLogsClient = mockClient(CloudWatchLogsClient)
17
+
9
18
  const mockResponse = {
10
19
  createLogGroup: {
11
20
  testCreateLogGroupResponse: 'An empty object is returned in the actual API'
@@ -23,21 +32,16 @@ const params = {
23
32
 
24
33
  let logs = null
25
34
 
26
- /* global before, after, describe, it */
35
+ /* global before, describe, it */
27
36
  describe('lib/cloudwatch_logs', () => {
28
37
  before(() => {
29
- aws.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
30
- callback(null, mockResponse.createLogGroup)
31
- })
32
- aws.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
33
- callback(null, mockResponse.putRetentionPolicy)
34
- })
38
+ mockCloudWatchLogsClient.reset()
39
+ mockCloudWatchLogsClient.on(CreateLogGroupCommand).resolves(mockResponse.createLogGroup)
40
+ mockCloudWatchLogsClient.on(PutRetentionPolicyCommand).resolves(mockResponse.putRetentionPolicy)
35
41
 
36
- logs = new CloudWatchLogs(require('aws-sdk'))
42
+ logs = new CloudWatchLogs({ region: 'us-east-1' })
37
43
  })
38
44
 
39
- after(() => aws.restore('CloudWatchLogs'))
40
-
41
45
  describe('_logGroupName', () => {
42
46
  it('correct value', () => {
43
47
  assert.equal(
package/test/main.js CHANGED
@@ -7,9 +7,52 @@ const fs = require('fs-extra')
7
7
  const { execFileSync } = require('child_process')
8
8
  const lambda = require(path.join(__dirname, '..', 'lib', 'main'))
9
9
  const Zip = require('node-zip')
10
- const { assert } = require('chai')
11
- const awsMock = require('aws-sdk-mock')
12
- awsMock.setSDK(path.resolve('node_modules/aws-sdk'))
10
+ let assert
11
+ import('chai').then(chai => {
12
+ assert = chai.assert
13
+ })
14
+
15
+ const { mockClient } = require('aws-sdk-client-mock')
16
+
17
+ const {
18
+ LambdaClient,
19
+ AddPermissionCommand,
20
+ CreateEventSourceMappingCommand,
21
+ CreateFunctionCommand,
22
+ DeleteEventSourceMappingCommand,
23
+ GetFunctionCommand,
24
+ ListEventSourceMappingsCommand,
25
+ ListTagsCommand,
26
+ TagResourceCommand,
27
+ UntagResourceCommand,
28
+ UpdateEventSourceMappingCommand,
29
+ UpdateFunctionCodeCommand,
30
+ UpdateFunctionConfigurationCommand
31
+ } = require('@aws-sdk/client-lambda')
32
+ const mockLambdaClient = mockClient(LambdaClient)
33
+ const lambdaClient = new LambdaClient({ region: 'us-east-1' })
34
+
35
+ const {
36
+ CloudWatchLogsClient,
37
+ CreateLogGroupCommand,
38
+ PutRetentionPolicyCommand
39
+ } = require('@aws-sdk/client-cloudwatch-logs')
40
+ const mockCloudWatchLogsClient = mockClient(CloudWatchLogsClient)
41
+
42
+ const {
43
+ CloudWatchEventsClient,
44
+ PutRuleCommand,
45
+ PutTargetsCommand
46
+ } = require('@aws-sdk/client-cloudwatch-events')
47
+ const mockCloudWatchEventsClient = mockClient(CloudWatchEventsClient)
48
+
49
+ const {
50
+ S3Client,
51
+ CreateBucketCommand,
52
+ PutBucketNotificationConfigurationCommand,
53
+ PutObjectCommand
54
+ } = require('@aws-sdk/client-s3')
55
+ const mockS3Client = mockClient(S3Client)
13
56
 
14
57
  const originalProgram = {
15
58
  packageManager: 'npm',
@@ -19,11 +62,11 @@ const originalProgram = {
19
62
  sessionToken: 'token',
20
63
  functionName: '___node-lambda',
21
64
  handler: 'index.handler',
22
- role: 'some:arn:aws:iam::role',
65
+ role: 'arn:aws:iam::999999999999:role/test',
23
66
  memorySize: 128,
24
67
  timeout: 3,
25
68
  description: '',
26
- runtime: 'nodejs18.x',
69
+ runtime: 'nodejs20.x',
27
70
  deadLetterConfigTargetArn: '',
28
71
  tracingConfig: '',
29
72
  Layers: '',
@@ -97,70 +140,59 @@ const lambdaMockSettings = {
97
140
  tagResource: {}
98
141
  }
99
142
 
100
- const _mockSetting = () => {
101
- awsMock.mock('CloudWatchEvents', 'putRule', (params, callback) => {
102
- callback(null, {})
103
- })
104
- awsMock.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
105
- callback(null, {})
106
- })
107
- awsMock.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
108
- callback(null, {})
109
- })
110
- awsMock.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
111
- callback(null, {})
112
- })
113
- awsMock.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
114
- callback(null, {})
115
- })
116
- awsMock.mock('S3', 'putObject', (params, callback) => {
117
- callback(null, { test: 'putObject' })
118
- })
119
-
120
- Object.keys(lambdaMockSettings).forEach((method) => {
121
- awsMock.mock('Lambda', method, (params, callback) => {
122
- callback(null, lambdaMockSettings[method])
123
- })
124
- })
125
-
126
- return require('aws-sdk')
127
- }
128
-
129
- const _awsRestore = () => {
130
- awsMock.restore('CloudWatchEvents')
131
- awsMock.restore('CloudWatchLogs')
132
- awsMock.restore('S3')
133
- awsMock.restore('Lambda')
134
- }
135
-
136
143
  /* global before, after, beforeEach, afterEach, describe, it */
137
144
  describe('lib/main', function () {
138
- if (['win32', 'darwin'].includes(process.platform)) {
139
- // It seems that it takes time for file operation in Windows and Mac.
145
+ if (process.platform === 'win32') {
146
+ // It seems that it takes very long time for file operation in Windows.
147
+ // So set `timeout(300000)` for the whole test.
148
+ this.timeout(300000)
149
+ } else if (process.platform === 'darwin') {
150
+ // It seems that it takes time for file operation in Mac.
140
151
  // So set `timeout(120000)` for the whole test.
141
152
  this.timeout(120000)
142
153
  }
143
154
 
144
- let aws = null // mock
145
- let awsLambda = null // mock
146
155
  before(() => {
147
- aws = _mockSetting()
148
- awsLambda = new aws.Lambda({ apiVersion: '2015-03-31' })
149
-
150
156
  if (process.platform === 'win32') {
151
157
  execFileSync('cmd.exe', ['/c', 'npm', 'ci'], { cwd: sourceDirectoryForTest })
152
158
  return
153
159
  }
154
160
  execFileSync('npm', ['ci'], { cwd: sourceDirectoryForTest })
155
161
  })
156
- after(() => _awsRestore())
157
162
 
158
163
  beforeEach(() => {
159
164
  program = Object.assign({}, originalProgram) // clone
165
+
166
+ mockLambdaClient.reset()
167
+ mockLambdaClient.on(AddPermissionCommand).resolves(lambdaMockSettings.addPermission)
168
+ mockLambdaClient.on(CreateEventSourceMappingCommand).resolves(lambdaMockSettings.createEventSourceMapping)
169
+ mockLambdaClient.on(CreateFunctionCommand).resolves(lambdaMockSettings.createFunction)
170
+ mockLambdaClient.on(DeleteEventSourceMappingCommand).resolves(lambdaMockSettings.deleteEventSourceMapping)
171
+ mockLambdaClient.on(GetFunctionCommand).resolves(lambdaMockSettings.getFunction)
172
+ mockLambdaClient.on(ListEventSourceMappingsCommand).resolves(lambdaMockSettings.listEventSourceMappings)
173
+ mockLambdaClient.on(ListTagsCommand).resolves(lambdaMockSettings.listTags)
174
+ mockLambdaClient.on(TagResourceCommand).resolves(lambdaMockSettings.tagResource)
175
+ mockLambdaClient.on(UntagResourceCommand).resolves(lambdaMockSettings.untagResource)
176
+ mockLambdaClient.on(UpdateEventSourceMappingCommand).resolves(lambdaMockSettings.updateEventSourceMapping)
177
+ mockLambdaClient.on(UpdateFunctionCodeCommand).resolves(lambdaMockSettings.updateFunctionCode)
178
+ mockLambdaClient.on(UpdateFunctionConfigurationCommand).resolves(lambdaMockSettings.updateFunctionConfiguration)
179
+
180
+ mockCloudWatchLogsClient.reset()
181
+ mockCloudWatchLogsClient.on(CreateLogGroupCommand).resolves({})
182
+ mockCloudWatchLogsClient.on(PutRetentionPolicyCommand).resolves({})
183
+
184
+ mockCloudWatchEventsClient.reset()
185
+ mockCloudWatchEventsClient.on(PutRuleCommand).resolves({})
186
+ mockCloudWatchEventsClient.on(PutTargetsCommand).resolves({})
187
+
188
+ mockS3Client.reset()
189
+ mockS3Client.on(CreateBucketCommand).resolves({})
190
+ mockS3Client.on(PutBucketNotificationConfigurationCommand).resolves({})
191
+ mockS3Client.on(PutObjectCommand).resolves({})
160
192
  })
161
193
 
162
194
  it('version should be set', () => {
163
- assert.equal(lambda.version, '1.2.1')
195
+ assert.equal(lambda.version, '2.0.0-alpha.0')
164
196
  })
165
197
 
166
198
  describe('_codeDirectory', () => {
@@ -1333,7 +1365,7 @@ describe('lib/main', function () {
1333
1365
  describe('_listEventSourceMappings', () => {
1334
1366
  it('simple test with mock', () => {
1335
1367
  return lambda._listEventSourceMappings(
1336
- awsLambda,
1368
+ lambdaClient,
1337
1369
  { FunctionName: 'test-func' }
1338
1370
  ).then((results) => {
1339
1371
  assert.deepEqual(
@@ -1397,7 +1429,7 @@ describe('lib/main', function () {
1397
1429
  program.eventSourceFile = ''
1398
1430
  const eventSourceList = lambda._eventSourceList(program)
1399
1431
  return lambda._updateEventSources(
1400
- awsLambda,
1432
+ lambdaClient,
1401
1433
  '',
1402
1434
  [],
1403
1435
  eventSourceList.EventSourceMappings
@@ -1410,7 +1442,7 @@ describe('lib/main', function () {
1410
1442
  program.eventSourceFile = 'event_sources.json'
1411
1443
  const eventSourceList = lambda._eventSourceList(program)
1412
1444
  return lambda._updateEventSources(
1413
- awsLambda,
1445
+ lambdaClient,
1414
1446
  'functionName',
1415
1447
  [],
1416
1448
  eventSourceList.EventSourceMappings
@@ -1421,7 +1453,7 @@ describe('lib/main', function () {
1421
1453
 
1422
1454
  it('simple test with mock (In case of deletion)', () => {
1423
1455
  return lambda._updateEventSources(
1424
- awsLambda,
1456
+ lambdaClient,
1425
1457
  'functionName',
1426
1458
  lambdaMockSettings.listEventSourceMappings.EventSourceMappings,
1427
1459
  {}
@@ -1434,7 +1466,7 @@ describe('lib/main', function () {
1434
1466
  program.eventSourceFile = 'event_sources.json'
1435
1467
  const eventSourceList = lambda._eventSourceList(program)
1436
1468
  return lambda._updateEventSources(
1437
- awsLambda,
1469
+ lambdaClient,
1438
1470
  'functionName',
1439
1471
  lambdaMockSettings.listEventSourceMappings.EventSourceMappings,
1440
1472
  eventSourceList.EventSourceMappings
@@ -1462,7 +1494,7 @@ describe('lib/main', function () {
1462
1494
  'event_sources.json',
1463
1495
  JSON.stringify(eventSourcesJsonValue)
1464
1496
  )
1465
- schedule = new ScheduleEvents(aws)
1497
+ schedule = new ScheduleEvents({ region: 'us-east-1' })
1466
1498
  })
1467
1499
 
1468
1500
  after(() => fs.unlinkSync('event_sources.json'))
@@ -1514,7 +1546,7 @@ describe('lib/main', function () {
1514
1546
  'event_sources.json',
1515
1547
  JSON.stringify(eventSourcesJsonValue)
1516
1548
  )
1517
- s3Events = new S3Events(aws)
1549
+ s3Events = new S3Events({ region: 'us-east-1' })
1518
1550
  })
1519
1551
 
1520
1552
  after(() => fs.unlinkSync('event_sources.json'))
@@ -1552,7 +1584,7 @@ describe('lib/main', function () {
1552
1584
  describe('_uploadNew', () => {
1553
1585
  it('simple test with mock', () => {
1554
1586
  const params = lambda._params(program, null)
1555
- return lambda._uploadNew(awsLambda, params, (results) => {
1587
+ return lambda._uploadNew(lambdaClient, params, (results) => {
1556
1588
  assert.deepEqual(results, lambdaMockSettings.createFunction)
1557
1589
  })
1558
1590
  })
@@ -1561,7 +1593,7 @@ describe('lib/main', function () {
1561
1593
  describe('_uploadExisting', () => {
1562
1594
  it('simple test with mock', () => {
1563
1595
  const params = lambda._params(program, null)
1564
- return lambda._uploadExisting(awsLambda, params).then((results) => {
1596
+ return lambda._uploadExisting(lambdaClient, params).then((results) => {
1565
1597
  assert.deepEqual(results, lambdaMockSettings.updateFunctionConfiguration)
1566
1598
  })
1567
1599
  })
@@ -1572,7 +1604,7 @@ describe('lib/main', function () {
1572
1604
  it('simple test with mock', () => {
1573
1605
  const params = lambda._params(program, null)
1574
1606
  return lambda._setLogsRetentionPolicy(
1575
- new CloudWatchLogs(aws),
1607
+ new CloudWatchLogs({ region: 'us-east-1' }),
1576
1608
  program,
1577
1609
  params.FunctionName
1578
1610
  ).then((results) => {
@@ -1649,7 +1681,7 @@ describe('lib/main', function () {
1649
1681
  describe('Lambda.prototype._updateTags()', () => {
1650
1682
  it('simple test with mock', () => {
1651
1683
  return lambda._updateTags(
1652
- awsLambda,
1684
+ lambdaClient,
1653
1685
  'arn:aws:lambda:eu-central-1:1234567:function:test',
1654
1686
  { tagKey: 'tagValue' }).then((result) => {
1655
1687
  assert.deepEqual(
@@ -1,6 +1,9 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
4
7
  const process = require('process')
5
8
  const path = require('path')
6
9
  const fs = require('fs-extra')
@@ -8,6 +11,11 @@ const spawn = require('child_process').spawn
8
11
  const execSync = require('child_process').execSync
9
12
  const nodeLambdaPath = path.join(__dirname, '..', 'bin', 'node-lambda')
10
13
 
14
+ const removeDotenvLog = (str) => {
15
+ // eslint-disable-next-line no-control-regex
16
+ return str.replace(/^\u001b\[38;5;142m\[dotenvx@.+\]injectingenv\(.+\)from.env\u001b\[39m/, '')
17
+ }
18
+
11
19
  /* global before, after, describe, it */
12
20
  // The reason for specifying the node command in this test is to support Windows.
13
21
  describe('bin/node-lambda', () => {
@@ -157,7 +165,7 @@ describe('bin/node-lambda', () => {
157
165
  process.env.AWS_RUNTIME = 'test'
158
166
  })
159
167
  after(() => {
160
- process.env.AWS_RUNTIME = 'nodejs18.x'
168
+ process.env.AWS_RUNTIME = 'nodejs20.x'
161
169
  })
162
170
 
163
171
  it('`node-lambda run` exitCode is `254` (callback(null))', (done) => {
@@ -171,14 +179,14 @@ describe('bin/node-lambda', () => {
171
179
  })
172
180
  })
173
181
 
174
- describe('node-lambda run (Runtime nodejs18.x is supported)', () => {
182
+ describe('node-lambda run (Runtime nodejs20.x is supported)', () => {
175
183
  const eventObj = {
176
184
  asyncTest: false,
177
185
  callbackWaitsForEmptyEventLoop: true // True is the default value of Lambda
178
186
  }
179
187
 
180
188
  before(() => {
181
- process.env.AWS_RUNTIME = 'nodejs18.x'
189
+ process.env.AWS_RUNTIME = 'nodejs20.x'
182
190
  })
183
191
 
184
192
  it('`node-lambda run` exitCode is not `254` (callback(null))', (done) => {
@@ -189,7 +197,7 @@ describe('bin/node-lambda', () => {
189
197
  })
190
198
  })
191
199
 
192
- describe('node-lambda run (Multiple events))', () => {
200
+ describe('node-lambda run (Multiple events)', () => {
193
201
  const eventObj = [{
194
202
  asyncTest: false,
195
203
  callbackWaitsForEmptyEventLoop: true,
@@ -217,7 +225,7 @@ describe('bin/node-lambda', () => {
217
225
  })
218
226
  })
219
227
 
220
- describe('node-lambda run (disable Multiple events))', () => {
228
+ describe('node-lambda run (disable Multiple events)', () => {
221
229
  const eventObj = [{
222
230
  asyncTest: false,
223
231
  callbackWaitsForEmptyEventLoop: true,
@@ -257,14 +265,14 @@ describe('bin/node-lambda', () => {
257
265
  '{asyncTest:false,callbackWaitsForEmptyEventLoop:true,callbackCode:\'callback(null);\',no:3}]' +
258
266
  '==================================Stoppingindex.handlerSuccess:'
259
267
 
260
- assert.equal(stdoutString, expected)
268
+ assert.equal(removeDotenvLog(stdoutString), expected)
261
269
  assert.equal(code, 0)
262
270
  done()
263
271
  })
264
272
  })
265
273
  })
266
274
 
267
- describe('node-lambda run (API Gateway events))', () => {
275
+ describe('node-lambda run (API Gateway events)', () => {
268
276
  const eventObj = {
269
277
  asyncTest: false,
270
278
  callbackWaitsForEmptyEventLoop: true,
@@ -289,12 +297,60 @@ describe('bin/node-lambda', () => {
289
297
  '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Runningindex.handler==================================event' +
290
298
  '{body:\'{"asyncTest":false,"callbackWaitsForEmptyEventLoop":true,"callbackCode":"callback(null);"}\'}' +
291
299
  '==================================Stoppingindex.handlerSuccess:'
292
- assert.equal(stdoutString, expected)
300
+ assert.equal(removeDotenvLog(stdoutString), expected)
301
+ assert.equal(code, 0)
302
+ done()
303
+ })
304
+ })
305
+ })
306
+
307
+ describe('node-lambda run (by *.mjs)', () => {
308
+ it('`node-lambda run` by index.mjs', function (done) {
309
+ const run = spawn('node', [
310
+ nodeLambdaPath, 'run',
311
+ '--handler', 'index_mjs.handler'
312
+ ])
313
+ let stdoutString = ''
314
+ run.stdout.on('data', (data) => {
315
+ stdoutString += data.toString().replace(/\r|\n|\s/g, '')
316
+ })
317
+
318
+ run.on('exit', (code) => {
319
+ const expected = 'Runningindex.handler(mjs)' +
320
+ '==================================' +
321
+ 'event{asyncTest:false,callbackWaitsForEmptyEventLoop:true,callbackCode:\'callback(null);\'}' +
322
+ '==================================' +
323
+ 'Stoppingindex.handler(mjs)Success:'
324
+ assert.equal(removeDotenvLog(stdoutString), expected)
293
325
  assert.equal(code, 0)
294
326
  done()
295
327
  })
296
328
  })
297
329
  })
330
+
331
+ describe('node-lambda run (handler file not found)', () => {
332
+ it('`node-lambda run` Invalid handler specification.', function (done) {
333
+ const run = spawn('node', [
334
+ nodeLambdaPath, 'run',
335
+ '--handler', 'not_found.handler'
336
+ ])
337
+ let stdoutString = ''
338
+ run.stdout.on('data', (data) => {
339
+ stdoutString += data.toString().replace(/\r|\n|\s/g, '')
340
+ })
341
+ let stderrString = ''
342
+ run.stderr.on('data', (data) => {
343
+ stderrString += data.toString()
344
+ })
345
+
346
+ run.on('exit', (code) => {
347
+ assert.equal(removeDotenvLog(stdoutString), '')
348
+ assert.match(stderrString, /Handler file not found\./)
349
+ assert.equal(code, 255)
350
+ done()
351
+ })
352
+ })
353
+ })
298
354
  })
299
355
 
300
356
  describe('node-lambda duplicate check of short option', () => {
@@ -332,7 +388,10 @@ describe('bin/node-lambda', () => {
332
388
  const packageJson = require(path.join(__dirname, '..', 'package.json'))
333
389
  it('The current version is displayed', () => {
334
390
  const ret = execSync(`node ${nodeLambdaPath} --version`)
335
- assert.equal(ret.toString().trim(), packageJson.version)
391
+ assert.equal(
392
+ ret.toString().trim().split('\n').pop(),
393
+ packageJson.version
394
+ )
336
395
  })
337
396
  })
338
397
  })
package/test/s3_deploy.js CHANGED
@@ -1,10 +1,17 @@
1
1
  'use strict'
2
2
 
3
- const { assert } = require('chai')
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
4
7
  const process = require('process')
5
- const path = require('path')
6
- const aws = require('aws-sdk-mock')
7
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
8
+ const {
9
+ S3Client,
10
+ CreateBucketCommand,
11
+ PutObjectCommand
12
+ } = require('@aws-sdk/client-s3')
13
+ const { mockClient } = require('aws-sdk-client-mock')
14
+ const mockS3Client = mockClient(S3Client)
8
15
  const S3Deploy = require('../lib/s3_deploy')
9
16
 
10
17
  const mockResponse = {
@@ -17,18 +24,11 @@ let s3Deploy = null
17
24
  /* global describe, it, before, after */
18
25
  describe('lib/s3_deploy', () => {
19
26
  before(() => {
20
- aws.mock('S3', 'putObject', (params, callback) => {
21
- callback(null, mockResponse.putObject)
22
- })
23
- aws.mock('S3', 'createBucket', (params, callback) => {
24
- callback(null, mockResponse.createBucket)
25
- })
26
-
27
- s3Deploy = new S3Deploy(require('aws-sdk'))
28
- })
27
+ mockS3Client.reset()
28
+ mockS3Client.on(CreateBucketCommand).resolves(mockResponse.createBucket)
29
+ mockS3Client.on(PutObjectCommand).resolves(mockResponse.putObject)
29
30
 
30
- after(() => {
31
- aws.restore('S3')
31
+ s3Deploy = new S3Deploy({ region: 'us-west-1' })
32
32
  })
33
33
 
34
34
  describe('_md5', () => {
package/test/s3_events.js CHANGED
@@ -1,9 +1,14 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
4
- const path = require('path')
5
- const aws = require('aws-sdk-mock')
6
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
7
+ const { S3Client, PutBucketNotificationConfigurationCommand } = require('@aws-sdk/client-s3')
8
+ const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
9
+ const { mockClient } = require('aws-sdk-client-mock')
10
+ const mockS3Client = mockClient(S3Client)
11
+ const mockLambdaClient = mockClient(LambdaClient)
7
12
  const S3Events = require('../lib/s3_events')
8
13
 
9
14
  const params = {
@@ -30,22 +35,15 @@ const mockResponse = {
30
35
 
31
36
  let s3Events = null
32
37
 
33
- /* global before, after, describe, it */
38
+ /* global before, describe, it */
34
39
  describe('lib/s3_events', () => {
35
40
  before(() => {
36
- aws.mock('Lambda', 'addPermission', (params, callback) => {
37
- callback(null, mockResponse.addPermission)
38
- })
39
- aws.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
40
- callback(null, mockResponse.putBucketNotificationConfiguration)
41
- })
42
-
43
- s3Events = new S3Events(require('aws-sdk'))
44
- })
41
+ mockS3Client.reset()
42
+ mockS3Client.on(PutBucketNotificationConfigurationCommand).resolves(mockResponse.putBucketNotificationConfiguration)
43
+ mockLambdaClient.reset()
44
+ mockLambdaClient.on(AddPermissionCommand).resolves(mockResponse.addPermission)
45
45
 
46
- after(() => {
47
- aws.restore('Lambda')
48
- aws.restore('S3')
46
+ s3Events = new S3Events({ region: 'us-west-1' })
49
47
  })
50
48
 
51
49
  describe('_functionName', () => {
@@ -1,9 +1,15 @@
1
1
  'use strict'
2
2
 
3
- const assert = require('chai').assert
3
+ let assert
4
+ import('chai').then(chai => {
5
+ assert = chai.assert
6
+ })
4
7
  const path = require('path')
5
- const aws = require('aws-sdk-mock')
6
- aws.setSDK(path.resolve('node_modules/aws-sdk'))
8
+ const { CloudWatchEventsClient, PutRuleCommand, PutTargetsCommand } = require('@aws-sdk/client-cloudwatch-events')
9
+ const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
10
+ const { mockClient } = require('aws-sdk-client-mock')
11
+ const mockCloudWatchEventsClient = mockClient(CloudWatchEventsClient)
12
+ const mockLambdaClient = mockClient(LambdaClient)
7
13
  const ScheduleEvents = require(path.join('..', 'lib', 'schedule_events'))
8
14
 
9
15
  const params = {
@@ -41,22 +47,14 @@ let schedule = null
41
47
  /* global before, after, describe, it */
42
48
  describe('lib/schedule_events', () => {
43
49
  before(() => {
44
- aws.mock('CloudWatchEvents', 'putRule', (params, callback) => {
45
- callback(null, mockResponse.putRule)
46
- })
47
- aws.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
48
- callback(null, mockResponse.putTargets)
49
- })
50
- aws.mock('Lambda', 'addPermission', (params, callback) => {
51
- callback(null, mockResponse.addPermission)
52
- })
50
+ mockCloudWatchEventsClient.reset()
51
+ mockCloudWatchEventsClient.on(PutRuleCommand).resolves(mockResponse.putRule)
52
+ mockCloudWatchEventsClient.on(PutTargetsCommand).resolves(mockResponse.putTargets)
53
53
 
54
- schedule = new ScheduleEvents(require('aws-sdk'))
55
- })
54
+ mockLambdaClient.reset()
55
+ mockLambdaClient.on(AddPermissionCommand).resolves(mockResponse.addPermission)
56
56
 
57
- after(() => {
58
- aws.restore('CloudWatchEvents')
59
- aws.restore('Lambda')
57
+ schedule = new ScheduleEvents({ region: 'us-west-1' })
60
58
  })
61
59
 
62
60
  describe('_ruleDescription (default)', () => {