diff mbox series

[4/4] tests: fetch: add npmsw test case for bundled dependencies

Message ID 20241209103158.20833-4-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series [1/4] tests: fetch: adapt npmsw tests to fixed unpack behavior | expand

Commit Message

Stefan Herbrechtsmeier Dec. 9, 2024, 10:31 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

The npm package lock and shrinkwrap file list bundled dependencies which
are supplied together with the parent dependency. The bundled
dependencies are marked by a flag. The flag and thereby test depends on
the lock file version. The old lock file version uses a `bundled` flag
and stores dependencies in the `dependencies` list. The new lock file
version uses an `inBundle` flag and stores dependencies in the
`packages` list.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

---

 lib/bb/tests/fetch.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 3eaaa8362..6dda0d381 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -3112,6 +3112,32 @@  class NPMTest(FetcherTest):
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
 
+    @skipIfNoNetwork()
+    def test_npmsw_bundled(self):
+        for packages_key, package_prefix, bundled_key in [
+            ('dependencies', '', 'bundled'),
+            ('packages', 'node_modules/', 'inBundle')
+        ]:
+            swfile = self.create_shrinkwrap_file({
+                packages_key: {
+                    package_prefix + 'array-flatten': {
+                        'version': '1.1.1',
+                        'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
+                        'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+                    },
+                    package_prefix + 'content-type': {
+                        'version': '1.0.4',
+                        'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
+                        'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
+                        bundled_key: True
+                    }
+                }
+            })
+            fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+            fetcher.download()
+            self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
+            self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
+
 class GitSharedTest(FetcherTest):
     def setUp(self):
         super(GitSharedTest, self).setUp()