Skip to content

Commit

Permalink
fix: fix unit tests with latest versions of packages (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
gemaxim authored Dec 16, 2024
1 parent fca32a6 commit d5b4b4e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,32 @@ interface DependencyInfo {
directDeps: string[];
}

// This function is a helper to return the version a dependency gets resolved to in the graph
// (in case we aren't able to determine it). This is useful for transitive dependencies
// where the latest version of the package gets pulled in by a top level dependency.
// This latest version can vary between python version and is not consistent for testing with `compareTransitiveLines`
function getGraphPkg(
graph: depGraphLib.DepGraph,
depInfo: DependencyInfo
): depGraphLib.Pkg {
const pkgs = graph.getPkgs();
if (depInfo.pkg.version) {
return depInfo.pkg;
}
return pkgs.filter((pkg) => pkg.name == depInfo.pkg.name)[0];
}

// We can't do a full dependency graph comparison, as generated dependency graphs vary wildly
// between Python versions. Instead, we ensure that the transitive lines are not broken.
function compareTransitiveLines(
received: depGraphLib.DepGraph,
expected: DependencyInfo[]
) {
expected.forEach((depInfo: DependencyInfo) => {
expect(
received.directDepsLeadingTo(depInfo.pkg).map((pkg) => pkg.name)
).toEqual(depInfo.directDeps);
const pkg = getGraphPkg(received, depInfo);
expect(received.directDepsLeadingTo(pkg).map((pkg) => pkg.name)).toEqual(
depInfo.directDeps
);
});
}

Expand Down Expand Up @@ -100,7 +116,7 @@ describe('inspect', () => {
{
pkg: {
name: 'jaraco.collections',
version: '5.0.1',
version: '5.1.0',
},
directDeps: ['irc'],
},
Expand All @@ -121,7 +137,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand All @@ -135,7 +150,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -163,7 +177,7 @@ describe('inspect', () => {
{
pkg: {
name: 's3transfer',
version: '0.10.2',
version: '0.10.4',
},
directDeps: ['awss'],
},
Expand All @@ -177,7 +191,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -314,7 +327,7 @@ describe('inspect', () => {
{
pkg: {
name: 'jaraco.collections',
version: '5.0.1',
version: '5.1.0',
},
directDeps: ['irc'],
},
Expand All @@ -335,7 +348,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand All @@ -349,7 +361,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -377,7 +388,7 @@ describe('inspect', () => {
{
pkg: {
name: 's3transfer',
version: '0.10.2',
version: '0.10.4',
},
directDeps: ['awss'],
},
Expand All @@ -391,7 +402,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -698,7 +708,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -750,7 +759,6 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down

0 comments on commit d5b4b4e

Please sign in to comment.