From 8b63e76f786ee98de0f46e98e99cb7d1ffc8a36f Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Thu, 3 Oct 2024 12:37:40 -0700 Subject: [PATCH] Add test for package-lock.json #3931 Signed-off-by: Jono Yang --- .../data/npm/alias/package-lock.json | 57 +++++++ .../data/npm/alias/package-lock.json.expected | 149 ++++++++++++++++++ .../package.json | 0 .../package.json.expected | 0 .../yarn.lock | 0 .../yarn.lock-expected | 0 tests/packagedcode/test_npm.py | 19 ++- 7 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 tests/packagedcode/data/npm/alias/package-lock.json create mode 100644 tests/packagedcode/data/npm/alias/package-lock.json.expected rename tests/packagedcode/data/npm/{special_extracted_requirements => alias}/package.json (100%) rename tests/packagedcode/data/npm/{special_extracted_requirements => alias}/package.json.expected (100%) rename tests/packagedcode/data/npm/yarn-lock/{v1-other-constraint => v1-alias}/yarn.lock (100%) rename tests/packagedcode/data/npm/yarn-lock/{v1-other-constraint => v1-alias}/yarn.lock-expected (100%) diff --git a/tests/packagedcode/data/npm/alias/package-lock.json b/tests/packagedcode/data/npm/alias/package-lock.json new file mode 100644 index 0000000000..024ce5c343 --- /dev/null +++ b/tests/packagedcode/data/npm/alias/package-lock.json @@ -0,0 +1,57 @@ +{ + "name": "poshi-language-support", + "version": "0.3.7", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "poshi-language-support", + "version": "0.3.7", + "dependencies": { + "@vscode/ripgrep": "^1.14.2", + "lodash": "^4.17.21" + }, + "devDependencies": { + "@ava/typescript": "^4.1.0", + "@types/glob": "^7.2.0", + "@types/lodash": "^4.14.178", + "@types/mocha": "^9.1.0", + "@types/node": "14.x", + "@types/vscode": "^1.64.0", + "@typescript-eslint/eslint-plugin": "^5.12.1", + "@typescript-eslint/parser": "^5.12.1", + "@vscode/test-electron": "^2.1.2", + "@vscode/vsce": "^2.22.0", + "ava": "^5.3.1", + "esbuild": "^0.18.15", + "eslint": "^8.9.0", + "glob": "^7.2.0", + "mocha": "^9.2.1", + "prettier": "^3.0.0", + "rimraf": "^5.0.1", + "typescript": "^4.5.5" + }, + "engines": { + "node": ">=16", + "vscode": "^1.64.0" + } + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + } + } +} diff --git a/tests/packagedcode/data/npm/alias/package-lock.json.expected b/tests/packagedcode/data/npm/alias/package-lock.json.expected new file mode 100644 index 0000000000..2bfba64986 --- /dev/null +++ b/tests/packagedcode/data/npm/alias/package-lock.json.expected @@ -0,0 +1,149 @@ +[ + { + "type": "npm", + "namespace": "", + "name": "poshi-language-support", + "version": "0.3.7", + "qualifiers": {}, + "subpath": null, + "primary_language": "JavaScript", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "holder": null, + "declared_license_expression": null, + "declared_license_expression_spdx": null, + "license_detections": [], + "other_license_expression": null, + "other_license_expression_spdx": null, + "other_license_detections": [], + "extracted_license_statement": null, + "notice_text": null, + "source_packages": [], + "file_references": [], + "is_private": false, + "is_virtual": false, + "extra_data": { + "lockfile_version": 2 + }, + "dependencies": [ + { + "purl": "pkg:npm/%40isaacs/cliui@8.0.2", + "extracted_requirement": "8.0.2", + "scope": "devDependencies", + "is_runtime": false, + "is_optional": true, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "npm", + "namespace": "@isaacs", + "name": "cliui", + "version": "8.0.2", + "qualifiers": {}, + "subpath": null, + "primary_language": "JavaScript", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": "3bc8dc8da6d76a578e1bd0d0d3e0115d66414df9cfe16340ab3ba224aee5978e009b118abff2763384cf8f18d8df39c109fbc15c5cee726d6dc1dc85c9b16a10", + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "holder": null, + "declared_license_expression": null, + "declared_license_expression_spdx": null, + "license_detections": [], + "other_license_expression": null, + "other_license_expression_spdx": null, + "other_license_detections": [], + "extracted_license_statement": null, + "notice_text": null, + "source_packages": [], + "file_references": [ + [ + { + "path": "node_modules/@isaacs/cliui", + "size": 0, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "extra_data": {} + } + ] + ], + "is_private": false, + "is_virtual": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:npm/string-width", + "extracted_requirement": "^4.2.0", + "scope": "devDependencies", + "is_runtime": false, + "is_optional": true, + "is_resolved": false, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:npm/strip-ansi", + "extracted_requirement": "^6.0.1", + "scope": "devDependencies", + "is_runtime": false, + "is_optional": true, + "is_resolved": false, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:npm/wrap-ansi", + "extracted_requirement": "^7.0.0", + "scope": "devDependencies", + "is_runtime": false, + "is_optional": true, + "is_resolved": false, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": "https://www.npmjs.com/package/@isaacs/cliui", + "repository_download_url": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "api_data_url": "https://registry.npmjs.org/@isaacs%2fcliui/8.0.2", + "datasource_id": "npm_package_lock_json", + "purl": "pkg:npm/%40isaacs/cliui@8.0.2" + }, + "extra_data": {} + } + ], + "repository_homepage_url": "https://www.npmjs.com/package/poshi-language-support", + "repository_download_url": "https://registry.npmjs.org/poshi-language-support/-/poshi-language-support-0.3.7.tgz", + "api_data_url": "https://registry.npmjs.org/poshi-language-support/0.3.7", + "datasource_id": "npm_package_lock_json", + "purl": "pkg:npm/poshi-language-support@0.3.7" + } +] \ No newline at end of file diff --git a/tests/packagedcode/data/npm/special_extracted_requirements/package.json b/tests/packagedcode/data/npm/alias/package.json similarity index 100% rename from tests/packagedcode/data/npm/special_extracted_requirements/package.json rename to tests/packagedcode/data/npm/alias/package.json diff --git a/tests/packagedcode/data/npm/special_extracted_requirements/package.json.expected b/tests/packagedcode/data/npm/alias/package.json.expected similarity index 100% rename from tests/packagedcode/data/npm/special_extracted_requirements/package.json.expected rename to tests/packagedcode/data/npm/alias/package.json.expected diff --git a/tests/packagedcode/data/npm/yarn-lock/v1-other-constraint/yarn.lock b/tests/packagedcode/data/npm/yarn-lock/v1-alias/yarn.lock similarity index 100% rename from tests/packagedcode/data/npm/yarn-lock/v1-other-constraint/yarn.lock rename to tests/packagedcode/data/npm/yarn-lock/v1-alias/yarn.lock diff --git a/tests/packagedcode/data/npm/yarn-lock/v1-other-constraint/yarn.lock-expected b/tests/packagedcode/data/npm/yarn-lock/v1-alias/yarn.lock-expected similarity index 100% rename from tests/packagedcode/data/npm/yarn-lock/v1-other-constraint/yarn.lock-expected rename to tests/packagedcode/data/npm/yarn-lock/v1-alias/yarn.lock-expected diff --git a/tests/packagedcode/test_npm.py b/tests/packagedcode/test_npm.py index 30acb962e2..2e5d5e4f33 100644 --- a/tests/packagedcode/test_npm.py +++ b/tests/packagedcode/test_npm.py @@ -275,6 +275,13 @@ def test_parse_package_lock_v2_2(self): packages = npm.NpmPackageLockJsonHandler.parse(test_file) self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) + def test_parse_package_lock_v2_alias(self): + test_file = self.get_test_loc('npm/alias/package-lock.json') + expected_loc = self.get_test_loc( + 'npm/alias/package-lock.json.expected') + packages = npm.NpmPackageLockJsonHandler.parse(test_file) + self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) + def test_is_datafile_npm_shrinkwrap_json(self): test_file = self.get_test_loc('npm/npm-shrinkwrap/npm-shrinkwrap.json') assert npm.NpmShrinkwrapJsonHandler.is_datafile(test_file) @@ -360,10 +367,10 @@ def test_npm_yarn_with_package_json_resolve_dependencies(self): expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES ) - def test_npm_yarn_lock_v1_parse_with_other_version_constraint(self): - test_file = self.get_test_loc('npm/yarn-lock/v1-other-constraint/yarn.lock') + def test_npm_yarn_lock_v1_parse_alias(self): + test_file = self.get_test_loc('npm/yarn-lock/v1-alias/yarn.lock') expected_loc = self.get_test_loc( - 'npm/yarn-lock/v1-other-constraint/yarn.lock-expected') + 'npm/yarn-lock/v1-alias/yarn.lock-expected') packages = npm.YarnLockV1Handler.parse(test_file) self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) @@ -393,9 +400,9 @@ def test_parse_pnpm_shrinkwrap_yaml(self): packages = npm.PnpmLockYamlHandler.parse(test_file) self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) - def test_parse_package_json_special_dep_requirements(self): - test_file = self.get_test_loc('npm/special_extracted_requirements/package.json') - expected_loc = self.get_test_loc('npm/special_extracted_requirements/package.json.expected') + def test_parse_package_json_alias_requirements(self): + test_file = self.get_test_loc('npm/alias/package.json') + expected_loc = self.get_test_loc('npm/alias/package.json.expected') packages = npm.NpmPackageJsonHandler.parse(test_file) self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES)