UNPKG

@mojojs/core

Version:

Real-time web framework

44 lines 1.23 kB
import { Server } from '../server.js'; import { UserAgent } from '../user-agent.js'; /** * Mock user-agent class. */ export class MockUserAgent extends UserAgent { constructor(options) { super(options); /** * Server to use for mock requests. */ this.server = undefined; this.server = undefined; } async [Symbol.asyncDispose]() { await this.stop(); } /** * Create a new mock user-agent. */ static async newMockUserAgent(app, options, serverOptions) { return await new MockUserAgent(options).start(app, serverOptions); } /** * Start mock server. */ async start(app, options = {}) { const listen = [options.https === true ? 'https://*' : 'http://*']; const server = (this.server = new Server(app, { ...options, listen, quiet: true })); await server.start(); if (this.baseURL === undefined) this.baseURL = server.urls[0]; return this; } /** * Stop mock server. */ async stop() { await this.destroy(); if (this.server !== undefined) return await this.server.stop(); } } //# sourceMappingURL=mock.js.map