pnpm

Форк
0
/
node.test.ts 
73 строки · 2.1 Кб
1
import AdmZip from 'adm-zip'
2
import { Response } from 'node-fetch'
3
import path from 'path'
4
import { Readable } from 'stream'
5
import { fetchNode, type FetchNodeOptions } from '@pnpm/node.fetcher'
6
import { tempDir } from '@pnpm/prepare'
7
import { isNonGlibcLinux } from 'detect-libc'
8

9
jest.mock('detect-libc', () => ({
10
  isNonGlibcLinux: jest.fn(),
11
}))
12

13
const fetchMock = jest.fn(async (url: string) => {
14
  if (url.endsWith('.zip')) {
15
    // The Windows code path for pnpm's node bootstrapping expects a subdir
16
    // within the .zip file.
17
    const pkgName = path.basename(url, '.zip')
18
    const zip = new AdmZip()
19
    zip.addFile(`${pkgName}/dummy-file`, Buffer.from('test'))
20

21
    return new Response(Readable.from(zip.toBuffer()))
22
  }
23

24
  return new Response(Readable.from(Buffer.alloc(0)))
25
})
26

27
beforeEach(() => {
28
  (isNonGlibcLinux as jest.Mock).mockReturnValue(Promise.resolve(false))
29
  fetchMock.mockClear()
30
})
31

32
test.skip('install Node using a custom node mirror', async () => {
33
  tempDir()
34

35
  const nodeMirrorBaseUrl = 'https://pnpm-node-mirror-test.localhost/download/release/'
36
  const opts: FetchNodeOptions = {
37
    nodeMirrorBaseUrl,
38
    cafsDir: path.resolve('files'),
39
  }
40

41
  await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
42

43
  for (const call of fetchMock.mock.calls) {
44
    expect(call[0]).toMatch(nodeMirrorBaseUrl)
45
  }
46
})
47

48
test.skip('install Node using the default node mirror', async () => {
49
  tempDir()
50

51
  const opts: FetchNodeOptions = {
52
    cafsDir: path.resolve('files'),
53
  }
54

55
  await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
56

57
  for (const call of fetchMock.mock.calls) {
58
    expect(call[0]).toMatch('https://nodejs.org/download/release/')
59
  }
60
})
61

62
test('install Node using a custom node mirror', async () => {
63
  (isNonGlibcLinux as jest.Mock).mockReturnValue(Promise.resolve(true))
64
  tempDir()
65

66
  const opts: FetchNodeOptions = {
67
    cafsDir: path.resolve('files'),
68
  }
69

70
  await expect(
71
    fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
72
  ).rejects.toThrow('The current system uses the "MUSL" C standard library. Node.js currently has prebuilt artifacts only for the "glibc" libc, so we can install Node.js only for glibc')
73
})
74

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.