2022-06-24 22:09:46 +02:00
|
|
|
import { JSDOM } from 'jsdom';
|
2021-03-06 18:56:45 +01:00
|
|
|
import path from 'path';
|
|
|
|
import supertest from 'supertest';
|
2021-10-29 17:33:05 +02:00
|
|
|
|
|
|
|
import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
|
2021-03-06 18:56:45 +01:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2021-10-29 17:33:05 +02:00
|
|
|
|
2021-03-06 18:56:45 +01:00
|
|
|
import { initializeServer } from './helper';
|
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
|
|
|
const mockManifest = jest.fn();
|
|
|
|
jest.mock('@verdaccio/ui-theme', () => mockManifest());
|
|
|
|
|
|
|
|
describe('test web server', () => {
|
|
|
|
beforeAll(() => {
|
2021-04-02 15:59:47 +02:00
|
|
|
mockManifest.mockReturnValue(() => ({
|
|
|
|
manifestFiles: {
|
|
|
|
js: ['runtime.js', 'vendors.js', 'main.js'],
|
|
|
|
},
|
2021-03-06 18:56:45 +01:00
|
|
|
staticPath: path.join(__dirname, 'static'),
|
|
|
|
manifest: require('./partials/manifest/manifest.json'),
|
2021-04-02 15:59:47 +02:00
|
|
|
}));
|
2021-03-06 18:56:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
mockManifest.mockClear();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('render', () => {
|
2022-06-24 22:09:46 +02:00
|
|
|
describe('output', () => {
|
|
|
|
const render = async (config = 'default-test.yaml') => {
|
|
|
|
const response = await supertest(await initializeServer(config))
|
|
|
|
.get('/')
|
|
|
|
.set('Accept', HEADERS.TEXT_HTML)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
|
|
.expect(HTTP_STATUS.OK);
|
|
|
|
return new JSDOM(response.text, { runScripts: 'dangerously' });
|
|
|
|
};
|
2021-03-06 18:56:45 +01:00
|
|
|
|
2022-06-24 22:09:46 +02:00
|
|
|
test('should match render set ui properties', async () => {
|
|
|
|
const {
|
|
|
|
window: { __VERDACCIO_BASENAME_UI_OPTIONS },
|
|
|
|
} = await render('web.yaml');
|
|
|
|
expect(__VERDACCIO_BASENAME_UI_OPTIONS).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
showInfo: true,
|
|
|
|
showSettings: true,
|
|
|
|
showThemeSwitch: true,
|
|
|
|
showFooter: true,
|
|
|
|
showSearch: true,
|
|
|
|
showDownloadTarball: true,
|
|
|
|
darkMode: false,
|
|
|
|
url_prefix: '/prefix',
|
|
|
|
basename: '/prefix/',
|
|
|
|
primaryColor: '#ffffff',
|
|
|
|
// FIXME: mock these values, avoid random
|
|
|
|
// base: 'http://127.0.0.1:60864/prefix/',
|
|
|
|
// version: '6.0.0-6-next.28',
|
|
|
|
logoURI: '',
|
|
|
|
flags: { searchRemote: true },
|
|
|
|
login: true,
|
|
|
|
pkgManagers: ['pnpm', 'yarn'],
|
|
|
|
title: 'verdaccio web',
|
|
|
|
scope: '@scope',
|
|
|
|
language: 'es-US',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-03-06 18:56:45 +01:00
|
|
|
|
2022-08-08 19:20:37 +02:00
|
|
|
test.todo('should default title');
|
|
|
|
test.todo('should need html cache');
|
2021-03-06 18:56:45 +01:00
|
|
|
});
|
|
|
|
|
2022-06-24 22:09:46 +02:00
|
|
|
describe('status', () => {
|
|
|
|
test('should return the http status 200 for root', async () => {
|
|
|
|
return supertest(await initializeServer('default-test.yaml'))
|
|
|
|
.get('/')
|
|
|
|
.set('Accept', HEADERS.TEXT_HTML)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
|
|
.expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return the body for a package detail page', async () => {
|
|
|
|
return supertest(await initializeServer('default-test.yaml'))
|
|
|
|
.get('/-/web/section/some-package')
|
|
|
|
.set('Accept', HEADERS.TEXT_HTML)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
|
|
|
|
.expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should static file not found', async () => {
|
|
|
|
return supertest(await initializeServer('default-test.yaml'))
|
|
|
|
.get('/-/static/not-found.js')
|
|
|
|
.set('Accept', HEADERS.TEXT_HTML)
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should static file found', async () => {
|
|
|
|
return supertest(await initializeServer('default-test.yaml'))
|
|
|
|
.get('/-/static/main.js')
|
|
|
|
.set('Accept', HEADERS.TEXT_HTML)
|
|
|
|
.expect(HTTP_STATUS.OK);
|
|
|
|
});
|
2021-03-06 18:56:45 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|