This commit is contained in:
2026-01-04 20:47:43 +00:00
parent a8b07e1dfd
commit abed903b06
15 changed files with 9186 additions and 181 deletions

View File

@@ -1,4 +1,4 @@
import { UiPublicServer } from '../ts';
import { UiPublicServer } from '../ts/index.js';
export const defaultPublicServer = new UiPublicServer({
port: 3000,

View File

@@ -1,12 +1,11 @@
import { tap, expect } from '@pushrocks/tapbundle';
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver';
import * as smartnetwork from '@pushrocks/smartnetwork';
import * as smartrequest from '@pushrocks/smartrequest';
import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver.js';
import * as smartnetwork from '@push.rocks/smartnetwork';
import { SmartRequest } from '@push.rocks/smartrequest';
const plugins = {
smartnetwork,
smartrequest,
};
let testserverInstance: uiPublicServer.UiPublicServer;
@@ -18,7 +17,7 @@ tap.test('should create an instance of PublicServer', async () => {
allowedPackages: ['@pushrocks/smartfile'],
mode: 'prod',
});
expect(testserverInstance).to.be.instanceOf(uiPublicServer.UiPublicServer);
expect(testserverInstance).toBeInstanceOf(uiPublicServer.UiPublicServer);
});
tap.test('should start the server', async () => {
@@ -26,8 +25,8 @@ tap.test('should start the server', async () => {
const result1 = await smartnetworkInstance.isLocalPortUnused(3000);
await testserverInstance.startServer();
const result2 = await smartnetworkInstance.isLocalPortUnused(3000);
expect(result1).to.be.true;
expect(result2).to.be.false;
expect(result1).toBeTrue();
expect(result2).toBeFalse();
});
tap.skip.test('optional manual testing', async (toolsArg) => {
@@ -35,65 +34,53 @@ tap.skip.test('optional manual testing', async (toolsArg) => {
});
tap.test('should NOT deliver a file for a malformed org', async () => {
const response = await plugins.smartrequest.request('http://localhost:3000/someorg/somemodule', {
method: 'GET',
});
console.log(response.body);
expect(response.body).to.equal('npmorg "someorg" must start with @');
const response = await SmartRequest.create()
.url('http://localhost:3000/someorg/somemodule')
.get();
const body = await response.text();
console.log(body);
expect(body).toEqual('npmorg "someorg" must start with @');
});
tap.test('should NOT deliver a file for a nonexisting file', async () => {
const response = await plugins.smartrequest.request(
'http://localhost:3000/@pushrocks/smartfile/readme2.md',
{
method: 'GET',
}
);
console.log(response.body);
expect(response.body.includes('@pushrocks/smartfile@ does not have a file at')).to.be.true;
const response = await SmartRequest.create()
.url('http://localhost:3000/@pushrocks/smartfile/readme2.md')
.get();
const body = await response.text();
console.log(body);
expect(body.includes('@pushrocks/smartfile@ does not have a file at')).toBeTrue();
});
tap.test('should deliver a file for an existing file', async () => {
const response = await plugins.smartrequest.request(
'http://localhost:3000/@pushrocks/smartfile/readme.md',
{
method: 'GET',
}
);
expect(response.body.startsWith('# @pushrocks/smartfile')).to.be.true;
const response = await SmartRequest.create()
.url('http://localhost:3000/@pushrocks/smartfile/readme.md')
.get();
const body = await response.text();
expect(body.startsWith('# @pushrocks/smartfile')).toBeTrue();
});
tap.test('should deliver different versions', async () => {
const response = await plugins.smartrequest.request(
'http://localhost:3000/@pushrocks/smartfile/package.json?version=7',
{
method: 'GET',
}
);
const packageJson = response.body;
expect(packageJson.version.startsWith('7')).to.be.true;
const response = await SmartRequest.create()
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=7')
.get();
const packageJson = await response.json();
expect(packageJson.version.startsWith('7')).toBeTrue();
const response2 = await plugins.smartrequest.request(
'http://localhost:3000/@pushrocks/smartfile/package.json?version=8.x.x',
{
method: 'GET',
}
);
const packageJson2 = response2.body;
expect(packageJson2.version.startsWith('8')).to.be.true;
const response2 = await SmartRequest.create()
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=8.x.x')
.get();
const packageJson2 = await response2.json();
expect(packageJson2.version.startsWith('8')).toBeTrue();
const response3 = await plugins.smartrequest.request(
'http://localhost:3000/@pushrocks/smartfile/package.json?version=6.0.6',
{
method: 'GET',
}
);
const packageJson3 = response3.body;
expect(packageJson3.version).to.equal('6.0.6');
const response3 = await SmartRequest.create()
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=6.0.6')
.get();
const packageJson3 = await response3.json();
expect(packageJson3.version).toEqual('6.0.6');
});
tap.test('should stop the server', async () => {
await testserverInstance.stopServer();
});
tap.start();
export default tap.start();