|
| 1 | +import {structUtils, Configuration, Project, StreamReport} from '@yarnpkg/core'; |
| 2 | + |
| 3 | +import {NpmTarballResolver} from '../sources/NpmTarballResolver'; |
| 4 | + |
| 5 | +import {makeConfiguration} from './_makeConfiguration'; |
| 6 | + |
| 7 | +describe(`NpmTarballResolver`, () => { |
| 8 | + let configuration: Configuration; |
| 9 | + let project: Project; |
| 10 | + let resolver: NpmTarballResolver; |
| 11 | + |
| 12 | + beforeEach(async () => { |
| 13 | + configuration = await makeConfiguration(); |
| 14 | + project = new Project(configuration.projectCwd!, {configuration}); |
| 15 | + resolver = new NpmTarballResolver(); |
| 16 | + }); |
| 17 | + describe(`supportsDescriptor`, () => { |
| 18 | + it(`should support npm descriptors with __archiveUrl parameters`, () => { |
| 19 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 20 | + const descriptor = structUtils.makeDescriptor(ident, `npm:1.0.0::__archiveUrl=https://registry.example.org/test-package-1.0.0.tgz`); |
| 21 | + |
| 22 | + expect(resolver.supportsDescriptor(descriptor, {project, resolver})).toBe(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it(`should not support npm descriptors without __archiveUrl parameters`, () => { |
| 26 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 27 | + const descriptor = structUtils.makeDescriptor(ident, `npm:1.0.0`); |
| 28 | + |
| 29 | + expect(resolver.supportsDescriptor(descriptor, {project, resolver})).toBe(false); |
| 30 | + }); |
| 31 | + |
| 32 | + it(`should not support non-npm descriptors`, () => { |
| 33 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 34 | + const descriptor = structUtils.makeDescriptor(ident, `file:./local-package.tgz`); |
| 35 | + |
| 36 | + expect(resolver.supportsDescriptor(descriptor, {project, resolver})).toBe(false); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + describe(`supportsLocator`, () => { |
| 41 | + it(`should not support any locators (handled by NpmSemverResolver)`, () => { |
| 42 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 43 | + const locator = structUtils.makeLocator(ident, `npm:1.0.0::__archiveUrl=https://registry.example.org/test-package-1.0.0.tgz`); |
| 44 | + |
| 45 | + expect(resolver.supportsLocator(locator, {project, resolver})).toBe(false); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe(`getCandidates`, () => { |
| 50 | + it(`should convert descriptor to locator`, async () => { |
| 51 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 52 | + const descriptor = structUtils.makeDescriptor(ident, `npm:1.0.0::__archiveUrl=https://registry.example.org/test-package-1.0.0.tgz`); |
| 53 | + const report = new StreamReport({stdout: process.stdout, configuration}); |
| 54 | + |
| 55 | + const candidates = await resolver.getCandidates(descriptor, {}, {project, resolver, report}); |
| 56 | + |
| 57 | + expect(candidates.length).toBe(1); |
| 58 | + expect(candidates[0].identHash).toBe(descriptor.identHash); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe(`getSatisfying`, () => { |
| 63 | + it(`should filter locators that match the descriptor`, async () => { |
| 64 | + const ident = structUtils.makeIdent(null, `test-package`); |
| 65 | + const descriptor = structUtils.makeDescriptor(ident, `npm:1.0.0::__archiveUrl=https://registry.example.org/test-package-1.0.0.tgz`); |
| 66 | + const locator1 = structUtils.makeLocator(ident, `npm:1.0.0::__archiveUrl=https://registry.example.org/test-package-1.0.0.tgz`); |
| 67 | + const locator2 = structUtils.makeLocator(ident, `npm:2.0.0::__archiveUrl=https://registry.example.org/test-package-2.0.0.tgz`); |
| 68 | + const report = new StreamReport({stdout: process.stdout, configuration}); |
| 69 | + |
| 70 | + const result = await resolver.getSatisfying(descriptor, {}, [locator1, locator2], {project, resolver, report}); |
| 71 | + |
| 72 | + expect(result.locators.length).toBe(1); |
| 73 | + expect(result.locators[0].locatorHash).toBe(locator1.locatorHash); |
| 74 | + expect(result.sorted).toBe(false); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments