Files
npmcdn/test/test.node.ts

87 lines
3.0 KiB
TypeScript
Raw Permalink Normal View History

2026-01-04 20:47:43 +00:00
import { tap, expect } from '@git.zone/tstest/tapbundle';
2022-01-06 01:20:03 +01:00
2026-01-04 20:47:43 +00:00
import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver.js';
import * as smartnetwork from '@push.rocks/smartnetwork';
import { SmartRequest } from '@push.rocks/smartrequest';
2022-01-06 01:20:03 +01:00
const plugins = {
smartnetwork,
};
let testserverInstance: uiPublicServer.UiPublicServer;
tap.test('should create an instance of PublicServer', async () => {
testserverInstance = new uiPublicServer.UiPublicServer({
npmRegistryUrl: 'https://registry.npmjs.org',
port: 3000,
allowedPackages: ['@pushrocks/smartfile'],
mode: 'prod',
});
2026-01-04 20:47:43 +00:00
expect(testserverInstance).toBeInstanceOf(uiPublicServer.UiPublicServer);
2022-01-06 01:20:03 +01:00
});
tap.test('should start the server', async () => {
const smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
const result1 = await smartnetworkInstance.isLocalPortUnused(3000);
await testserverInstance.startServer();
const result2 = await smartnetworkInstance.isLocalPortUnused(3000);
2026-01-04 20:47:43 +00:00
expect(result1).toBeTrue();
expect(result2).toBeFalse();
2022-01-06 01:20:03 +01:00
});
tap.skip.test('optional manual testing', async (toolsArg) => {
await toolsArg.delayFor(30000);
});
tap.test('should NOT deliver a file for a malformed org', async () => {
2026-01-04 20:47:43 +00:00
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 @');
2022-01-06 01:20:03 +01:00
});
tap.test('should NOT deliver a file for a nonexisting file', async () => {
2026-01-04 20:47:43 +00:00
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();
2022-01-06 01:20:03 +01:00
});
tap.test('should deliver a file for an existing file', async () => {
2026-01-04 20:47:43 +00:00
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();
2022-01-06 01:20:03 +01:00
});
tap.test('should deliver different versions', async () => {
2026-01-04 20:47:43 +00:00
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();
2022-01-06 01:20:03 +01:00
2026-01-04 20:47:43 +00:00
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();
2022-01-06 01:20:03 +01:00
2026-01-04 20:47:43 +00:00
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');
2022-01-06 01:20:03 +01:00
});
tap.test('should stop the server', async () => {
await testserverInstance.stopServer();
});
2026-01-04 20:47:43 +00:00
export default tap.start();