mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
chore: migrate vitest more package (#4778)
* chore: migrate proxy package * chore: migrate logger-prettier
This commit is contained in:
parent
0c7b19b192
commit
477f9bcba4
@ -1,10 +0,0 @@
|
||||
const config = require('../../../jest/config');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
// FIXME: increase to 90
|
||||
lines: 60,
|
||||
},
|
||||
},
|
||||
});
|
@ -30,7 +30,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf ./build",
|
||||
"test": "cross-env TZ=utc jest",
|
||||
"test": "cross-env TZ=utc vitest run",
|
||||
"type-check": "tsc --noEmit -p tsconfig.build.json",
|
||||
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
||||
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
||||
|
@ -1,21 +1,21 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`formatter printMessage should display a bytes request 1`] = `"fatal<-- 200, user: null(127.0.0.1), req: 'GET /verdaccio', bytes: 0/150186"`;
|
||||
exports[`formatter > printMessage > should display a bytes request 1`] = `"fatal<-- 200, user: null(127.0.0.1), req: 'GET /verdaccio', bytes: 0/150186"`;
|
||||
|
||||
exports[`formatter printMessage should display a resource request 1`] = `"info <-- 127.0.0.1 requested 'GET /verdaccio'"`;
|
||||
exports[`formatter > printMessage > should display a resource request 1`] = `"info <-- 127.0.0.1 requested 'GET /verdaccio'"`;
|
||||
|
||||
exports[`formatter printMessage should display a streaming request 1`] = `"fatal--> 304, req: 'GET https://registry.npmjs.org/verdaccio' (streaming)"`;
|
||||
exports[`formatter > printMessage > should display a streaming request 1`] = `"fatal--> 304, req: 'GET https://registry.npmjs.org/verdaccio' (streaming)"`;
|
||||
|
||||
exports[`formatter printMessage should display an error request 1`] = `"fatal--> ERR, req: 'GET https://registry.fake.org/aaa', error: getaddrinfo ENOTFOUND registry.fake.org"`;
|
||||
exports[`formatter > printMessage > should display an error request 1`] = `"fatal--> ERR, req: 'GET https://registry.fake.org/aaa', error: getaddrinfo ENOTFOUND registry.fake.org"`;
|
||||
|
||||
exports[`formatter printMessage should display an fatal request 1`] = `"fatal--> ERR, req: 'GET https://registry.fake.org/aaa', error: fatal error"`;
|
||||
exports[`formatter > printMessage > should display an fatal request 1`] = `"fatal--> ERR, req: 'GET https://registry.fake.org/aaa', error: fatal error"`;
|
||||
|
||||
exports[`formatter printMessage should display config file 1`] = `"warn --- config file - /Users/user/.config/verdaccio/config/config.yaml"`;
|
||||
exports[`formatter > printMessage > should display config file 1`] = `"warn --- config file - /Users/user/.config/verdaccio/config/config.yaml"`;
|
||||
|
||||
exports[`formatter printMessage should display custom log message 1`] = `"fatal--- custom - foo - undefined"`;
|
||||
exports[`formatter > printMessage > should display custom log message 1`] = `"fatal--- custom - foo - undefined"`;
|
||||
|
||||
exports[`formatter printMessage should display trace level 1`] = `"trace--- [trace] - foo"`;
|
||||
exports[`formatter > printMessage > should display trace level 1`] = `"trace--- [trace] - foo"`;
|
||||
|
||||
exports[`formatter printMessage should display trace level with pretty stamp 1`] = `"[formatted-date] trace--- [trace] - foo"`;
|
||||
exports[`formatter > printMessage > should display trace level with pretty stamp 1`] = `"[formatted-date] trace--- [trace] - foo"`;
|
||||
|
||||
exports[`formatter printMessage should display version and http address 1`] = `"warn --- http address - http://localhost:4873/ - verdaccio/5.0.0"`;
|
||||
exports[`formatter > printMessage > should display version and http address 1`] = `"warn --- http address - http://localhost:4873/ - verdaccio/5.0.0"`;
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { printMessage } from '../src/formatter';
|
||||
import { LevelCode } from '../src/levels';
|
||||
|
||||
jest.mock('dayjs', () => ({
|
||||
vi.mock('dayjs', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
format: () => 'formatted-date',
|
||||
|
@ -1,5 +1,6 @@
|
||||
import pino from 'pino';
|
||||
import { Writable } from 'stream';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { buildPretty } from '../src';
|
||||
|
||||
@ -10,7 +11,8 @@ describe('prettyFactory', () => {
|
||||
prettyStamp: false,
|
||||
colors: false,
|
||||
};
|
||||
test('should return a function', (done) => {
|
||||
test('should return a function', () =>
|
||||
new Promise((done) => {
|
||||
const pretty = buildPretty(prettyfierOptions);
|
||||
const log = pino(
|
||||
new Writable({
|
||||
@ -19,10 +21,10 @@ describe('prettyFactory', () => {
|
||||
const formatted = pretty(JSON.parse(chunk));
|
||||
expect(formatted).toBe('info --- test message');
|
||||
cb();
|
||||
done();
|
||||
done(true);
|
||||
},
|
||||
})
|
||||
);
|
||||
log.info({ test: 'test' }, '@{test} message');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { formatLoggingDate, padRight } from '../src/utils';
|
||||
|
||||
describe('formatLoggingDate', () => {
|
||||
|
@ -1,10 +0,0 @@
|
||||
const config = require('../../../jest/config');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
// FIXME: increase to 90
|
||||
lines: 39,
|
||||
},
|
||||
},
|
||||
});
|
@ -1,12 +0,0 @@
|
||||
const config = require('../../jest/config');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 79,
|
||||
functions: 90,
|
||||
lines: 86,
|
||||
statements: 86,
|
||||
},
|
||||
},
|
||||
});
|
@ -26,11 +26,11 @@
|
||||
"verdaccio"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf ./build",
|
||||
"test": "jest",
|
||||
"test": "vitest run",
|
||||
"type-check": "tsc --noEmit -p tsconfig.build.json",
|
||||
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
||||
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { DEFAULT_REGISTRY } from '@verdaccio/config';
|
||||
import { HEADERS, TOKEN_BASIC, TOKEN_BEARER, constants } from '@verdaccio/core';
|
||||
import { Logger } from '@verdaccio/types';
|
||||
@ -5,11 +7,11 @@ import { buildToken } from '@verdaccio/utils';
|
||||
|
||||
import { ProxyStorage } from '../src';
|
||||
|
||||
const mockDebug = jest.fn();
|
||||
const mockInfo = jest.fn();
|
||||
const mockHttp = jest.fn();
|
||||
const mockError = jest.fn();
|
||||
const mockWarn = jest.fn();
|
||||
const mockDebug = vi.fn();
|
||||
const mockInfo = vi.fn();
|
||||
const mockHttp = vi.fn();
|
||||
const mockError = vi.fn();
|
||||
const mockWarn = vi.fn();
|
||||
|
||||
const logger = {
|
||||
debug: mockDebug,
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { logger, setup } from '@verdaccio/logger';
|
||||
|
||||
import { ProxyStorage } from '../src';
|
||||
|
@ -1,4 +1,5 @@
|
||||
import assert from 'assert';
|
||||
import { describe, test } from 'vitest';
|
||||
|
||||
import { parseInterval } from '../src/proxy-utils';
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import nock from 'nock';
|
||||
import path from 'path';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { Config, parseConfigFile } from '@verdaccio/config';
|
||||
import { API_ERROR, errorUtils } from '@verdaccio/core';
|
||||
@ -10,11 +11,11 @@ import { ProxyStorage } from '../src';
|
||||
|
||||
const getConf = (name) => path.join(__dirname, '/conf', name);
|
||||
|
||||
const mockDebug = jest.fn();
|
||||
const mockInfo = jest.fn();
|
||||
const mockHttp = jest.fn();
|
||||
const mockError = jest.fn();
|
||||
const mockWarn = jest.fn();
|
||||
const mockDebug = vi.fn();
|
||||
const mockInfo = vi.fn();
|
||||
const mockHttp = vi.fn();
|
||||
const mockError = vi.fn();
|
||||
const mockWarn = vi.fn();
|
||||
|
||||
const logger = {
|
||||
debug: mockDebug,
|
||||
@ -24,39 +25,25 @@ const logger = {
|
||||
warn: mockWarn,
|
||||
} as unknown as Logger;
|
||||
|
||||
// mock to get the headers fixed value
|
||||
jest.mock('crypto', () => {
|
||||
return {
|
||||
randomBytes: (): { toString: () => string } => {
|
||||
return {
|
||||
toString: (): string => 'foo-random-bytes',
|
||||
};
|
||||
},
|
||||
pseudoRandomBytes: (): { toString: () => string } => {
|
||||
return {
|
||||
toString: (): string => 'foo-phseudo-bytes',
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const domain = 'https://registry.npmjs.org';
|
||||
|
||||
describe('proxy', () => {
|
||||
beforeEach(() => {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
const defaultRequestOptions = {
|
||||
url: 'https://registry.npmjs.org',
|
||||
url: domain,
|
||||
};
|
||||
const proxyPath = getConf('proxy1.yaml');
|
||||
const conf = new Config(parseConfigFile(proxyPath));
|
||||
conf.server_id = 'foo-phseudo-bytes';
|
||||
|
||||
describe('getRemoteMetadata', () => {
|
||||
beforeEach(() => {
|
||||
nock.cleanAll();
|
||||
nock.abortPendingRequests();
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
describe('basic requests', () => {
|
||||
test('success call to remote', async () => {
|
||||
|
@ -4,6 +4,7 @@
|
||||
import getStream from 'get-stream';
|
||||
import nock from 'nock';
|
||||
import path from 'path';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { Config, parseConfigFile } from '@verdaccio/config';
|
||||
import { streamUtils } from '@verdaccio/core';
|
||||
@ -13,11 +14,11 @@ import { ProxyStorage } from '../src';
|
||||
|
||||
const getConf = (name) => path.join(__dirname, '/conf', name);
|
||||
|
||||
const mockDebug = jest.fn();
|
||||
const mockInfo = jest.fn();
|
||||
const mockHttp = jest.fn();
|
||||
const mockError = jest.fn();
|
||||
const mockWarn = jest.fn();
|
||||
const mockDebug = vi.fn();
|
||||
const mockInfo = vi.fn();
|
||||
const mockHttp = vi.fn();
|
||||
const mockError = vi.fn();
|
||||
const mockWarn = vi.fn();
|
||||
|
||||
const logger = {
|
||||
debug: mockDebug,
|
||||
|
@ -1,17 +1,18 @@
|
||||
import nock from 'nock';
|
||||
import path from 'path';
|
||||
import { beforeEach, describe, test, vi } from 'vitest';
|
||||
|
||||
import { Config, parseConfigFile } from '@verdaccio/config';
|
||||
import { logger, setup } from '@verdaccio/logger';
|
||||
|
||||
import { ProxyStorage } from '../src';
|
||||
|
||||
setup();
|
||||
setup({});
|
||||
|
||||
const getConf = (name) => path.join(__dirname, '/conf', name);
|
||||
|
||||
// // mock to get the headers fixed value
|
||||
jest.mock('crypto', () => {
|
||||
vi.mock('crypto', () => {
|
||||
return {
|
||||
randomBytes: (): { toString: () => string } => {
|
||||
return {
|
||||
@ -30,7 +31,7 @@ describe('tarball proxy', () => {
|
||||
beforeEach(() => {
|
||||
nock.cleanAll();
|
||||
nock.abortPendingRequests();
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
const defaultRequestOptions = {
|
||||
url: 'https://registry.verdaccio.org',
|
||||
@ -40,24 +41,27 @@ describe('tarball proxy', () => {
|
||||
const conf = new Config(parseConfigFile(proxyPath));
|
||||
|
||||
describe('fetchTarball', () => {
|
||||
test('get file tarball fetch', (done) => {
|
||||
test('get file tarball fetch', () =>
|
||||
new Promise((done) => {
|
||||
nock('https://registry.verdaccio.org')
|
||||
.get('/jquery/-/jquery-0.0.1.tgz')
|
||||
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
||||
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
||||
const stream = prox1.fetchTarball(
|
||||
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
||||
// @ts-expect-error
|
||||
{}
|
||||
);
|
||||
stream.on('response', () => {
|
||||
done();
|
||||
done(true);
|
||||
});
|
||||
stream.on('error', (err) => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
test.skip('get file tarball handle retries', (done) => {
|
||||
test.skip('get file tarball handle retries', () =>
|
||||
new Promise((done) => {
|
||||
nock('https://registry.verdaccio.org')
|
||||
.get('/jquery/-/jquery-0.0.1.tgz')
|
||||
.twice()
|
||||
@ -74,7 +78,7 @@ describe('tarball proxy', () => {
|
||||
// FIXME: stream should have handle 2 retry
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
// test('get file tarball correct content-length', (done) => {
|
||||
|
Loading…
Reference in New Issue
Block a user