mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-23 22:27:34 -05:00
5bfab621d4
* feat: add tarball details for published packages * remove throw err
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
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();
|
|
});
|
|
});
|