Skip to content

Commit 88e90e9

Browse files
authored
test: add integration test for esbuild with local dependency (#455)
1 parent 3de673a commit 88e90e9

File tree

7 files changed

+58
-1
lines changed

7 files changed

+58
-1
lines changed

aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim
9292
subprocess_npm=self.subprocess_npm,
9393
osutils=self.osutils,
9494
build_options=self.options,
95+
install_links=self.build_dir == self.source_dir,
9596
)
9697
)
9798

tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,31 @@ def test_esbuild_can_build_in_source(self, runtime):
463463
expected_files = {"included.js"}
464464
output_files = set(os.listdir(self.artifacts_dir))
465465
self.assertEqual(expected_files, output_files)
466+
467+
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",), ("nodejs18.x",)])
468+
def test_esbuild_can_build_in_source_with_local_dependency(self, runtime):
469+
self.source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-local-dependency")
470+
471+
options = {"entry_points": ["included.js"]}
472+
473+
self.builder.build(
474+
self.source_dir,
475+
self.artifacts_dir,
476+
self.scratch_dir,
477+
os.path.join(self.source_dir, "package.json"),
478+
runtime=runtime,
479+
options=options,
480+
executable_search_paths=[self.binpath],
481+
build_in_source=True,
482+
)
483+
484+
# dependencies installed in source folder
485+
self.assertIn("node_modules", os.listdir(self.source_dir))
486+
487+
# dependencies not in scratch
488+
self.assertNotIn("node_modules", os.listdir(self.scratch_dir))
489+
490+
# bundle is in artifacts
491+
expected_files = {"included.js"}
492+
output_files = set(os.listdir(self.artifacts_dir))
493+
self.assertEqual(expected_files, output_files)

tests/integration/workflows/nodejs_npm_esbuild/testdata/no-deps-esbuild/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"keywords": [],
66
"author": "",
77
"license": "APACHE2.0",
8+
"main": "included.js",
89
"devDependencies": {
910
"esbuild": "^0.14.36"
1011
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//excluded
2+
const x = 1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//included
2+
const localdep = require('local-dependency');
3+
exports.handler = async (event, context) => {
4+
return localdep;
5+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "with-local-dependency",
3+
"version": "1.0.0",
4+
"description": "",
5+
"keywords": [],
6+
"author": "",
7+
"license": "APACHE2.0",
8+
"main": "included.js",
9+
"dependencies": {
10+
"local-dependency": "file:../no-deps-esbuild"
11+
},
12+
"devDependencies": {
13+
"esbuild": "^0.11.23"
14+
}
15+
}

tests/unit/workflows/nodejs_npm_esbuild/test_workflow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ def test_workflow_uses_production_npm_version(self, get_workflow_mock):
304304
self.assertIsInstance(workflow.actions[2], EsbuildBundleAction)
305305

306306
get_workflow_mock.get_install_action.assert_called_with(
307-
source_dir="source", install_dir="scratch_dir", subprocess_npm=ANY, osutils=ANY, build_options=None
307+
source_dir="source",
308+
install_dir="scratch_dir",
309+
subprocess_npm=ANY,
310+
osutils=ANY,
311+
build_options=None,
312+
install_links=False,
308313
)
309314

310315
@patch("aws_lambda_builders.workflows.nodejs_npm_esbuild.workflow.NodejsNpmEsbuildWorkflow._get_esbuild_subprocess")

0 commit comments

Comments
 (0)