UNPKG

@dhlab/e2e-autogen

Version:

Google 스프레드시트 기반 시나리오를 Playwright 테스트 스텁 코드로 자동 생성하고, 테스트 실행 결과를 다시 시트에 업데이트하는 CLI 도구

102 lines (101 loc) 6.28 kB
var _SocketIoPlayer_instances, _SocketIoPlayer_http, _SocketIoPlayer_io, _SocketIoPlayer_port, _SocketIoPlayer_ns, _SocketIoPlayer_socket, _SocketIoPlayer_timers, _SocketIoPlayer_step, _SocketIoPlayer_bind, _SocketIoPlayer_burst, _SocketIoPlayer_emitWithDelay, _SocketIoPlayer_clear; Object.defineProperty(exports, "__esModule", { value: true }); exports.SocketIoPlayer = void 0; const tslib_1 = require("tslib"); const types_1 = require("./types"); class SocketIoPlayer { constructor({ httpServer, io, port }) { _SocketIoPlayer_instances.add(this); _SocketIoPlayer_http.set(this, void 0); _SocketIoPlayer_io.set(this, void 0); _SocketIoPlayer_port.set(this, void 0); _SocketIoPlayer_ns.set(this, void 0); _SocketIoPlayer_socket.set(this, void 0); _SocketIoPlayer_timers.set(this, []); _SocketIoPlayer_step.set(this, 0); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_http, httpServer, "f"); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_io, io, "f"); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_port, port, "f"); if (!tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_http, "f") || !tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_io, "f") || !tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_port, "f")) throw new Error("invalid args"); } async start(s) { await new Promise((resolve) => { tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_http, "f").listen(tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_port, "f"), () => resolve()); }); const nsPath = s.namespace || "/"; tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_ns, nsPath === "/" ? tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_io, "f").of("/") : tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_io, "f").of(nsPath), "f"); // handshake reject 처리 tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_ns, "f").use((_, next) => { const rej = s.handshakeReject; if (!rej) { next(); return; } if (rej.afterMs && rej.afterMs > 0) { const t = setTimeout(() => { const error = new Error(rej.message); error.data = { message: rej.message, code: rej.code }; next(error); }, rej.afterMs); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_timers, "f").push(t); return; } const error = new Error(rej.message); error.data = { message: rej.message, code: rej.code }; next(error); }); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_ns, "f").on("connection", (socket) => { tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_socket, socket, "f"); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_step, 0, "f"); // onConnect tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_burst).call(this, socket, s.onConnect); // 단계별 트리거 if (s.steps.length > 0) tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_bind).call(this, socket, s.steps); if (s.disconnectAfterMs != null) { const t = setTimeout(() => socket.disconnect(true), s.disconnectAfterMs); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_timers, "f").push(t); } socket.on("disconnect", () => { tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_socket, undefined, "f"); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_clear).call(this); }); }); } close() { tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_clear).call(this); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_io, "f")?.close(); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_http, "f")?.close(); } connected() { return tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_socket, "f")?.connected ?? false; } } exports.SocketIoPlayer = SocketIoPlayer; _SocketIoPlayer_http = new WeakMap(), _SocketIoPlayer_io = new WeakMap(), _SocketIoPlayer_port = new WeakMap(), _SocketIoPlayer_ns = new WeakMap(), _SocketIoPlayer_socket = new WeakMap(), _SocketIoPlayer_timers = new WeakMap(), _SocketIoPlayer_step = new WeakMap(), _SocketIoPlayer_instances = new WeakSet(), _SocketIoPlayer_bind = function _SocketIoPlayer_bind(socket, steps) { const handler = (eventName) => (...args) => { const step = steps[tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_step, "f")]; if (!step) return; const ok = step.expect.event === eventName && (0, types_1.TJSON_EQ)(step.expect.args, args); if (!ok) return; tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_emitWithDelay).call(this, socket, step.responses); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_step, tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_step, "f") + 1, "f"); }; const events = Array.from(new Set(steps.map((s) => s.expect.event))); events.forEach((ev) => socket.on(ev, handler(ev))); }, _SocketIoPlayer_burst = function _SocketIoPlayer_burst(socket, burst) { if (burst.responses.length === 0) return; tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_instances, "m", _SocketIoPlayer_emitWithDelay).call(this, socket, burst.responses); }, _SocketIoPlayer_emitWithDelay = function _SocketIoPlayer_emitWithDelay(socket, rs) { rs.forEach((r) => { const t = setTimeout(() => socket.emit(r.event, ...r.args), r.delayMs); tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_timers, "f").push(t); }); }, _SocketIoPlayer_clear = function _SocketIoPlayer_clear() { tslib_1.__classPrivateFieldGet(this, _SocketIoPlayer_timers, "f").forEach(clearTimeout); tslib_1.__classPrivateFieldSet(this, _SocketIoPlayer_timers, [], "f"); };