From 7d147e8b5f4fc64772c31d62ab83870694bece66 Mon Sep 17 00:00:00 2001 From: Lewis Jones Date: Wed, 9 Jul 2025 11:56:34 +0100 Subject: [PATCH] Add nested dirs to test --- componentDetection.test.ts | 12 +++++++--- test/nested/package-lock.json | 45 +++++++++++++++++++++++++++++++++++ test/nested/package.json | 12 ++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 test/nested/package-lock.json create mode 100644 test/nested/package.json diff --git a/componentDetection.test.ts b/componentDetection.test.ts index c9e1b5a..0e7edfe 100644 --- a/componentDetection.test.ts +++ b/componentDetection.test.ts @@ -198,12 +198,18 @@ describe('normalizeDependencyGraphPaths with real output.json', () => { const dependencyGraphs = output.dependencyGraphs; // Use the same filePath as the action default (".") const normalized = ComponentDetection.normalizeDependencyGraphPaths(dependencyGraphs, 'test'); - // Root level manifests should not have leading slashes + + // Should contain root level manifests without leading slashes expect(Object.keys(normalized)).toContain('package.json'); expect(Object.keys(normalized)).toContain('package-lock.json'); - // All keys should now be relative to the repo root (cwd) and start with '/' + + // Should contain nested manifests with relative paths (no leading slashes) + expect(Object.keys(normalized)).toContain('nested/package.json'); + expect(Object.keys(normalized)).toContain('nested/package-lock.json'); + + // All keys should be relative paths without leading slashes for (const key of Object.keys(normalized)) { - expect(key.startsWith('/')).toBe(true); + expect(key.startsWith('/')).toBe(false); // No leading slashes expect(key).not.toMatch(/^\w:\\|^\/\/|^\.{1,2}\//); // Not windows absolute, not network, not relative } }); diff --git a/test/nested/package-lock.json b/test/nested/package-lock.json new file mode 100644 index 0000000..75a79a1 --- /dev/null +++ b/test/nested/package-lock.json @@ -0,0 +1,45 @@ +{ + "name": "nested-test-package", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "nested-test-package", + "version": "1.0.0", + "dependencies": { + "lodash": "^4.17.21" + }, + "devDependencies": { + "jest": "^29.0.0" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/jest": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", + "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", + "dev": true, + "bin": { + "jest": "bin/jest.js" + } + } + }, + "dependencies": { + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "jest": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", + "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", + "dev": true + } + } +} diff --git a/test/nested/package.json b/test/nested/package.json new file mode 100644 index 0000000..90d8828 --- /dev/null +++ b/test/nested/package.json @@ -0,0 +1,12 @@ +{ + "name": "nested-test-package", + "version": "1.0.0", + "description": "A nested test package for component detection testing", + "main": "index.js", + "dependencies": { + "lodash": "^4.17.21" + }, + "devDependencies": { + "jest": "^29.0.0" + } +}