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:
parent
1d2f33c5bf
commit
a049bba201
9 changed files with 24 additions and 30 deletions
9
.changeset/silent-bags-listen.md
Normal file
9
.changeset/silent-bags-listen.md
Normal 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
|
|
@ -14,7 +14,7 @@ const { mkdir, mkdtemp } = fs.promises ? fs.promises : require('fs/promises');
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
export async function createTempFolder(prefix: string): Promise<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 + '-'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,7 +13,7 @@ async function readLogFile(path: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createLogFile() {
|
async function createLogFile() {
|
||||||
const folder = await fileUtils.createTempFolder('logger-1');
|
const folder = await fileUtils.createTempFolder('logger');
|
||||||
const file = join(folder, 'logger.log');
|
const file = join(folder, 'logger.log');
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ let locaDatabase: pluginUtils.Storage<{}>;
|
||||||
describe('Local Database', () => {
|
describe('Local Database', () => {
|
||||||
let tmpFolder;
|
let tmpFolder;
|
||||||
beforeEach(async () => {
|
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 tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
|
||||||
locaDatabase = new LocalDatabase(
|
locaDatabase = new LocalDatabase(
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -58,7 +58,7 @@ describe('Local Database', () => {
|
||||||
mockmkdir.mockImplementation(() => {
|
mockmkdir.mockImplementation(() => {
|
||||||
throw Error();
|
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 tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
|
||||||
const instance = new LocalDatabase(
|
const instance = new LocalDatabase(
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { Readable } from 'stream';
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
import { fileUtils } from '@verdaccio/core';
|
import { fileUtils } from '@verdaccio/core';
|
||||||
import { createTempFolder } from '@verdaccio/test-helper';
|
|
||||||
import { Logger, Manifest } from '@verdaccio/types';
|
import { Logger, Manifest } from '@verdaccio/types';
|
||||||
|
|
||||||
import LocalDriver from '../src/local-fs';
|
import LocalDriver from '../src/local-fs';
|
||||||
|
@ -78,15 +77,16 @@ describe('Local FS test', () => {
|
||||||
test('should write a tarball', () =>
|
test('should write a tarball', () =>
|
||||||
new Promise((done) => {
|
new Promise((done) => {
|
||||||
const abort = new AbortController();
|
const abort = new AbortController();
|
||||||
const tmp = createTempFolder('local-fs-write-tarball');
|
fileUtils.createTempFolder('local-fs-write-tarball').then((tmp) => {
|
||||||
const localFs = new LocalDriver(tmp, logger);
|
const localFs = new LocalDriver(tmp, logger);
|
||||||
const readableStream = Readable.from('foooo');
|
const readableStream = Readable.from('foooo');
|
||||||
// TODO: verify file exist
|
// TODO: verify file exist
|
||||||
localFs.writeTarball('juan-1.0.0.tgz', { signal: abort.signal }).then((stream) => {
|
localFs.writeTarball('juan-1.0.0.tgz', { signal: abort.signal }).then((stream) => {
|
||||||
stream.on('finish', () => {
|
stream.on('finish', () => {
|
||||||
done(true);
|
done(true);
|
||||||
|
});
|
||||||
|
readableStream.pipe(stream);
|
||||||
});
|
});
|
||||||
readableStream.pipe(stream);
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe('Local Database', () => {
|
||||||
let tmpFolder;
|
let tmpFolder;
|
||||||
let locaDatabase;
|
let locaDatabase;
|
||||||
beforeEach(async () => {
|
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 tempFolder = path.join(tmpFolder, 'verdaccio-test.yaml');
|
||||||
const writeMock = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
|
const writeMock = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
|
||||||
locaDatabase = new LocalDatabase( // @ts-expect-error
|
locaDatabase = new LocalDatabase( // @ts-expect-error
|
||||||
|
|
|
@ -6,4 +6,3 @@ export { addNewVersion } from './addNewVersion';
|
||||||
export { generatePublishNewVersionManifest } from './generatePublishNewVersionManifest';
|
export { generatePublishNewVersionManifest } from './generatePublishNewVersionManifest';
|
||||||
export { initializeServer } from './initializeServer';
|
export { initializeServer } from './initializeServer';
|
||||||
export { publishVersion } from './actions';
|
export { publishVersion } from './actions';
|
||||||
export { createTempFolder } from './utils';
|
|
||||||
|
|
|
@ -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 => {
|
export const getTarball = (name: string): string => {
|
||||||
const r = name.split('/');
|
const r = name.split('/');
|
||||||
if (r.length === 1) {
|
if (r.length === 1) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ export class Registry {
|
||||||
config: Partial<ConfigYaml>
|
config: Partial<ConfigYaml>
|
||||||
): Promise<{ tempFolder: string; configPath: string; yamlContent: string }> {
|
): Promise<{ tempFolder: string; configPath: string; yamlContent: string }> {
|
||||||
debug(`fromConfigToPath`);
|
debug(`fromConfigToPath`);
|
||||||
const tempFolder = await fileUtils.createTempFolder('registry-');
|
const tempFolder = await fileUtils.createTempFolder('registry');
|
||||||
debug(`tempFolder %o`, tempFolder);
|
debug(`tempFolder %o`, tempFolder);
|
||||||
const yamlContent = fromJStoYAML(config) as string;
|
const yamlContent = fromJStoYAML(config) as string;
|
||||||
const configPath = path.join(tempFolder, 'registry.yaml');
|
const configPath = path.join(tempFolder, 'registry.yaml');
|
||||||
|
|
Loading…
Reference in a new issue