mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
13310814da
* #2606 add prettier plugin sort imprts * #2606 update pnpm-lock.yaml * #2606 update eslint rules * #2606 fixes website directory formatting Co-authored-by: Ayush Sharma <ayush.sharma@trivago.com>
109 lines
2.8 KiB
TypeScript
109 lines
2.8 KiB
TypeScript
import _ from 'lodash';
|
|
|
|
import { HTTP_STATUS, VerdaccioError } from '@verdaccio/core';
|
|
|
|
import { mockServer } from '../src/mock';
|
|
import smartRequest, { PromiseAssert } from '../src/request';
|
|
import { IRequestPromise } from '../src/types';
|
|
|
|
describe('Request Functional', () => {
|
|
jest.setTimeout(20000);
|
|
const mockServerPort = 55547;
|
|
const domainTest = `http://localhost:${55547}`;
|
|
const restTest = `${domainTest}/jquery`;
|
|
let mockRegistry;
|
|
|
|
describe('Request Functional', () => {
|
|
test('PromiseAssert', () => {
|
|
expect(_.isFunction(smartRequest)).toBeTruthy();
|
|
});
|
|
|
|
test('basic resolve', (done) => {
|
|
const requestPromise: IRequestPromise = new PromiseAssert((resolve) => {
|
|
resolve(1);
|
|
});
|
|
// @ts-ignore
|
|
requestPromise.then((result) => {
|
|
expect(result).toBe(1);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('smartRequest Rest', () => {
|
|
beforeAll(async () => {
|
|
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
|
mockRegistry = await mockServer(mockServerPort).init(binPath);
|
|
});
|
|
|
|
afterAll(function (done) {
|
|
const [registry, pid] = mockRegistry;
|
|
registry.stop();
|
|
console.log(`registry ${pid} has been stopped`);
|
|
|
|
done();
|
|
});
|
|
|
|
test('basic rest', (done) => {
|
|
const options: any = {
|
|
url: restTest,
|
|
method: 'GET',
|
|
};
|
|
|
|
smartRequest(options).then((result) => {
|
|
expect(_.isString(result)).toBeTruthy();
|
|
done();
|
|
});
|
|
});
|
|
|
|
describe('smartRequest Status', () => {
|
|
test('basic check status 200', (done) => {
|
|
const options: any = {
|
|
url: restTest,
|
|
method: 'GET',
|
|
};
|
|
// @ts-ignore
|
|
smartRequest(options)
|
|
.status(HTTP_STATUS.OK)
|
|
.then((result) => {
|
|
expect(JSON.parse(result).name).toBe('jquery');
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('basic ping status and empty response', (done) => {
|
|
const options: any = {
|
|
url: `${domainTest}/-/ping`,
|
|
method: 'GET',
|
|
};
|
|
// @ts-ignore
|
|
smartRequest(options)
|
|
.status(HTTP_STATUS.OK)
|
|
.then((result) => {
|
|
expect(JSON.parse(result)).toEqual({});
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('basic check status 404', (done) => {
|
|
const options: any = {
|
|
url: 'http://www.google.fake',
|
|
method: 'GET',
|
|
};
|
|
// @ts-ignore
|
|
smartRequest(options)
|
|
.status(HTTP_STATUS.NOT_FOUND)
|
|
.then(
|
|
() => {
|
|
// we do not intent to resolve this
|
|
},
|
|
(error: VerdaccioError) => {
|
|
expect(error.code).toBe('ENOTFOUND');
|
|
done();
|
|
}
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|