0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/packages/plugins/memory/test/local-memory.spec.ts
Behrang Yarahmadi 13310814da
#2606 add prettier plugin sort imports (#2607)
* #2606 add prettier plugin sort imprts

* #2606 update pnpm-lock.yaml

* #2606 update eslint rules

* #2606 fixes website directory formatting

Co-authored-by: Ayush Sharma <ayush.sharma@trivago.com>
2021-10-29 17:33:05 +02:00

66 lines
2.1 KiB
TypeScript

import { IPluginStorage, Logger } from '@verdaccio/types';
import LocalMemory from '../src/index';
import { ConfigMemory } from '../src/local-memory';
import { DataHandler } from '../src/memory-handler';
import config from './partials/config';
const logger: Logger = {
error: (e) => console.warn(e),
info: (e) => console.warn(e),
debug: (e) => console.warn(e),
child: (e) => console.warn(e),
warn: (e) => console.warn(e),
http: (e) => console.warn(e),
trace: (e) => console.warn(e),
};
const defaultConfig = { logger, config: null };
describe('memory unit test .', () => {
describe('LocalMemory', () => {
test('should create an LocalMemory instance', () => {
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig);
expect(localMemory).toBeDefined();
});
test('should create add a package', (done) => {
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig);
localMemory.add('test').then(() => {
localMemory.get().then((data: DataHandler) => {
expect(data).toHaveLength(1);
done();
});
});
});
test('should reach max limit', (done) => {
config.limit = 2;
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig);
localMemory.add('test1').then(() => {
localMemory.add('test2').then(() => {
localMemory.add('test3').catch((err) => {
expect(err).not.toBeNull();
expect(err.message).toMatch(/Storage memory has reached limit of limit packages/);
done();
});
});
});
});
test('should remove a package', (done) => {
const pkgName = 'test';
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig);
localMemory.add(pkgName).then(() => {
localMemory.remove(pkgName).then(() => {
localMemory.get().then((data) => {
expect(data).toHaveLength(0);
done();
});
});
});
});
});
});