0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
verdaccio/packages/server/express/test/_helper.ts
Juan Picado e93d6a30a4
chore: vitest migration part 5 (#4914)
* migrate web package to vitest

* migrate node-api to vitest

* migrate file-locking vitest

* migrate cli

* remove jest from npm packages

* Create weak-cherries-serve.md

* update ci
2024-10-20 19:26:36 +02:00

29 lines
958 B
TypeScript

import { Application } from 'express';
import path from 'path';
import { parseConfigFile } from '@verdaccio/config';
import { fileUtils } from '@verdaccio/core';
import { setup } from '@verdaccio/logger';
import { generateRandomHexString } from '@verdaccio/utils';
import apiMiddleware from '../src';
export const getConf = async (conf) => {
const configPath = path.join(__dirname, 'config', conf);
const config = parseConfigFile(configPath);
// generate and create storage folder
const storage = await fileUtils.createTempFolder('config');
config.storage = storage;
// custom config to avoid conflict with other tests
config.auth.htpasswd.file = path.join(
storage,
`${config.auth.htpasswd.file}-${generateRandomHexString()}`
);
return config;
};
export async function initializeServer(configName): Promise<Application> {
const config = await getConf(configName);
setup(config.log ?? {});
return apiMiddleware(config);
}