Skip to content

Commit

Permalink
fix: added a test provoking the error
Browse files Browse the repository at this point in the history
  • Loading branch information
dotkas committed Nov 17, 2023
1 parent ff69a14 commit 7fa37d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nuget-parser/parsers/dotnet-core-v2-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface DotnetPackage {
}

// Dependencies that starts with these are discarded
const FILTERED_DEPENDENCY_PREFIX = ['runtime'];
export const FILTERED_DEPENDENCY_PREFIX = ['runtime'];

// The list of top level dependencies and transitive dependencies differ based on the target runtime we've defined.
// In the generated dependency file created by the `dotnet` CLI, this is organized by the target framework moniker (TFM).
Expand Down
27 changes: 27 additions & 0 deletions test/parsers/parse-core-v2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import * as plugin from '../../lib';
import * as dotnet from '../../lib/nuget-parser/cli/dotnet';
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
import { FILTERED_DEPENDENCY_PREFIX } from '../../lib/nuget-parser/parsers/dotnet-core-v2-parser';

describe('when generating depGraphs and runtime assemblies using the v2 parser', () => {
it.each([
Expand Down Expand Up @@ -107,6 +108,32 @@ describe('when generating depGraphs and runtime assemblies using the v2 parser',
},
);

it('does not include ignored packages in the resulting depGraph', async () => {
const projectPath = './test/fixtures/dotnetcore/dotnet_8';
await dotnet.restore(projectPath);
const manifestFile = 'obj/project.assets.json';
const result = await plugin.inspect(projectPath, manifestFile, {
'dotnet-runtime-resolution': true,
});

if (!pluginApi.isMultiResult(result)) {
throw new Error('expected a multiResult response from inspection');
}

const depGraph = result.scannedProjects[0].depGraph;

// TS doesn't get expect().toBeDefined() and will still complain
if (!depGraph) {
throw new Error('expected depGraph to be defined');
}

const pkgNames = depGraph.getDepPkgs().map((pkg) => pkg.name);
const filteredPkgNames: string[] = pkgNames.filter((pkgName) =>
FILTERED_DEPENDENCY_PREFIX.some((prefix) => pkgName.startsWith(prefix)),
);
expect(filteredPkgNames).toEqual([]);
});

it.each([
{
description: 'net472 - with package.assets.json',
Expand Down

0 comments on commit 7fa37d4

Please sign in to comment.