Skip to content

Commit

Permalink
fix: handle-empty-property-group
Browse files Browse the repository at this point in the history
  • Loading branch information
37IulianPopovici committed Jan 16, 2025
1 parent c12b34b commit 384c222
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,19 @@ export function getTargetFrameworksFromProjectFile(manifestFile) {
if (!projectPropertyGroup) {
return targetFrameworksResult;
}
const propertyList =
projectPropertyGroup.find((propertyGroup) => {
return (
'TargetFramework' in propertyGroup ||
'TargetFrameworks' in propertyGroup ||
'TargetFrameworkVersion' in propertyGroup
);
}) || {};
let propertyList: any = {};
try {
propertyList =
projectPropertyGroup.find((propertyGroup) => {
return (
'TargetFramework' in propertyGroup ||
'TargetFrameworks' in propertyGroup ||
'TargetFrameworkVersion' in propertyGroup
);
}) || {};
} catch (err) {
propertyList = {};
}

if (isEmpty(propertyList)) {
return targetFrameworksResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions test/fixtures/dotnet-empty-property-group/expected-tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "",
"version": "",
"hasDevDependencies": false,
"dependencies": {}
}
1 change: 1 addition & 0 deletions test/fixtures/dotnet-empty-property-group/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?>
22 changes: 22 additions & 0 deletions test/lib/dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ test('.Net dotnet-empty-manifest returns empty tree', async () => {
expect(tree).toEqual(expectedTree);
});

test('.Net dotnet-empty-property-group returns empty tree', async () => {
const includeDev = false;
const tree = await buildDepTreeFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'packages.config',
includeDev,
);
const expectedTree = load('dotnet-empty-property-group/expected-tree.json');
expect(tree).toEqual(expectedTree);
});

test('.Net dotnet-invalid-manifest throws', async () => {
const unparsableManifestError =
new OpenSourceEcosystems.UnparseableManifestError(
Expand Down Expand Up @@ -196,6 +207,17 @@ test('.Net .csproj dotnet-empty-manifest returns empty tree', async () => {
expect(tree).toEqual(expectedTree);
});

test('.Net .csproj dotnet-empty-property-group returns empty tree', async () => {
const includeDev = false;
const tree = await buildDepTreeFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'empty-property-group.csproj',
includeDev,
);
const expectedTree = load('dotnet-empty-property-group/expected-tree.json');
expect(tree).toEqual(expectedTree);
});

test('.Net .csproj core dotnet-invalid-manifest throws', async () => {
const unparsableManifestError =
new OpenSourceEcosystems.UnparseableManifestError(
Expand Down
22 changes: 22 additions & 0 deletions test/lib/target-frameworks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ describe('Target framework tests', () => {
},
);

it.concurrent(
'.Net .csproj dotnet-empty-property-group target framework extracted',
async () => {
const targetFrameworks = await extractTargetFrameworksFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'empty-property-group.csproj',
);
expect(targetFrameworks).toEqual([]);
},
);

it.concurrent(
'.Net .csproj multiple target frameworks extracted as expected',
async () => {
Expand Down Expand Up @@ -133,6 +144,17 @@ describe('Target framework tests', () => {
},
);

it.concurrent(
'.Net packages.config dotnet-empty-property-group target framework extracted',
async () => {
const targetFrameworks = await extractTargetFrameworksFromFiles(
`${__dirname}/../fixtures/dotnet-empty-property-group`,
'packages.config',
);
expect(targetFrameworks).toEqual([]);
},
);

/*
****** project.json ******
*/
Expand Down

0 comments on commit 384c222

Please sign in to comment.