import { tap, expect } from '@pushrocks/tapbundle'; import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver'; import * as smartnetwork from '@pushrocks/smartnetwork'; import * as smartrequest from '@pushrocks/smartrequest'; const plugins = { smartnetwork, smartrequest, }; 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', }); expect(testserverInstance).to.be.instanceOf(uiPublicServer.UiPublicServer); }); 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); expect(result1).to.be.true; expect(result2).to.be.false; }); tap.skip.test('optional manual testing', async (toolsArg) => { await toolsArg.delayFor(30000); }); 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 @'); }); 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; }); 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; }); 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 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 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'); }); tap.test('should stop the server', async () => { await testserverInstance.stopServer(); }); tap.start();