From 4cd2bc2d2ad79e7b9d7439b853604ba94dcd1b91 Mon Sep 17 00:00:00 2001 From: Levan Giguashvili Date: Mon, 15 Apr 2019 15:35:38 +0300 Subject: [PATCH] fix: make sure that the projects const is iteratable when testing against a packages.config file that has no deps we got an error stating that we cannot do forEach on undefined, this PR fixes that. --- lib/nuget-parser/packages-config-parser.js | 4 +++- test/parse-packages-config-no-deps.test.js | 21 +++++++++++++++++++ .../packages-config-no-deps/nodeps.csproj | 5 +++++ .../packages-config-no-deps/packages.config | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/parse-packages-config-no-deps.test.js create mode 100644 test/stubs/packages-config-no-deps/nodeps.csproj create mode 100644 test/stubs/packages-config-no-deps/packages.config diff --git a/lib/nuget-parser/packages-config-parser.js b/lib/nuget-parser/packages-config-parser.js index 37f9a199..4bc8f529 100644 --- a/lib/nuget-parser/packages-config-parser.js +++ b/lib/nuget-parser/packages-config-parser.js @@ -10,7 +10,9 @@ function parsePackagesConfigFileContents(fileContent) { if (err) { throw err; } else { - result.packages.package.forEach( + const packages = result.packages.package || []; + + packages.forEach( function scanPackagesConfigNode(node) { const installedDependency = Dependency.from.packgesConfigEntry(node); diff --git a/test/parse-packages-config-no-deps.test.js b/test/parse-packages-config-no-deps.test.js new file mode 100644 index 00000000..e4b0bcf1 --- /dev/null +++ b/test/parse-packages-config-no-deps.test.js @@ -0,0 +1,21 @@ +'use strict'; + +const test = require('tap').test; +const plugin = require('../lib/index'); +const projectPath = './test/stubs/packages-config-no-deps/'; + +test('parse packages-config-no-deps project successfully', function (t) { + plugin.inspect( + projectPath, + 'packages.config', + { + packagesFolder: projectPath + './_packages', + }) + .then(function () { + t.pass('parsed file correctly'); + t.end(); + }) + .catch(function () { + t.fail('failed parsing a project with no deps'); + }); +}); diff --git a/test/stubs/packages-config-no-deps/nodeps.csproj b/test/stubs/packages-config-no-deps/nodeps.csproj new file mode 100644 index 00000000..470569de --- /dev/null +++ b/test/stubs/packages-config-no-deps/nodeps.csproj @@ -0,0 +1,5 @@ + + + netcoreapp2.0 + + diff --git a/test/stubs/packages-config-no-deps/packages.config b/test/stubs/packages-config-no-deps/packages.config new file mode 100644 index 00000000..037b768b --- /dev/null +++ b/test/stubs/packages-config-no-deps/packages.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file