Skip to content

Commit

Permalink
fix: Corrected wrong fix for problem in
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Jun 9, 2023
1 parent 8bc0a6e commit 367fe89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
11 changes: 2 additions & 9 deletions lib/DependencyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,15 @@ export class DependencyResolver {
}. Using that`
)
dependency.targetModule = existingModule
} else if (!this._store.hasPuppetfileRequirementWithTargetModule(dependency.targetModule.getSlug())) {
this._log.debug(
`Dependency ${dependency.targetModule.getSlug()} is not already a base Puppetfile requirement, adding it.`
)
} else {
this._log.debug(`Adding requirement for dependency to ${dependency.targetModule.getSlug()}`)
this._store.addRequirement(
new Requirement()
.withSource(RequirementSource.Dependency)
.withSourceModule(targetModule)
.withTargetModule(dependency.targetModule)
.withDependencyRange(dependency.dependencyRange)
)
} else if (
this._store.hasPuppetfileRequirementWithTargetModule(dependency.targetModule.getSlug()) &&
!this._ignoreList.some((slug) => slug === dependency.targetModule?.getSlug())
) {
throw new NoVersionFoundError(dependency)
}
}
}
Expand Down
30 changes: 29 additions & 1 deletion test/dependency.resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('The dependency resolver', function () {
],
},
})
sb.get('/v3/releases/test-wrongdepc-1.2.2').setResponseBody({
slug: 'test-defaultdependency',
metadata: {
dependencies: [],
},
})
sb.get('/v3/releases/test-wrongdepc-1.2.3').setResponseBody({
slug: 'test-defaultdependency',
metadata: {
Expand Down Expand Up @@ -124,6 +130,9 @@ describe('The dependency resolver', function () {
{
version: '1.2.3',
},
{
version: '1.2.2',
},
],
})
sb.get('/v3/modules/test-deprecated').setResponseBody({
Expand Down Expand Up @@ -185,6 +194,25 @@ mod 'test-dependency', '1.2.4'
expect(subject.dependentModules[0].version).toEqual('1.2.5')
})

it('should create a valid puppetfile when a dependency is in the Puppetfile', async () => {
const subject = await new DependencyResolver()
.withPuppetFile(
await new PuppetFile().fromText(`
forge 'http://localhost:${sb.getPort()}'
mod 'test-default', '1.2.3'
mod 'test-defaultdependency', '1.2.5'
`)
)
.resolve()
expect(subject.modules).toHaveLength(2)
expect(subject.modules[0].getSlug()).toEqual('test-default')
expect(subject.modules[0].version).toEqual('1.2.3')
expect(subject.modules[1].getSlug()).toEqual('test-defaultdependency')
expect(subject.modules[1].version).toEqual('1.2.5')
expect(subject.dependentModules).toHaveLength(0)
})

it('should hide items from the puppetfile', async () => {
const subject = await new DependencyResolver()
.withPuppetFile(
Expand Down Expand Up @@ -284,7 +312,7 @@ mod 'test-deprecated', '1.2.3'
forge 'http://localhost:${sb.getPort()}'
mod 'test-wrongdepa', '1.2.3'
mod 'test-wrongdepc', '1.2.3'
mod 'test-wrongdepc', '1.2.2'
`)
)

Expand Down

0 comments on commit 367fe89

Please sign in to comment.