From 251cbd22dd778d9532d5ef858e13fbc09aa83993 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Thu, 25 Jan 2024 18:21:06 +0100 Subject: [PATCH] Improve test coverage --- django_esm/utils.py | 2 +- tests/node_modules/.package-lock.json | 27 ++++++++++++++++++++++++++- tests/package.json | 7 ++++++- tests/packages/deep/features/a.js | 0 tests/packages/deep/features/b.js | 0 tests/packages/deep/index.js | 0 tests/packages/deep/package.json | 10 ++++++++++ tests/packages/deep/utils/a.js | 0 tests/packages/flat/index.js | 0 tests/packages/flat/package.json | 6 ++++++ tests/packages/flat2/index.js | 0 tests/packages/flat2/package.json | 7 +++++++ tests/packages/list/index.js | 0 tests/packages/list/package.json | 4 ++++ tests/packages/string/package.json | 4 ++++ tests/test_utils.py | 6 ++++++ tests/testapp/static/js/index.js.map | 0 17 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/packages/deep/features/a.js create mode 100644 tests/packages/deep/features/b.js create mode 100644 tests/packages/deep/index.js create mode 100644 tests/packages/deep/package.json create mode 100644 tests/packages/deep/utils/a.js create mode 100644 tests/packages/flat/index.js create mode 100644 tests/packages/flat/package.json create mode 100644 tests/packages/flat2/index.js create mode 100644 tests/packages/flat2/package.json create mode 100644 tests/packages/list/index.js create mode 100644 tests/packages/list/package.json create mode 100644 tests/packages/string/package.json create mode 100644 tests/testapp/static/js/index.js.map diff --git a/django_esm/utils.py b/django_esm/utils.py index c39a297..94b4469 100644 --- a/django_esm/utils.py +++ b/django_esm/utils.py @@ -102,7 +102,7 @@ def parse_package_json(path: Path = None): try: module = exports["default"] yield from get_static_from_abs_path( - str(Path(name) / module), + name, path / module, settings.BASE_DIR / "node_modules", ) diff --git a/tests/node_modules/.package-lock.json b/tests/node_modules/.package-lock.json index 527af82..d159412 100644 --- a/tests/node_modules/.package-lock.json +++ b/tests/node_modules/.package-lock.json @@ -21,11 +21,27 @@ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==" }, + "node_modules/deep": { + "resolved": "packages/deep", + "link": true + }, + "node_modules/flat": { + "resolved": "packages/flat", + "link": true + }, + "node_modules/flat2": { + "resolved": "packages/flat2", + "link": true + }, "node_modules/htmx.org": { "version": "1.9.10", "resolved": "https://registry.npmjs.org/htmx.org/-/htmx.org-1.9.10.tgz", "integrity": "sha512-UgchasltTCrTuU2DQLom3ohHrBvwr7OqpwyAVJ9VxtNBng4XKkVsqrv0Qr3srqvM9ZNI3f1MmvVQQqK7KW/bTA==" }, + "node_modules/list": { + "resolved": "packages/list", + "link": true + }, "node_modules/lit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/lit/-/lit-3.1.0.tgz", @@ -53,6 +69,15 @@ "dependencies": { "@types/trusted-types": "^2.0.2" } - } + }, + "node_modules/string": { + "resolved": "packages/string", + "link": true + }, + "packages/deep": {}, + "packages/flat": {}, + "packages/flat2": {}, + "packages/list": {}, + "packages/string": {} } } diff --git a/tests/package.json b/tests/package.json index 7d219d3..6734d2b 100644 --- a/tests/package.json +++ b/tests/package.json @@ -9,7 +9,12 @@ "#htmx": "https://unpkg.com/htmx.org@1.9.10" }, "dependencies": { + "deep": "file:packages/deep", + "flat": "file:packages/flat", + "flat2": "file:packages/flat2", "htmx.org": "^1.9.9", - "lit": "^3.1.0" + "list": "file:packages/list", + "lit": "^3.1.0", + "string": "file:packages/string" } } diff --git a/tests/packages/deep/features/a.js b/tests/packages/deep/features/a.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/deep/features/b.js b/tests/packages/deep/features/b.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/deep/index.js b/tests/packages/deep/index.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/deep/package.json b/tests/packages/deep/package.json new file mode 100644 index 0000000..e74878e --- /dev/null +++ b/tests/packages/deep/package.json @@ -0,0 +1,10 @@ +{ + "name": "deep", + "exports": { + ".": { + "import": "./index.js" + }, + "./*": "./*", + "./utils": ["./utils/a.js"] + } +} diff --git a/tests/packages/deep/utils/a.js b/tests/packages/deep/utils/a.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/flat/index.js b/tests/packages/flat/index.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/flat/package.json b/tests/packages/flat/package.json new file mode 100644 index 0000000..cb37f11 --- /dev/null +++ b/tests/packages/flat/package.json @@ -0,0 +1,6 @@ +{ + "name": "flat", + "exports": { + "default": "./index.js" + } +} diff --git a/tests/packages/flat2/index.js b/tests/packages/flat2/index.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/flat2/package.json b/tests/packages/flat2/package.json new file mode 100644 index 0000000..2a9ebd5 --- /dev/null +++ b/tests/packages/flat2/package.json @@ -0,0 +1,7 @@ +{ + "name": "flat2", + "exports": { + "node": "./index.js", + "import": "./index.js" + } +} diff --git a/tests/packages/list/index.js b/tests/packages/list/index.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/packages/list/package.json b/tests/packages/list/package.json new file mode 100644 index 0000000..e70c3a8 --- /dev/null +++ b/tests/packages/list/package.json @@ -0,0 +1,4 @@ +{ + "name": "list", + "exports": ["./index.js"] +} diff --git a/tests/packages/string/package.json b/tests/packages/string/package.json new file mode 100644 index 0000000..7c75573 --- /dev/null +++ b/tests/packages/string/package.json @@ -0,0 +1,4 @@ +{ + "name": "string", + "exports": "./index.js" +} diff --git a/tests/test_utils.py b/tests/test_utils.py index 1abc2e1..59d8d6b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -24,6 +24,12 @@ def test_parse_dependencies(package_json): import_map["@lit/reactive-element"] == "@lit/reactive-element/reactive-element.js" ) + assert import_map["string"] == "string/index.js" + assert import_map["list/index.js"] == "list/index.js" + assert import_map["flat"] == "flat/index.js" + assert import_map["flat2"] == "flat2/index.js" + assert import_map["deep"] == "deep/index.js" + assert import_map["deep/features/a.js"] == "deep/features/a.js" def test_parse_root_package__bad_imports(package_json): diff --git a/tests/testapp/static/js/index.js.map b/tests/testapp/static/js/index.js.map new file mode 100644 index 0000000..e69de29