-
Notifications
You must be signed in to change notification settings - Fork 821
Expand file tree
/
Copy pathsource_builder.test.ts
More file actions
97 lines (85 loc) · 3.6 KB
/
source_builder.test.ts
File metadata and controls
97 lines (85 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import assert from 'node:assert';
import { FunctionDefinition, renderFunctions } from './source_builder';
import { printNodeArray } from '../test_utils/ts_node_printer';
import { Runtime } from '@aws-sdk/client-lambda';
describe('render function', () => {
describe('import', () => {
it('imports defineFunction renderFunction is defined', () => {
const definition: FunctionDefinition = {};
definition.name = 'function1';
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /import\s?\{\s?defineFunction\s?\}\s?from\s?"\@aws-amplify\/backend"/);
});
});
describe('does not render', () => {
it('does not render the properties if its empty', () => {
const rendered = renderFunctions({});
const source = printNodeArray(rendered);
assert.doesNotMatch(source, new RegExp(`entry:`));
assert.match(source, /throw new Error/);
});
});
describe('render properties', () => {
it('does render entry property', () => {
const definition: FunctionDefinition = {};
definition.entry = 'index.handler';
definition.name = 'sayHello';
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /entry: /);
});
it('does render name property', () => {
const definition: FunctionDefinition = {};
definition.name = 'function1';
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /name: /);
});
test.each([[Runtime.nodejs16x], [Runtime.nodejs18x], [Runtime.nodejs20x], [Runtime.nodejs22x]])(
'does render runtime property for %s nodejs.',
(nodejsRuntime: Runtime) => {
const definition: FunctionDefinition = {};
definition.runtime = nodejsRuntime;
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
const expectedRuntime = nodejsRuntime.split('nodejs')[1].split('.')[0];
assert(expectedRuntime);
assert.match(source, new RegExp(`runtime: ${expectedRuntime}`));
},
);
it('throws error for unsupported nodejs runtime', () => {
const definition: FunctionDefinition = {};
definition.runtime = Runtime.nodejs14x;
assert.throws(() => renderFunctions(definition), /Unsupported nodejs runtime/);
});
it('does not render runtime property for unsupported runtimes', () => {
const definition: FunctionDefinition = {};
definition.runtime = Runtime.dotnet8;
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.doesNotMatch(source, /runtime: /);
});
it('does render timeoutSeconds property', () => {
const definition: FunctionDefinition = {};
definition.timeoutSeconds = 3;
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /timeoutSeconds: /);
});
it('does render memoryMB property', () => {
const definition: FunctionDefinition = {};
definition.memoryMB = 128;
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /memoryMB: /);
});
it('does render environment property', () => {
const definition: FunctionDefinition = {};
definition.environment = { Variables: { ENV: 'dev', REGION: 'us-west-2' } };
const rendered = renderFunctions(definition);
const source = printNodeArray(rendered);
assert.match(source, /environment: /);
});
});
});