コード例 #1
0
 def test_packages_with_externals(self):
     action = EsbuildBundleAction(
         "source",
         "artifacts",
         {
             "entry_points": ["x.js"],
             "external": ["fetch", "aws-sdk"]
         },
         self.osutils,
         self.subprocess_esbuild,
     )
     action.execute()
     self.subprocess_esbuild.run.assert_called_with(
         [
             "x.js",
             "--bundle",
             "--platform=node",
             "--format=cjs",
             "--minify",
             "--sourcemap",
             "--external:fetch",
             "--external:aws-sdk",
             "--target=es2020",
             "--outdir=artifacts",
         ],
         cwd="source",
     )
コード例 #2
0
 def test_includes_multiple_entry_points_if_requested(self):
     action = EsbuildBundleAction(
         "source",
         "artifacts",
         {
             "entry_points": ["x.js", "y.js"],
             "target": "node14"
         },
         self.osutils,
         self.subprocess_esbuild,
     )
     action.execute()
     self.subprocess_esbuild.run.assert_called_with(
         [
             "x.js",
             "y.js",
             "--bundle",
             "--platform=node",
             "--format=cjs",
             "--minify",
             "--sourcemap",
             "--target=node14",
             "--outdir=artifacts",
         ],
         cwd="source",
     )
コード例 #3
0
 def test_packages_with_custom_loaders(self):
     action = EsbuildBundleAction(
         "source",
         "artifacts",
         {
             "entry_points": ["x.js"],
             "loader": [".proto=text", ".json=js"]
         },
         self.osutils,
         self.subprocess_esbuild,
     )
     action.execute()
     self.subprocess_esbuild.run.assert_called_with(
         [
             "x.js",
             "--bundle",
             "--platform=node",
             "--format=cjs",
             "--minify",
             "--sourcemap",
             "--loader:.proto=text",
             "--loader:.json=js",
             "--target=es2020",
             "--outdir=artifacts",
         ],
         cwd="source",
     )
コード例 #4
0
    def test_raises_error_if_entrypoints_not_specified(self):
        action = EsbuildBundleAction("source", "artifacts",
                                     {"config": "param"}, self.osutils,
                                     self.subprocess_esbuild)
        with self.assertRaises(ActionFailedError) as raised:
            action.execute()

        self.assertEqual(raised.exception.args[0],
                         "entry_points not set ({'config': 'param'})")
コード例 #5
0
    def test_raises_error_if_entrypoints_empty_list(self):
        action = EsbuildBundleAction("source", "artifacts", {
            "config": "param",
            "entry_points": []
        }, self.osutils, self.subprocess_esbuild)
        with self.assertRaises(ActionFailedError) as raised:
            action.execute()

        self.assertEqual(
            raised.exception.args[0],
            "entry_points must not be empty ({'config': 'param', 'entry_points': []})"
        )
コード例 #6
0
 def test_runs_node_subprocess_if_deps_skipped(self):
     action = EsbuildBundleAction(
         tempfile.mkdtemp(),
         "artifacts",
         {"entry_points": ["app.ts"]},
         self.osutils,
         self.subprocess_esbuild,
         self.subprocess_nodejs,
         True,
     )
     action.execute()
     self.subprocess_nodejs.run.assert_called()
コード例 #7
0
    def test_checks_if_single_entrypoint_exists(self):

        action = EsbuildBundleAction("source", "artifacts",
                                     {"entry_points": ["x.js"]}, self.osutils,
                                     self.subprocess_esbuild)
        self.osutils.file_exists.side_effect = [False]

        with self.assertRaises(ActionFailedError) as raised:
            action.execute()

        self.osutils.file_exists.assert_called_with("source/x.js")

        self.assertEqual(raised.exception.args[0],
                         "entry point source/x.js does not exist")
コード例 #8
0
 def test_does_not_minify_if_requested(self):
     action = EsbuildBundleAction("source", "artifacts", {
         "entry_points": ["x.js"],
         "minify": False
     }, self.osutils, self.subprocess_esbuild)
     action.execute()
     self.subprocess_esbuild.run.assert_called_with(
         [
             "x.js",
             "--bundle",
             "--platform=node",
             "--format=cjs",
             "--sourcemap",
             "--target=es2020",
             "--outdir=artifacts",
         ],
         cwd="source",
     )
コード例 #9
0
    def test_packages_javascript_with_minification_and_sourcemap(self):
        action = EsbuildBundleAction("source", "artifacts",
                                     {"entry_points": ["x.js"]}, self.osutils,
                                     self.subprocess_esbuild)
        action.execute()

        self.subprocess_esbuild.run.assert_called_with(
            [
                "x.js",
                "--bundle",
                "--platform=node",
                "--format=cjs",
                "--minify",
                "--sourcemap",
                "--target=es2020",
                "--outdir=artifacts",
            ],
            cwd="source",
        )
コード例 #10
0
 def test_uses_specified_target(self):
     action = EsbuildBundleAction("source", "artifacts", {
         "entry_points": ["x.js"],
         "target": "node14"
     }, self.osutils, self.subprocess_esbuild)
     action.execute()
     self.subprocess_esbuild.run.assert_called_with(
         [
             "x.js",
             "--bundle",
             "--platform=node",
             "--format=cjs",
             "--minify",
             "--sourcemap",
             "--target=node14",
             "--outdir=artifacts",
         ],
         cwd="source",
     )