@@ -29,29 +29,30 @@ def setUp(self):
29
29
self .no_deps = os .path .join (self .TEST_DATA_FOLDER , "no-deps" )
30
30
31
31
self .builder = LambdaBuilder (language = "nodejs" , dependency_manager = "npm" , application_framework = None )
32
- self .runtime = "nodejs12.x"
33
32
34
33
def tearDown (self ):
35
34
shutil .rmtree (self .artifacts_dir )
36
35
shutil .rmtree (self .scratch_dir )
37
36
shutil .rmtree (self .dependencies_dir )
38
37
39
- def test_builds_project_without_dependencies (self ):
38
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
39
+ def test_builds_project_without_dependencies (self , runtime ):
40
40
source_dir = os .path .join (self .TEST_DATA_FOLDER , "no-deps" )
41
41
42
42
self .builder .build (
43
43
source_dir ,
44
44
self .artifacts_dir ,
45
45
self .scratch_dir ,
46
46
os .path .join (source_dir , "package.json" ),
47
- runtime = self . runtime ,
47
+ runtime = runtime ,
48
48
)
49
49
50
50
expected_files = {"package.json" , "included.js" }
51
51
output_files = set (os .listdir (self .artifacts_dir ))
52
52
self .assertEqual (expected_files , output_files )
53
53
54
- def test_builds_project_without_manifest (self ):
54
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
55
+ def test_builds_project_without_manifest (self , runtime ):
55
56
source_dir = os .path .join (self .TEST_DATA_FOLDER , "no-manifest" )
56
57
57
58
with mock .patch .object (logger , "warning" ) as mock_warning :
@@ -60,38 +61,40 @@ def test_builds_project_without_manifest(self):
60
61
self .artifacts_dir ,
61
62
self .scratch_dir ,
62
63
os .path .join (source_dir , "package.json" ),
63
- runtime = self . runtime ,
64
+ runtime = runtime ,
64
65
)
65
66
66
67
expected_files = {"app.js" }
67
68
output_files = set (os .listdir (self .artifacts_dir ))
68
69
mock_warning .assert_called_once_with ("package.json file not found. Continuing the build without dependencies." )
69
70
self .assertEqual (expected_files , output_files )
70
71
71
- def test_builds_project_and_excludes_hidden_aws_sam (self ):
72
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
73
+ def test_builds_project_and_excludes_hidden_aws_sam (self , runtime ):
72
74
source_dir = os .path .join (self .TEST_DATA_FOLDER , "excluded-files" )
73
75
74
76
self .builder .build (
75
77
source_dir ,
76
78
self .artifacts_dir ,
77
79
self .scratch_dir ,
78
80
os .path .join (source_dir , "package.json" ),
79
- runtime = self . runtime ,
81
+ runtime = runtime ,
80
82
)
81
83
82
84
expected_files = {"package.json" , "included.js" }
83
85
output_files = set (os .listdir (self .artifacts_dir ))
84
86
self .assertEqual (expected_files , output_files )
85
87
86
- def test_builds_project_with_remote_dependencies (self ):
88
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
89
+ def test_builds_project_with_remote_dependencies (self , runtime ):
87
90
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npm-deps" )
88
91
89
92
self .builder .build (
90
93
source_dir ,
91
94
self .artifacts_dir ,
92
95
self .scratch_dir ,
93
96
os .path .join (source_dir , "package.json" ),
94
- runtime = self . runtime ,
97
+ runtime = runtime ,
95
98
)
96
99
97
100
expected_files = {"package.json" , "included.js" , "node_modules" }
@@ -102,15 +105,16 @@ def test_builds_project_with_remote_dependencies(self):
102
105
output_modules = set (os .listdir (os .path .join (self .artifacts_dir , "node_modules" )))
103
106
self .assertEqual (expected_modules , output_modules )
104
107
105
- def test_builds_project_with_npmrc (self ):
108
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
109
+ def test_builds_project_with_npmrc (self , runtime ):
106
110
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npmrc" )
107
111
108
112
self .builder .build (
109
113
source_dir ,
110
114
self .artifacts_dir ,
111
115
self .scratch_dir ,
112
116
os .path .join (source_dir , "package.json" ),
113
- runtime = self . runtime ,
117
+ runtime = runtime ,
114
118
)
115
119
116
120
expected_files = {"package.json" , "included.js" , "node_modules" }
@@ -122,8 +126,20 @@ def test_builds_project_with_npmrc(self):
122
126
output_modules = set (os .listdir (os .path .join (self .artifacts_dir , "node_modules" )))
123
127
self .assertEqual (expected_modules , output_modules )
124
128
125
- @parameterized .expand (["package-lock" , "shrinkwrap" , "package-lock-and-shrinkwrap" ])
126
- def test_builds_project_with_lockfile (self , dir_name ):
129
+ @parameterized .expand (
130
+ [
131
+ ("nodejs12.x" , "package-lock" ),
132
+ ("nodejs14.x" , "package-lock" ),
133
+ ("nodejs16.x" , "package-lock" ),
134
+ ("nodejs12.x" , "shrinkwrap" ),
135
+ ("nodejs14.x" , "shrinkwrap" ),
136
+ ("nodejs16.x" , "shrinkwrap" ),
137
+ ("nodejs12.x" , "package-lock-and-shrinkwrap" ),
138
+ ("nodejs14.x" , "package-lock-and-shrinkwrap" ),
139
+ ("nodejs16.x" , "package-lock-and-shrinkwrap" ),
140
+ ]
141
+ )
142
+ def test_builds_project_with_lockfile (self , runtime , dir_name ):
127
143
expected_files_common = {"package.json" , "included.js" , "node_modules" }
128
144
expected_files_by_dir_name = {
129
145
"package-lock" : {"package-lock.json" },
@@ -138,7 +154,7 @@ def test_builds_project_with_lockfile(self, dir_name):
138
154
self .artifacts_dir ,
139
155
self .scratch_dir ,
140
156
os .path .join (source_dir , "package.json" ),
141
- runtime = self . runtime ,
157
+ runtime = runtime ,
142
158
)
143
159
144
160
expected_files = expected_files_common .union (expected_files_by_dir_name [dir_name ])
@@ -147,8 +163,8 @@ def test_builds_project_with_lockfile(self, dir_name):
147
163
148
164
self .assertEqual (expected_files , output_files )
149
165
150
- def test_fails_if_npm_cannot_resolve_dependencies ( self ):
151
-
166
+ @ parameterized . expand ([( "nodejs12.x" ,), ( "nodejs14.x" ,), ( "nodejs16.x" ,)])
167
+ def test_fails_if_npm_cannot_resolve_dependencies ( self , runtime ):
152
168
source_dir = os .path .join (self .TEST_DATA_FOLDER , "broken-deps" )
153
169
154
170
with self .assertRaises (WorkflowFailedError ) as ctx :
@@ -157,20 +173,21 @@ def test_fails_if_npm_cannot_resolve_dependencies(self):
157
173
self .artifacts_dir ,
158
174
self .scratch_dir ,
159
175
os .path .join (source_dir , "package.json" ),
160
- runtime = self . runtime ,
176
+ runtime = runtime ,
161
177
)
162
178
163
179
self .
assertIn (
"No matching version found for [email protected] " ,
str (
ctx .
exception ))
164
180
165
- def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir (self ):
181
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
182
+ def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir (self , runtime ):
166
183
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npm-deps" )
167
184
168
185
self .builder .build (
169
186
source_dir ,
170
187
self .artifacts_dir ,
171
188
self .scratch_dir ,
172
189
os .path .join (source_dir , "package.json" ),
173
- runtime = self . runtime ,
190
+ runtime = runtime ,
174
191
dependencies_dir = self .dependencies_dir ,
175
192
download_dependencies = False ,
176
193
)
@@ -179,15 +196,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
179
196
output_files = set (os .listdir (self .artifacts_dir ))
180
197
self .assertEqual (expected_files , output_files )
181
198
182
- def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir (self ):
199
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
200
+ def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir (self , runtime ):
183
201
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npm-deps" )
184
202
185
203
self .builder .build (
186
204
source_dir ,
187
205
self .artifacts_dir ,
188
206
self .scratch_dir ,
189
207
os .path .join (source_dir , "package.json" ),
190
- runtime = self . runtime ,
208
+ runtime = runtime ,
191
209
dependencies_dir = self .dependencies_dir ,
192
210
download_dependencies = True ,
193
211
)
@@ -208,7 +226,10 @@ def test_builds_project_with_remote_dependencies_with_download_dependencies_and_
208
226
output_dependencies_files = set (os .listdir (os .path .join (self .dependencies_dir )))
209
227
self .assertNotIn (expected_dependencies_files , output_dependencies_files )
210
228
211
- def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir (self ):
229
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
230
+ def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir (
231
+ self , runtime
232
+ ):
212
233
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npm-deps" )
213
234
214
235
with mock .patch .object (logger , "info" ) as mock_info :
@@ -217,7 +238,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
217
238
self .artifacts_dir ,
218
239
self .scratch_dir ,
219
240
os .path .join (source_dir , "package.json" ),
220
- runtime = self . runtime ,
241
+ runtime = runtime ,
221
242
dependencies_dir = None ,
222
243
download_dependencies = False ,
223
244
)
@@ -231,15 +252,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
231
252
"artifacts directory. "
232
253
)
233
254
234
- def test_builds_project_without_combine_dependencies (self ):
255
+ @parameterized .expand ([("nodejs12.x" ,), ("nodejs14.x" ,), ("nodejs16.x" ,)])
256
+ def test_builds_project_without_combine_dependencies (self , runtime ):
235
257
source_dir = os .path .join (self .TEST_DATA_FOLDER , "npm-deps" )
236
258
237
259
self .builder .build (
238
260
source_dir ,
239
261
self .artifacts_dir ,
240
262
self .scratch_dir ,
241
263
os .path .join (source_dir , "package.json" ),
242
- runtime = self . runtime ,
264
+ runtime = runtime ,
243
265
dependencies_dir = self .dependencies_dir ,
244
266
download_dependencies = True ,
245
267
combine_dependencies = False ,
0 commit comments