diff --git a/bin/beacon.js b/bin/beacon.js index bb66eba..fd74d26 100755 --- a/bin/beacon.js +++ b/bin/beacon.js @@ -11,8 +11,12 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); -const VERSION = '1.0.0'; const PKG_ROOT = path.join(__dirname, '..'); +let VERSION = '1.0.0'; +try { + const pkg = require(path.join(PKG_ROOT, 'package.json')); + if (pkg && pkg.version) VERSION = pkg.version; +} catch (_) {} const INSTALL_DIR = path.join(os.homedir(), '.beacon', 'npm'); const VENV_DIR = path.join(INSTALL_DIR, 'venv'); diff --git a/tests/test_npm_wrapper.py b/tests/test_npm_wrapper.py new file mode 100644 index 0000000..77b7c9e --- /dev/null +++ b/tests/test_npm_wrapper.py @@ -0,0 +1,23 @@ +import json +import os +import subprocess +import unittest + +class TestNpmWrapper(unittest.TestCase): + def test_version_matches_package_json(self): + repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + pkg_json_path = os.path.join(repo_root, "package.json") + beacon_js_path = os.path.join(repo_root, "bin", "beacon.js") + + with open(pkg_json_path, "r", encoding="utf-8") as f: + pkg_data = json.load(f) + expected_version = pkg_data.get("version") + + res = subprocess.run( + ["node", beacon_js_path, "--version"], + capture_output=True, text=True, check=True + ) + self.assertEqual(res.stdout.strip(), expected_version) + +if __name__ == "__main__": + unittest.main()