|
1 | 1 | import assert from 'node:assert'; |
2 | 2 | import { FunctionDefinition, renderFunctions } from './source_builder'; |
3 | 3 | import { printNodeArray } from '../test_utils/ts_node_printer'; |
| 4 | +import { Runtime } from '@aws-sdk/client-lambda'; |
4 | 5 |
|
5 | 6 | describe('render function', () => { |
6 | 7 | describe('import', () => { |
@@ -40,13 +41,33 @@ describe('render function', () => { |
40 | 41 | const source = printNodeArray(rendered); |
41 | 42 | assert.match(source, /name: /); |
42 | 43 | }); |
43 | | - it('does render runtime property', () => { |
| 44 | + test.each([[Runtime.nodejs16x], [Runtime.nodejs18x], [Runtime.nodejs20x], [Runtime.nodejs22x]])( |
| 45 | + 'does render runtime property for %s nodejs.', |
| 46 | + (nodejsRuntime: Runtime) => { |
| 47 | + const definition: FunctionDefinition = {}; |
| 48 | + definition.runtime = nodejsRuntime; |
| 49 | + |
| 50 | + const rendered = renderFunctions(definition); |
| 51 | + const source = printNodeArray(rendered); |
| 52 | + const expectedRuntime = nodejsRuntime.split('nodejs')[1].split('.')[0]; |
| 53 | + assert(expectedRuntime); |
| 54 | + assert.match(source, new RegExp(`runtime: ${expectedRuntime}`)); |
| 55 | + }, |
| 56 | + ); |
| 57 | + |
| 58 | + it('throws error for unsupported nodejs runtime', () => { |
| 59 | + const definition: FunctionDefinition = {}; |
| 60 | + definition.runtime = Runtime.nodejs14x; |
| 61 | + |
| 62 | + assert.throws(() => renderFunctions(definition), /Unsupported nodejs runtime/); |
| 63 | + }); |
| 64 | + it('does not render runtime property for unsupported runtimes', () => { |
44 | 65 | const definition: FunctionDefinition = {}; |
45 | | - definition.runtime = 'nodejs18.x'; |
| 66 | + definition.runtime = Runtime.dotnet8; |
46 | 67 |
|
47 | 68 | const rendered = renderFunctions(definition); |
48 | 69 | const source = printNodeArray(rendered); |
49 | | - assert.match(source, /runtime: 18/); |
| 70 | + assert.doesNotMatch(source, /runtime: /); |
50 | 71 | }); |
51 | 72 | it('does render timeoutSeconds property', () => { |
52 | 73 | const definition: FunctionDefinition = {}; |
|
0 commit comments