File: package-request.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (91 lines) | stat: -rw-r--r-- 3,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* @flow */

import PackageRequest from '../src/package-request.js';
import * as reporters from '../src/reporters/index.js';
import PackageResolver from '../src/package-resolver.js';
import Lockfile from '../src/lockfile';
import Config from '../src/config.js';

async function prepareRequest(pattern: string, version: string, resolved: string, parentRequest?: Object): Object {
  const privateDepCache = {[pattern]: {version, resolved}};
  const reporter = new reporters.NoopReporter({});
  const depRequestPattern = {
    pattern,
    registry: 'npm',
    hint: null,
    optional: false,
    parentNames: [],
    parentRequest,
  };
  if (parentRequest) {
    depRequestPattern.parentRequest = parentRequest;
    depRequestPattern.parentNames = [...parentRequest.parentNames, parentRequest.pattern];

    const lock = parentRequest.getLocked();
    privateDepCache[parentRequest.pattern] = {version: lock.version, resolved: lock._remote.resolved};
  }
  const lockfile = new Lockfile({cache: privateDepCache});
  const config = await Config.create({}, reporter);
  const resolver = new PackageResolver(config, lockfile);
  const request = new PackageRequest(depRequestPattern, resolver);

  return {request, reporter};
}

test('Produce valid remote type for a git-over-ssh dep', async () => {
  const {request, reporter} = await prepareRequest(
    'private-dep@github:yarnpkg/private-dep#1.0.0',
    '1.0.0',
    'git+ssh://git@github.com/yarnpkg/private-dep.git#d6c57894210c52be02da7859dbb5205feb85d8b0',
  );

  expect(request.getLocked('git')._remote.type).toBe('git');
  expect(request.getLocked('tarball')._remote.type).toBe('git');

  await reporter.close();
});

test('Produce valid remote type for a git-over-https dep', async () => {
  const {request, reporter} = await prepareRequest(
    'public-dep@yarnpkg/public-dep#1.0.0',
    '1.0.0',
    'git+https://github.com/yarnpkg/public-dep#1fde368',
  );

  expect(request.getLocked('git')._remote.type).toBe('git');
  expect(request.getLocked('tarball')._remote.type).toBe('git');

  await reporter.close();
});

test('Produce valid remote type for a git public dep', async () => {
  const {request, reporter} = await prepareRequest(
    'public-dep@yarnpkg/public-dep#1fde368',
    '1.0.0',
    'https://codeload.github.com/yarnpkg/public-dep/tar.gz/1fde368',
  );

  expect(request.getLocked('git')._remote.type).toBe('git');
  expect(request.getLocked('tarball')._remote.type).toBe('tarball');

  await reporter.close();
});

test('Check parentNames flowing in the request', async () => {
  const {request: parentRequest, reporter: parentReporter} = await prepareRequest(
    'parent@1.0.0',
    '1.0.0',
    'git+ssh://git@github.com/yarnpkg/parent.git',
  );
  expect(parentRequest).not.toBeNull();
  const {request: childRequest, reporter: childReporter} = await prepareRequest(
    'child@1.0.0',
    '1.0.0',
    'git+ssh://git@github.com/yarnpkg/child.git',
    parentRequest,
  );

  expect(childRequest.parentNames).toContain(parentRequest.pattern);
  await parentReporter.close();
  await childReporter.close();
});