mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
0c7b19b192
* chore: migrate core to vitest * chore: migrate url module * chore: migrate tarball package * chore: migrate loader package * chore: migrate hook package * chore: migrate signature package * chore: migrate utils package
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
import { getTarballDetails } from '../src/getTarballDetails.ts';
|
|
|
|
const getFilePath = (filename: string): string => {
|
|
return path.resolve(__dirname, `assets/${filename}`);
|
|
};
|
|
|
|
const getFileBuffer = async (filename: string): Promise<Buffer> => {
|
|
return fs.promises.readFile(getFilePath(filename));
|
|
};
|
|
|
|
describe('getTarballDetails', () => {
|
|
test('should return stats of tarball (gzipped)', async () => {
|
|
const buffer = await getFileBuffer('tarball.tgz');
|
|
const details = await getTarballDetails(buffer);
|
|
expect(details.fileCount).toBe(2);
|
|
expect(details.unpackedSize).toBe(1280);
|
|
});
|
|
|
|
test('should return stats of tarball (uncompressed)', async () => {
|
|
const buffer = await getFileBuffer('tarball.tar');
|
|
const details = await getTarballDetails(buffer);
|
|
expect(details.fileCount).toBe(2);
|
|
expect(details.unpackedSize).toBe(1280);
|
|
});
|
|
|
|
test('should throw an error if the buffer is corrupt', async () => {
|
|
const corruptBuffer = Buffer.from('this is not a tarball');
|
|
await expect(getTarballDetails(corruptBuffer)).rejects.toThrow();
|
|
});
|
|
});
|