0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

chore(tests): temp folder naming (#4950)

This commit is contained in:
Marc Bernard 2024-11-16 04:43:12 -05:00 committed by GitHub
parent 1d2f33c5bf
commit a049bba201
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 24 additions and 30 deletions

View file

@ -0,0 +1,9 @@
---
'@verdaccio/logger-commons': patch
'@verdaccio/local-storage': patch
'@verdaccio/test-helper': patch
'@verdaccio/core': patch
'verdaccio': patch
---
chore(tests): temp folder naming

View file

@ -14,7 +14,7 @@ const { mkdir, mkdtemp } = fs.promises ? fs.promises : require('fs/promises');
* @returns string
*/
export async function createTempFolder(prefix: string): Promise<string> {
return await mkdtemp(path.join(os.tmpdir(), prefix));
return await mkdtemp(path.join(os.tmpdir(), 'verdaccio-' + prefix + '-'));
}
/**

View file

@ -13,7 +13,7 @@ async function readLogFile(path: string) {
}
async function createLogFile() {
const folder = await fileUtils.createTempFolder('logger-1');
const folder = await fileUtils.createTempFolder('logger');
const file = join(folder, 'logger.log');
return file;
}

View file

@ -30,7 +30,7 @@ let locaDatabase: pluginUtils.Storage<{}>;
describe('Local Database', () => {
let tmpFolder;
beforeEach(async () => {
tmpFolder = await fileUtils.createTempFolder('local-storage-plugin-');
tmpFolder = await fileUtils.createTempFolder('local-storage-plugin');
const tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
locaDatabase = new LocalDatabase(
// @ts-expect-error
@ -58,7 +58,7 @@ describe('Local Database', () => {
mockmkdir.mockImplementation(() => {
throw Error();
});
const tmpFolder = await fileUtils.createTempFolder('local-storage-plugin-');
const tmpFolder = await fileUtils.createTempFolder('local-storage-plugin');
const tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
const instance = new LocalDatabase(
// @ts-expect-error

View file

@ -4,7 +4,6 @@ import { Readable } from 'stream';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { fileUtils } from '@verdaccio/core';
import { createTempFolder } from '@verdaccio/test-helper';
import { Logger, Manifest } from '@verdaccio/types';
import LocalDriver from '../src/local-fs';
@ -78,15 +77,16 @@ describe('Local FS test', () => {
test('should write a tarball', () =>
new Promise((done) => {
const abort = new AbortController();
const tmp = createTempFolder('local-fs-write-tarball');
const localFs = new LocalDriver(tmp, logger);
const readableStream = Readable.from('foooo');
// TODO: verify file exist
localFs.writeTarball('juan-1.0.0.tgz', { signal: abort.signal }).then((stream) => {
stream.on('finish', () => {
done(true);
fileUtils.createTempFolder('local-fs-write-tarball').then((tmp) => {
const localFs = new LocalDriver(tmp, logger);
const readableStream = Readable.from('foooo');
// TODO: verify file exist
localFs.writeTarball('juan-1.0.0.tgz', { signal: abort.signal }).then((stream) => {
stream.on('finish', () => {
done(true);
});
readableStream.pipe(stream);
});
readableStream.pipe(stream);
});
}));
});

View file

@ -22,7 +22,7 @@ describe('Local Database', () => {
let tmpFolder;
let locaDatabase;
beforeEach(async () => {
tmpFolder = await fileUtils.createTempFolder('local-storage-plugin-');
tmpFolder = await fileUtils.createTempFolder('local-storage-plugin');
const tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
const writeMock = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
locaDatabase = new LocalDatabase( // @ts-expect-error

View file

@ -6,4 +6,3 @@ export { addNewVersion } from './addNewVersion';
export { generatePublishNewVersionManifest } from './generatePublishNewVersionManifest';
export { initializeServer } from './initializeServer';
export { publishVersion } from './actions';
export { createTempFolder } from './utils';

View file

@ -1,17 +1,3 @@
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
/**
* Create a temporary folder.
* @param prefix The prefix of the folder name.
* @returns string
* @deprecated use @verdaccio/core:createTempFolder async function instead
*/
export function createTempFolder(prefix: string): string {
return fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), prefix));
}
export const getTarball = (name: string): string => {
const r = name.split('/');
if (r.length === 1) {

View file

@ -61,7 +61,7 @@ export class Registry {
config: Partial<ConfigYaml>
): Promise<{ tempFolder: string; configPath: string; yamlContent: string }> {
debug(`fromConfigToPath`);
const tempFolder = await fileUtils.createTempFolder('registry-');
const tempFolder = await fileUtils.createTempFolder('registry');
debug(`tempFolder %o`, tempFolder);
const yamlContent = fromJStoYAML(config) as string;
const configPath = path.join(tempFolder, 'registry.yaml');