2022-07-29 20:51:45 +02:00
|
|
|
import { join } from 'path';
|
|
|
|
|
|
|
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
|
|
import { logger, setup } from '@verdaccio/logger';
|
|
|
|
import { IPluginStorage } from '@verdaccio/types';
|
2020-10-23 22:05:46 +02:00
|
|
|
|
2021-10-29 17:33:05 +02:00
|
|
|
import LocalMemory from '../src/index';
|
2020-10-23 22:05:46 +02:00
|
|
|
import { ConfigMemory } from '../src/local-memory';
|
|
|
|
import { DataHandler } from '../src/memory-handler';
|
|
|
|
|
2022-07-29 20:51:45 +02:00
|
|
|
setup();
|
|
|
|
|
|
|
|
const config = new Config(parseConfigFile(join(__dirname, 'config.yaml')));
|
2020-10-23 22:05:46 +02:00
|
|
|
|
2022-07-29 20:51:45 +02:00
|
|
|
const defaultConfig = { logger, config };
|
2020-10-23 22:05:46 +02:00
|
|
|
|
|
|
|
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);
|
2021-09-08 19:06:37 +02:00
|
|
|
localMemory.add('test').then(() => {
|
|
|
|
localMemory.get().then((data: DataHandler) => {
|
2020-10-23 22:05:46 +02:00
|
|
|
expect(data).toHaveLength(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should reach max limit', (done) => {
|
2022-07-29 20:51:45 +02:00
|
|
|
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(
|
|
|
|
// @ts-ignore
|
|
|
|
{ limit: 2 },
|
|
|
|
defaultConfig
|
|
|
|
);
|
2020-10-23 22:05:46 +02:00
|
|
|
|
2021-09-08 19:06:37 +02:00
|
|
|
localMemory.add('test1').then(() => {
|
|
|
|
localMemory.add('test2').then(() => {
|
|
|
|
localMemory.add('test3').catch((err) => {
|
2020-10-23 22:05:46 +02:00
|
|
|
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);
|
2021-09-08 19:06:37 +02:00
|
|
|
localMemory.add(pkgName).then(() => {
|
|
|
|
localMemory.remove(pkgName).then(() => {
|
|
|
|
localMemory.get().then((data) => {
|
2020-10-23 22:05:46 +02:00
|
|
|
expect(data).toHaveLength(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|