pnpm
73 строки · 2.1 Кб
1import AdmZip from 'adm-zip'2import { Response } from 'node-fetch'3import path from 'path'4import { Readable } from 'stream'5import { fetchNode, type FetchNodeOptions } from '@pnpm/node.fetcher'6import { tempDir } from '@pnpm/prepare'7import { isNonGlibcLinux } from 'detect-libc'8
9jest.mock('detect-libc', () => ({10isNonGlibcLinux: jest.fn(),11}))12
13const fetchMock = jest.fn(async (url: string) => {14if (url.endsWith('.zip')) {15// The Windows code path for pnpm's node bootstrapping expects a subdir16// within the .zip file.17const pkgName = path.basename(url, '.zip')18const zip = new AdmZip()19zip.addFile(`${pkgName}/dummy-file`, Buffer.from('test'))20
21return new Response(Readable.from(zip.toBuffer()))22}23
24return new Response(Readable.from(Buffer.alloc(0)))25})26
27beforeEach(() => {28(isNonGlibcLinux as jest.Mock).mockReturnValue(Promise.resolve(false))29fetchMock.mockClear()30})31
32test.skip('install Node using a custom node mirror', async () => {33tempDir()34
35const nodeMirrorBaseUrl = 'https://pnpm-node-mirror-test.localhost/download/release/'36const opts: FetchNodeOptions = {37nodeMirrorBaseUrl,38cafsDir: path.resolve('files'),39}40
41await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)42
43for (const call of fetchMock.mock.calls) {44expect(call[0]).toMatch(nodeMirrorBaseUrl)45}46})47
48test.skip('install Node using the default node mirror', async () => {49tempDir()50
51const opts: FetchNodeOptions = {52cafsDir: path.resolve('files'),53}54
55await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)56
57for (const call of fetchMock.mock.calls) {58expect(call[0]).toMatch('https://nodejs.org/download/release/')59}60})61
62test('install Node using a custom node mirror', async () => {63(isNonGlibcLinux as jest.Mock).mockReturnValue(Promise.resolve(true))64tempDir()65
66const opts: FetchNodeOptions = {67cafsDir: path.resolve('files'),68}69
70await expect(71fetchNode(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